mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
refactor: remove unnecessary getters
This commit is contained in:
@ -132,8 +132,8 @@ func writeMultipartReport(w *multipart.Writer, rep *ReportReq) error { // nolint
|
||||
|
||||
// Report sends request as json or multipart (if has attachment).
|
||||
func (c *client) Report(rep ReportReq) (err error) {
|
||||
rep.Client = c.cm.GetConfig().ClientID
|
||||
rep.ClientVersion = c.cm.GetConfig().AppVersion
|
||||
rep.Client = c.cm.config.ClientID
|
||||
rep.ClientVersion = c.cm.config.AppVersion
|
||||
rep.ClientType = EmailClientType
|
||||
|
||||
var req *http.Request
|
||||
@ -196,8 +196,8 @@ func (c *client) ReportBugWithEmailClient(os, osVersion, title, description, use
|
||||
// ReportCrash is old. Use sentry instead.
|
||||
func (c *client) ReportCrash(stacktrace string) (err error) {
|
||||
crashReq := ReportReq{
|
||||
Client: c.cm.GetConfig().ClientID,
|
||||
ClientVersion: c.cm.GetConfig().AppVersion,
|
||||
Client: c.cm.config.ClientID,
|
||||
ClientVersion: c.cm.config.AppVersion,
|
||||
ClientType: EmailClientType,
|
||||
OS: runtime.GOOS,
|
||||
Debug: stacktrace,
|
||||
|
||||
@ -168,7 +168,7 @@ type client struct {
|
||||
func newClient(cm *ClientManager, userID string) *client {
|
||||
return &client{
|
||||
cm: cm,
|
||||
hc: getHTTPClient(cm.GetConfig(), cm.GetRoundTripper()),
|
||||
hc: getHTTPClient(cm.config, cm.roundTripper),
|
||||
userID: userID,
|
||||
requestLocker: &sync.Mutex{},
|
||||
keyLocker: &sync.Mutex{},
|
||||
@ -207,7 +207,7 @@ func (c *client) Do(req *http.Request, retryUnauthorized bool) (res *http.Respon
|
||||
func (c *client) doBuffered(req *http.Request, bodyBuffer []byte, retryUnauthorized bool) (res *http.Response, err error) { // nolint[funlen]
|
||||
isAuthReq := strings.Contains(req.URL.Path, "/auth")
|
||||
|
||||
req.Header.Set("x-pm-appversion", c.cm.GetConfig().AppVersion)
|
||||
req.Header.Set("x-pm-appversion", c.cm.config.AppVersion)
|
||||
req.Header.Set("x-pm-apiversion", strconv.Itoa(Version))
|
||||
|
||||
if c.uid != "" {
|
||||
@ -310,7 +310,7 @@ func (c *client) doJSONBuffered(req *http.Request, reqBodyBuffer []byte, data in
|
||||
req.Header.Set("Accept", "application/vnd.protonmail.v1+json")
|
||||
|
||||
var cancelRequest context.CancelFunc
|
||||
if c.cm.GetConfig().MinSpeed > 0 {
|
||||
if c.cm.config.MinSpeed > 0 {
|
||||
var ctx context.Context
|
||||
ctx, cancelRequest = context.WithCancel(req.Context())
|
||||
defer func() {
|
||||
@ -326,7 +326,7 @@ func (c *client) doJSONBuffered(req *http.Request, reqBodyBuffer []byte, data in
|
||||
defer res.Body.Close() //nolint[errcheck]
|
||||
|
||||
var resBody []byte
|
||||
if c.cm.GetConfig().MinSpeed == 0 {
|
||||
if c.cm.config.MinSpeed == 0 {
|
||||
resBody, err = ioutil.ReadAll(res.Body)
|
||||
} else {
|
||||
resBody, err = c.readAllMinSpeed(res.Body, cancelRequest)
|
||||
@ -404,7 +404,7 @@ func (c *client) doJSONBuffered(req *http.Request, reqBodyBuffer []byte, data in
|
||||
}
|
||||
|
||||
func (c *client) readAllMinSpeed(data io.Reader, cancelRequest context.CancelFunc) ([]byte, error) {
|
||||
firstReadTimeout := c.cm.GetConfig().FirstReadTimeout
|
||||
firstReadTimeout := c.cm.config.FirstReadTimeout
|
||||
if firstReadTimeout == 0 {
|
||||
firstReadTimeout = 5 * time.Minute
|
||||
}
|
||||
@ -413,7 +413,7 @@ func (c *client) readAllMinSpeed(data io.Reader, cancelRequest context.CancelFun
|
||||
})
|
||||
var buffer bytes.Buffer
|
||||
for {
|
||||
_, err := io.CopyN(&buffer, data, c.cm.GetConfig().MinSpeed)
|
||||
_, err := io.CopyN(&buffer, data, c.cm.config.MinSpeed)
|
||||
timer.Stop()
|
||||
timer.Reset(1 * time.Second)
|
||||
if err == io.EOF {
|
||||
|
||||
@ -100,11 +100,6 @@ func (cm *ClientManager) SetRoundTripper(rt http.RoundTripper) {
|
||||
cm.roundTripper = rt
|
||||
}
|
||||
|
||||
// GetRoundTripper gets the roundtripper used by clients created by this client manager.
|
||||
func (cm *ClientManager) GetRoundTripper() (rt http.RoundTripper) {
|
||||
return cm.roundTripper
|
||||
}
|
||||
|
||||
// GetClient returns a client for the given userID.
|
||||
// If the client does not exist already, it is created.
|
||||
func (cm *ClientManager) GetClient(userID string) Client {
|
||||
@ -241,11 +236,6 @@ func (cm *ClientManager) switchToReachableServer() (proxy string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetConfig returns the config used to configure clients.
|
||||
func (cm *ClientManager) GetConfig() *ClientConfig {
|
||||
return cm.config
|
||||
}
|
||||
|
||||
// GetToken returns the token for the given userID.
|
||||
func (cm *ClientManager) GetToken(userID string) string {
|
||||
cm.tokensLocker.Lock()
|
||||
|
||||
@ -152,8 +152,8 @@ func (c *client) ReportSentryCrash(reportErr error) (err error) {
|
||||
}
|
||||
tags := map[string]string{
|
||||
"OS": runtime.GOOS,
|
||||
"Client": c.cm.GetConfig().ClientID,
|
||||
"Version": c.cm.GetConfig().AppVersion,
|
||||
"Client": c.cm.config.ClientID,
|
||||
"Version": c.cm.config.AppVersion,
|
||||
"UserAgent": CurrentUserAgent,
|
||||
"UserID": c.userID,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user