apply staticcheck
This commit is contained in:
parent
e224a452be
commit
ab395a42c8
5 changed files with 16 additions and 19 deletions
|
@ -43,8 +43,8 @@ func NewFreeboxAPIVersion(client *FreeboxHttpClient, discovery FreeboxDiscovery)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.IsValid() == false {
|
if !result.IsValid() {
|
||||||
return nil, errors.New("Could not get the API version")
|
return nil, errors.New("could not get the API version")
|
||||||
}
|
}
|
||||||
log.Debug.Println("APIVersion", result)
|
log.Debug.Println("APIVersion", result)
|
||||||
return result, nil
|
return result, nil
|
||||||
|
@ -56,7 +56,7 @@ func (f *FreeboxAPIVersion) IsValid() bool {
|
||||||
}
|
}
|
||||||
return f.APIDomain != "" &&
|
return f.APIDomain != "" &&
|
||||||
f.UID != "" &&
|
f.UID != "" &&
|
||||||
f.HTTPSAvailable == true &&
|
f.HTTPSAvailable &&
|
||||||
f.HTTPSPort != 0 &&
|
f.HTTPSPort != 0 &&
|
||||||
f.DeviceName != "" &&
|
f.DeviceName != "" &&
|
||||||
f.APIVersion != "" &&
|
f.APIVersion != "" &&
|
||||||
|
@ -65,12 +65,12 @@ func (f *FreeboxAPIVersion) IsValid() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FreeboxAPIVersion) GetURL(path string, miscPath ...interface{}) (string, error) {
|
func (f *FreeboxAPIVersion) GetURL(path string, miscPath ...interface{}) (string, error) {
|
||||||
if f.IsValid() == false {
|
if !f.IsValid() {
|
||||||
return "", errors.New("Invalid FreeboxAPIVersion")
|
return "", errors.New("invalid FreeboxAPIVersion")
|
||||||
}
|
}
|
||||||
versionSplit := strings.Split(f.APIVersion, ".")
|
versionSplit := strings.Split(f.APIVersion, ".")
|
||||||
if len(versionSplit) != 2 {
|
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 := make([]interface{}, len(miscPath)+4)
|
||||||
args[0] = f.APIDomain
|
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 {
|
func (f *FreeboxAPIVersion) getDiscovery(discovery FreeboxDiscovery) func(client *FreeboxHttpClient) error {
|
||||||
function := func(*FreeboxHttpClient) error {
|
function := func(*FreeboxHttpClient) error {
|
||||||
return errors.New("Wrong discovery argument")
|
return errors.New("wrong discovery argument")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch discovery {
|
switch discovery {
|
||||||
|
@ -161,7 +161,6 @@ func (f *FreeboxAPIVersion) newFreeboxAPIVersionMDNS(*FreeboxHttpClient) error {
|
||||||
case "device_type":
|
case "device_type":
|
||||||
f.DeviceType = kv[1]
|
f.DeviceType = kv[1]
|
||||||
default:
|
default:
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if f.IsValid() {
|
if f.IsValid() {
|
||||||
|
|
|
@ -45,7 +45,7 @@ S27oDfFq04XSox7JM9HdTt2hLK96x1T7FpFrBTnALzb7vHv9MhXqAT90fPR/8A==
|
||||||
|
|
||||||
func newTLSConfig() *tls.Config {
|
func newTLSConfig() *tls.Config {
|
||||||
caCertPool := x509.NewCertPool()
|
caCertPool := x509.NewCertPool()
|
||||||
if caCertPool.AppendCertsFromPEM([]byte(freeboxRootCA)) == false {
|
if !caCertPool.AppendCertsFromPEM([]byte(freeboxRootCA)) {
|
||||||
panic("Could not add the certificate")
|
panic("Could not add the certificate")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,11 +52,11 @@ func NewFreeboxConnectionFromConfig(reader io.Reader) (*FreeboxConnection, error
|
||||||
if err := json.NewDecoder(reader).Decode(&config); err != nil {
|
if err := json.NewDecoder(reader).Decode(&config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if config.APIVersion.IsValid() == false {
|
if !config.APIVersion.IsValid() {
|
||||||
return nil, fmt.Errorf("Invalid api_version: %v", config.APIVersion)
|
return nil, fmt.Errorf("invalid api_version: %v", config.APIVersion)
|
||||||
}
|
}
|
||||||
if config.AppToken == "" {
|
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)
|
session, err := NewFreeboxSession(config.AppToken, client, config.APIVersion)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -20,9 +19,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type FreeboxHttpClient struct {
|
type FreeboxHttpClient struct {
|
||||||
client http.Client
|
client http.Client
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
decoder func(io.Reader, interface{}) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type freeboxAPIResponse struct {
|
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 {
|
if err := json.Unmarshal(body, &apiResponse); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if apiResponse.Success == false {
|
if !apiResponse.Success {
|
||||||
switch apiResponse.ErrorCode {
|
switch apiResponse.ErrorCode {
|
||||||
case errAuthRequired.Error():
|
case errAuthRequired.Error():
|
||||||
return errAuthRequired
|
return errAuthRequired
|
||||||
|
|
|
@ -67,7 +67,7 @@ func GetAppToken(client *FreeboxHttpClient, apiVersion *FreeboxAPIVersion) (stri
|
||||||
case "granted":
|
case "granted":
|
||||||
return postResponse.AppToken, nil
|
return postResponse.AppToken, nil
|
||||||
default:
|
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()
|
f.sessionTokenLock.Lock()
|
||||||
defer f.sessionTokenLock.Unlock()
|
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)
|
log.Debug.Printf("Updated %v ago. Skipping", sinceLastUpdate)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue