apply staticcheck

This commit is contained in:
Alexandre Blazart 2022-09-30 21:11:12 +02:00
parent e224a452be
commit ab395a42c8
No known key found for this signature in database
GPG Key ID: 7067AE298F0C655B
5 changed files with 16 additions and 19 deletions

View File

@ -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() {

View File

@ -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")
}

View File

@ -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)

View File

@ -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

View File

@ -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
}