refactor color system to be separate from models, also move errors out of models.
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-02-28 22:52:06 +01:00
parent df865574bf
commit 62e7cb88f4
32 changed files with 532 additions and 516 deletions
+10 -9
View File
@@ -7,6 +7,7 @@ import (
"crypto/sha1"
"encoding/json"
"fmt"
"git.aiterp.net/lucifer/new-server/internal/lerrors"
"git.aiterp.net/lucifer/new-server/models"
"io"
"log"
@@ -163,9 +164,9 @@ func (b *bridge) command(ctx context.Context, command string, payload interface{
res, err := http.DefaultClient.Do(req)
if err != nil {
return models.ErrCannotForwardRequest
return lerrors.ErrCannotForwardRequest
} else if res.StatusCode != 200 {
return models.ErrIncorrectToken
return lerrors.ErrIncorrectToken
}
if target == nil {
@@ -174,7 +175,7 @@ func (b *bridge) command(ctx context.Context, command string, payload interface{
err = json.NewDecoder(res.Body).Decode(&target)
if err != nil {
return models.ErrUnexpectedResponse
return lerrors.ErrUnexpectedResponse
}
return nil
@@ -190,27 +191,27 @@ func (b *bridge) authenticate(ctx context.Context) error {
Password: b.password,
})
if err != nil {
return models.ErrMissingToken
return lerrors.ErrMissingToken
}
req, err := http.NewRequestWithContext(ctx, "POST", accountEndpoint + "login", bytes.NewReader(body))
req, err := http.NewRequestWithContext(ctx, "POST", accountEndpoint+"login", bytes.NewReader(body))
if err != nil {
return models.ErrMissingToken
return lerrors.ErrMissingToken
}
addDefaultHeaders(req)
res, err := http.DefaultClient.Do(req)
if err != nil {
return models.ErrCannotForwardRequest
return lerrors.ErrCannotForwardRequest
} else if res.StatusCode != 200 {
return models.ErrIncorrectToken
return lerrors.ErrIncorrectToken
}
var resBody authResBody
err = json.NewDecoder(res.Body).Decode(&resBody)
if err != nil {
return models.ErrBridgeSearchFailed
return lerrors.ErrBridgeSearchFailed
}
log.Printf("Mill: Authenticated as %s", resBody.NickName)