diff --git a/charger/simpleevse.go b/charger/simpleevse.go index d18c216a4..f5ac72abe 100644 --- a/charger/simpleevse.go +++ b/charger/simpleevse.go @@ -38,7 +38,7 @@ func NewSimpleEVSE(conn, device string) (api.Charger, error) { var handler modbus.ClientHandler if conn != "" && device != "" { - log.FATAL.Fatal("cannot define uri and device both") + return nil, errors.New("cannot define uri and device both") } if conn != "" { handler = modbus.NewTCPClientHandler(conn) diff --git a/provider/http.go b/provider/http.go index a59383dd5..c24a180bd 100644 --- a/provider/http.go +++ b/provider/http.go @@ -31,13 +31,14 @@ type Auth struct { } // NewAuth creates authorization headers from config -func NewAuth(log *util.Logger, auth Auth, headers map[string]string) { +func NewAuth(log *util.Logger, auth Auth, headers map[string]string) error { if strings.ToLower(auth.Type) != "basic" { - log.FATAL.Fatalf("unsupported auth type: %s", auth.Type) + return fmt.Errorf("unsupported auth type: %s", auth.Type) } basicAuth := auth.User + ":" + auth.Password headers["Authorization"] = "Basic " + base64.StdEncoding.EncodeToString([]byte(basicAuth)) + return nil } // NewHTTPProviderFromConfig creates a HTTP provider @@ -50,7 +51,7 @@ func NewHTTPProviderFromConfig(other map[string]interface{}) (*HTTP, error) { Scale float64 Insecure bool Auth Auth - }{} + }{Headers: make(map[string]string)} if err := util.DecodeOther(other, &cc); err != nil { return nil, err @@ -69,10 +70,9 @@ func NewHTTPProviderFromConfig(other map[string]interface{}) (*HTTP, error) { // handle basic auth if cc.Auth.Type != "" { - if p.headers == nil { - p.headers = make(map[string]string) + if err := NewAuth(log, cc.Auth, p.headers); err != nil { + return nil, err } - NewAuth(log, cc.Auth, p.headers) } // ignore the self signed certificate diff --git a/provider/socket.go b/provider/socket.go index 33a4aecdc..3904b5975 100644 --- a/provider/socket.go +++ b/provider/socket.go @@ -37,7 +37,7 @@ func NewSocketProviderFromConfig(other map[string]interface{}) (*Socket, error) Insecure bool Auth Auth Timeout time.Duration - }{} + }{Headers: make(map[string]string)} if err := util.DecodeOther(other, &cc); err != nil { return nil, err } @@ -54,10 +54,9 @@ func NewSocketProviderFromConfig(other map[string]interface{}) (*Socket, error) // handle basic auth if cc.Auth.Type != "" { - if p.headers == nil { - p.headers = make(map[string]string) + if err := NewAuth(log, cc.Auth, p.headers); err != nil { + return nil, err } - NewAuth(log, cc.Auth, p.headers) } // ignore the self signed certificate diff --git a/util/test/errors.go b/util/test/errors.go index fb08dae46..a88224496 100644 --- a/util/test/errors.go +++ b/util/test/errors.go @@ -11,7 +11,7 @@ const config = "../errors.yaml" var acceptable map[string][]string -// Acceptable returns true is a test error is configured as acceptable +// Acceptable checks if a test error is configured as acceptable func Acceptable(class string, err error) bool { if len(acceptable) == 0 { definitions, err := ioutil.ReadFile(config)