diff options
| -rw-r--r-- | backend/.golangci.yml | 1 | ||||
| -rw-r--r-- | backend/api/handler_wrapper.go | 4 | ||||
| -rw-r--r-- | backend/api/handlers.go | 10 | ||||
| -rw-r--r-- | backend/api/workaround.go | 2 | ||||
| -rw-r--r-- | backend/gen/api/handler_wrapper_gen.go | 18 | ||||
| -rw-r--r-- | backend/main.go | 4 | ||||
| -rw-r--r-- | backend/taskqueue/processor.go | 12 |
7 files changed, 26 insertions, 25 deletions
diff --git a/backend/.golangci.yml b/backend/.golangci.yml index a8eddf8..a6494c0 100644 --- a/backend/.golangci.yml +++ b/backend/.golangci.yml @@ -2,3 +2,4 @@ linters: enable: - gofmt - goimports + - stylecheck diff --git a/backend/api/handler_wrapper.go b/backend/api/handler_wrapper.go index fdee581..748af66 100644 --- a/backend/api/handler_wrapper.go +++ b/backend/api/handler_wrapper.go @@ -14,12 +14,12 @@ import ( var _ StrictServerInterface = (*ApiHandlerWrapper)(nil) type ApiHandlerWrapper struct { - innerHandler ApiHandler + innerHandler APIHandler } func NewHandler(queries *db.Queries, hubs GameHubsInterface) *ApiHandlerWrapper { return &ApiHandlerWrapper{ - innerHandler: ApiHandler{ + innerHandler: APIHandler{ q: queries, hubs: hubs, }, diff --git a/backend/api/handlers.go b/backend/api/handlers.go index 659e5c1..229246f 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -12,7 +12,7 @@ import ( "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" ) -type ApiHandler struct { +type APIHandler struct { q *db.Queries hubs GameHubsInterface } @@ -21,7 +21,7 @@ type GameHubsInterface interface { StartGame(gameID int) error } -func (h *ApiHandler) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) { +func (h *APIHandler) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) { username := request.Body.Username password := request.Body.Password userID, err := auth.Login(ctx, h.q, username, password) @@ -52,7 +52,7 @@ func (h *ApiHandler) PostLogin(ctx context.Context, request PostLoginRequestObje }, nil } -func (h *ApiHandler) GetToken(ctx context.Context, request GetTokenRequestObject, user *auth.JWTClaims) (GetTokenResponseObject, error) { +func (h *APIHandler) GetToken(ctx context.Context, request GetTokenRequestObject, user *auth.JWTClaims) (GetTokenResponseObject, error) { newToken, err := auth.NewShortLivedJWT(user) if err != nil { return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) @@ -62,7 +62,7 @@ func (h *ApiHandler) GetToken(ctx context.Context, request GetTokenRequestObject }, nil } -func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject, user *auth.JWTClaims) (GetGamesResponseObject, error) { +func (h *APIHandler) GetGames(ctx context.Context, request GetGamesRequestObject, user *auth.JWTClaims) (GetGamesResponseObject, error) { gameRows, err := h.q.ListGamesForPlayer(ctx, int32(user.UserID)) if err != nil { return nil, echo.NewHTTPError(http.StatusInternalServerError, err.Error()) @@ -100,7 +100,7 @@ func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject }, nil } -func (h *ApiHandler) GetGame(ctx context.Context, request GetGameRequestObject, user *auth.JWTClaims) (GetGameResponseObject, error) { +func (h *APIHandler) GetGame(ctx context.Context, request GetGameRequestObject, user *auth.JWTClaims) (GetGameResponseObject, error) { // TODO: check user permission gameID := request.GameID row, err := h.q.GetGameByID(ctx, int32(gameID)) diff --git a/backend/api/workaround.go b/backend/api/workaround.go index a3c47d7..5b5fe59 100644 --- a/backend/api/workaround.go +++ b/backend/api/workaround.go @@ -12,7 +12,7 @@ func GetSwaggerWithPrefix(prefix string) (*openapi3.T, error) { return nil, err } - var prefixedPaths openapi3.Paths = openapi3.Paths{} + prefixedPaths := openapi3.Paths{} for key, value := range spec.Paths.Map() { prefixedPaths.Set(prefix+key, value) } diff --git a/backend/gen/api/handler_wrapper_gen.go b/backend/gen/api/handler_wrapper_gen.go index 7fd34b2..42fc5e8 100644 --- a/backend/gen/api/handler_wrapper_gen.go +++ b/backend/gen/api/handler_wrapper_gen.go @@ -111,15 +111,15 @@ import ( "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" ) -var _ StrictServerInterface = (*ApiHandlerWrapper)(nil) +var _ StrictServerInterface = (*APIHandlerWrapper)(nil) -type ApiHandlerWrapper struct { - innerHandler ApiHandler +type APIHandlerWrapper struct { + impl APIHandler } -func NewHandler(queries *db.Queries, hubs GameHubsInterface) *ApiHandlerWrapper { - return &ApiHandlerWrapper{ - innerHandler: ApiHandler{ +func NewHandler(queries *db.Queries, hubs GameHubsInterface) *APIHandlerWrapper { + return &APIHandlerWrapper{ + impl: APIHandler{ q: queries, hubs: hubs, }, @@ -140,7 +140,7 @@ func parseJWTClaimsFromAuthorizationHeader(authorization string) (*auth.JWTClaim } {{ range . }} - func (h *ApiHandlerWrapper) {{ .Name }}(ctx context.Context, request {{ .Name }}RequestObject) ({{ .Name }}ResponseObject, error) { + func (h *APIHandlerWrapper) {{ .Name }}(ctx context.Context, request {{ .Name }}RequestObject) ({{ .Name }}ResponseObject, error) { {{ if .RequiresLogin -}} user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization) if err != nil { @@ -159,9 +159,9 @@ func parseJWTClaimsFromAuthorizationHeader(authorization string) (*auth.JWTClaim }, nil } {{ end -}} - return h.innerHandler.{{ .Name }}(ctx, request, user) + return h.impl.{{ .Name }}(ctx, request, user) {{ else -}} - return h.innerHandler.{{ .Name }}(ctx, request) + return h.impl.{{ .Name }}(ctx, request) {{ end -}} } {{ end }} diff --git a/backend/main.go b/backend/main.go index 9f92415..c8a5832 100644 --- a/backend/main.go +++ b/backend/main.go @@ -38,7 +38,7 @@ func main() { log.Fatalf("Error loading env %v", err) } - openApiSpec, err := api.GetSwaggerWithPrefix("/api") + openAPISpec, err := api.GetSwaggerWithPrefix("/api") if err != nil { log.Fatalf("Error loading OpenAPI spec\n: %s", err) } @@ -79,7 +79,7 @@ func main() { }) apiGroup := e.Group("/api") - apiGroup.Use(oapimiddleware.OapiRequestValidator(openApiSpec)) + apiGroup.Use(oapimiddleware.OapiRequestValidator(openAPISpec)) apiHandler := api.NewHandler(queries, gameHubs) api.RegisterHandlers(apiGroup, api.NewStrictHandler(apiHandler, nil)) diff --git a/backend/taskqueue/processor.go b/backend/taskqueue/processor.go index b64b01c..cf90cbc 100644 --- a/backend/taskqueue/processor.go +++ b/backend/taskqueue/processor.go @@ -58,11 +58,11 @@ func (p *processor) doProcessTaskCompileSwiftToWasm( MaxDuration: 5000, Code: payload.Code(), } - reqJson, err := json.Marshal(reqData) + reqJSON, err := json.Marshal(reqData) if err != nil { return nil, fmt.Errorf("json.Marshal failed: %v", err) } - res, err := http.Post("http://worker:80/api/swiftc", "application/json", bytes.NewBuffer(reqJson)) + res, err := http.Post("http://worker:80/api/swiftc", "application/json", bytes.NewBuffer(reqJSON)) if err != nil { return nil, fmt.Errorf("http.Post failed: %v", err) } @@ -95,11 +95,11 @@ func (p *processor) doProcessTaskCompileWasmToNativeExecutable( MaxDuration: 5000, Code: payload.Code(), } - reqJson, err := json.Marshal(reqData) + reqJSON, err := json.Marshal(reqData) if err != nil { return nil, fmt.Errorf("json.Marshal failed: %v", err) } - res, err := http.Post("http://worker:80/api/wasmc", "application/json", bytes.NewBuffer(reqJson)) + res, err := http.Post("http://worker:80/api/wasmc", "application/json", bytes.NewBuffer(reqJSON)) if err != nil { return nil, fmt.Errorf("http.Post failed: %v", err) } @@ -134,11 +134,11 @@ func (p *processor) doProcessTaskRunTestcase( Code: payload.Code(), Stdin: payload.Stdin, } - reqJson, err := json.Marshal(reqData) + reqJSON, err := json.Marshal(reqData) if err != nil { return nil, fmt.Errorf("json.Marshal failed: %v", err) } - res, err := http.Post("http://worker:80/api/testrun", "application/json", bytes.NewBuffer(reqJson)) + res, err := http.Post("http://worker:80/api/testrun", "application/json", bytes.NewBuffer(reqJSON)) if err != nil { return nil, fmt.Errorf("http.Post failed: %v", err) } |
