diff --git a/fbx/api_version.go b/fbx/api_version.go index b2d4490..a538274 100644 --- a/fbx/api_version.go +++ b/fbx/api_version.go @@ -43,8 +43,8 @@ func NewFreeboxAPIVersion(client *FreeboxHttpClient, discovery FreeboxDiscovery) return nil, err } - if result.IsValid() == false { - return nil, errors.New("Could not get the API version") + if !result.IsValid() { + return nil, errors.New("could not get the API version") } log.Debug.Println("APIVersion", result) return result, nil @@ -56,7 +56,7 @@ func (f *FreeboxAPIVersion) IsValid() bool { } return f.APIDomain != "" && f.UID != "" && - f.HTTPSAvailable == true && + f.HTTPSAvailable && f.HTTPSPort != 0 && f.DeviceName != "" && f.APIVersion != "" && @@ -65,12 +65,12 @@ func (f *FreeboxAPIVersion) IsValid() bool { } func (f *FreeboxAPIVersion) GetURL(path string, miscPath ...interface{}) (string, error) { - if f.IsValid() == false { - return "", errors.New("Invalid FreeboxAPIVersion") + if !f.IsValid() { + return "", errors.New("invalid FreeboxAPIVersion") } versionSplit := strings.Split(f.APIVersion, ".") if len(versionSplit) != 2 { - return "", fmt.Errorf("Could not decode the api version \"%s\"", f.APIVersion) + return "", fmt.Errorf("could not decode the api version \"%s\"", f.APIVersion) } args := make([]interface{}, len(miscPath)+4) args[0] = f.APIDomain @@ -85,7 +85,7 @@ func (f *FreeboxAPIVersion) GetURL(path string, miscPath ...interface{}) (string func (f *FreeboxAPIVersion) getDiscovery(discovery FreeboxDiscovery) func(client *FreeboxHttpClient) error { function := func(*FreeboxHttpClient) error { - return errors.New("Wrong discovery argument") + return errors.New("wrong discovery argument") } switch discovery { @@ -161,7 +161,6 @@ func (f *FreeboxAPIVersion) newFreeboxAPIVersionMDNS(*FreeboxHttpClient) error { case "device_type": f.DeviceType = kv[1] default: - break } } if f.IsValid() { diff --git a/fbx/cert.go b/fbx/cert.go index 583f4c3..fe1ecb1 100644 --- a/fbx/cert.go +++ b/fbx/cert.go @@ -45,7 +45,7 @@ S27oDfFq04XSox7JM9HdTt2hLK96x1T7FpFrBTnALzb7vHv9MhXqAT90fPR/8A== func newTLSConfig() *tls.Config { caCertPool := x509.NewCertPool() - if caCertPool.AppendCertsFromPEM([]byte(freeboxRootCA)) == false { + if !caCertPool.AppendCertsFromPEM([]byte(freeboxRootCA)) { panic("Could not add the certificate") } diff --git a/fbx/connection.go b/fbx/connection.go index 70bf17e..3d82732 100644 --- a/fbx/connection.go +++ b/fbx/connection.go @@ -52,11 +52,11 @@ func NewFreeboxConnectionFromConfig(reader io.Reader) (*FreeboxConnection, error if err := json.NewDecoder(reader).Decode(&config); err != nil { return nil, err } - if config.APIVersion.IsValid() == false { - return nil, fmt.Errorf("Invalid api_version: %v", config.APIVersion) + if !config.APIVersion.IsValid() { + return nil, fmt.Errorf("invalid api_version: %v", config.APIVersion) } if config.AppToken == "" { - return nil, fmt.Errorf("Invalid app_token: %s", config.AppToken) + return nil, fmt.Errorf("invalid app_token: %s", config.AppToken) } session, err := NewFreeboxSession(config.AppToken, client, config.APIVersion) diff --git a/fbx/http_client.go b/fbx/http_client.go index 5973b03..cd1ad69 100644 --- a/fbx/http_client.go +++ b/fbx/http_client.go @@ -6,7 +6,6 @@ import ( "encoding/json" "errors" "fmt" - "io" "io/ioutil" "net/http" "time" @@ -20,9 +19,8 @@ var ( ) type FreeboxHttpClient struct { - client http.Client - ctx context.Context - decoder func(io.Reader, interface{}) error + client http.Client + ctx context.Context } type freeboxAPIResponse struct { @@ -100,7 +98,7 @@ func (f *FreeboxHttpClient) do(req *http.Request, out interface{}) error { if err := json.Unmarshal(body, &apiResponse); err != nil { return err } - if apiResponse.Success == false { + if !apiResponse.Success { switch apiResponse.ErrorCode { case errAuthRequired.Error(): return errAuthRequired diff --git a/fbx/session.go b/fbx/session.go index bdb9251..e19c4d5 100644 --- a/fbx/session.go +++ b/fbx/session.go @@ -67,7 +67,7 @@ func GetAppToken(client *FreeboxHttpClient, apiVersion *FreeboxAPIVersion) (stri case "granted": return postResponse.AppToken, nil default: - return "", fmt.Errorf("Access is %s", status.Status) + return "", fmt.Errorf("access is %s", status.Status) } } } @@ -110,7 +110,7 @@ func (f *FreeboxSession) Refresh() error { f.sessionTokenLock.Lock() defer f.sessionTokenLock.Unlock() - if sinceLastUpdate := time.Now().Sub(f.sessionTokenLastUpdate); sinceLastUpdate < 5*time.Second { + if sinceLastUpdate := time.Since(f.sessionTokenLastUpdate); sinceLastUpdate < 5*time.Second { log.Debug.Printf("Updated %v ago. Skipping", sinceLastUpdate) return nil }