diff --git a/cmd/web_server/handler/frontend.go b/cmd/web_server/handler/frontend.go index 3fc83f7..4472dfb 100644 --- a/cmd/web_server/handler/frontend.go +++ b/cmd/web_server/handler/frontend.go @@ -16,6 +16,7 @@ func SetupFrontendRoute(baseRoute *gin.RouterGroup, frontendDist string) { g.GET("/admin", RenderHTML) g.GET("/admin/problem", RenderHTML) + // Static file routing g.Static("manifest.json", fmt.Sprintf("%s/manifest.json", frontendDist)) g.Static("/assets", fmt.Sprintf("%s/assets", frontendDist)) g.Static("/avatars", fmt.Sprintf("%s/avatars", frontendDist)) diff --git a/cmd/web_server/handler/problem.go b/cmd/web_server/handler/problem.go index 186bac6..e792762 100644 --- a/cmd/web_server/handler/problem.go +++ b/cmd/web_server/handler/problem.go @@ -2,7 +2,6 @@ package handler import ( "net/http" - "strconv" "github.com/gin-gonic/gin" judge_model "github.com/oj-lab/oj-lab-platform/models/judge" @@ -95,20 +94,12 @@ func deleteProblem(ginCtx *gin.Context) { // @Accept json // @Success 200 func getProblemInfoList(ginCtx *gin.Context) { - limitStr := ginCtx.Query("limit") - offsetStr := ginCtx.Query("offset") - if limitStr == "" { - limitStr = "10" - } - if offsetStr == "" { - offsetStr = "0" - } - limit, err := strconv.Atoi(limitStr) + limit, err := gin_utils.QueryInt(ginCtx, "limit", 10) if err != nil { gin_utils.NewInvalidParamError(ginCtx, "limit", err.Error()) return } - offset, err := strconv.Atoi(offsetStr) + offset, err := gin_utils.QueryInt(ginCtx, "offset", 0) if err != nil { gin_utils.NewInvalidParamError(ginCtx, "offset", err.Error()) return diff --git a/cmd/web_server/handler/user.go b/cmd/web_server/handler/user.go index 00b8e79..7748031 100644 --- a/cmd/web_server/handler/user.go +++ b/cmd/web_server/handler/user.go @@ -3,7 +3,6 @@ package handler import ( "fmt" "net/http" - "strconv" "strings" "github.com/gin-gonic/gin" @@ -52,21 +51,21 @@ func AddUserCasbinPolicies() error { } func GetUserList(ginCtx *gin.Context) { - options := user_model.GetUserOptions{} - limitStr := ginCtx.Query("limit") - offsetStr := ginCtx.Query("offset") - limit, err := strconv.Atoi(limitStr) + limit, err := gin_utils.QueryInt(ginCtx, "limit", 10) if err != nil { - limit = 10 + gin_utils.NewInvalidParamError(ginCtx, "limit", err.Error()) + return } - offset, err := strconv.Atoi(offsetStr) + offset, err := gin_utils.QueryInt(ginCtx, "offset", 0) if err != nil { - offset = 0 + gin_utils.NewInvalidParamError(ginCtx, "offset", err.Error()) + return } - options.Limit = func() *int { return &limit }() - options.Offset = func() *int { return &offset }() - users, total, err := user_service.GetUserList(ginCtx, options) + users, total, err := user_service.GetUserList(ginCtx, user_model.GetUserOptions{ + Limit: &limit, + Offset: &offset, + }) if err != nil { gin_utils.NewInternalError(ginCtx, fmt.Sprintf("failed to get user list: %v", err)) return diff --git a/modules/auth/github.go b/modules/auth/github.go index 0c2406e..b905b0f 100644 --- a/modules/auth/github.go +++ b/modules/auth/github.go @@ -9,21 +9,24 @@ import ( config_module "github.com/oj-lab/oj-lab-platform/modules/config" ) -const githubOauthEntryURL = "https://github.com/login/oauth/authorize" -const githubAccessTokenURL = "https://github.com/login/oauth/access_token" -const githubApiUserURL = "https://api.github.com/user" - const ( + githubOauthEntryURL = "https://github.com/login/oauth/authorize" + githubAccessTokenURL = "https://github.com/login/oauth/access_token" + githubApiUserURL = "https://api.github.com/user" + servicePortProp = "service.port" serviceHostProp = "service.host" serviceSSLEnabledProp = "service.ssl_enabled" ) -var githubClientID string -var githubClientSecret string -var servicePort uint -var serviceHost string -var serviceSSLEnabled bool +var ( + githubClientID string + githubClientSecret string + + servicePort uint + serviceHost string + serviceSSLEnabled bool +) func init() { githubClientID = config_module.AppConfig().GetString("auth_modulegithub.client_id") diff --git a/modules/auth/jwt.go b/modules/auth/jwt.go index 7ca899e..fbb2ed2 100644 --- a/modules/auth/jwt.go +++ b/modules/auth/jwt.go @@ -8,8 +8,10 @@ import ( config_module "github.com/oj-lab/oj-lab-platform/modules/config" ) -var jwtSecret string -var jwtDuration time.Duration +var ( + jwtSecret string + jwtDuration time.Duration +) func init() { jwtSecret = config_module.AppConfig().GetString("jwt.secret")