Skip to content

Commit

Permalink
Tidy code
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Aug 3, 2024
1 parent cb6a4b0 commit 6e9b71d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
1 change: 1 addition & 0 deletions cmd/web_server/handler/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 2 additions & 11 deletions cmd/web_server/handler/problem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
21 changes: 10 additions & 11 deletions cmd/web_server/handler/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handler
import (
"fmt"
"net/http"
"strconv"
"strings"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions modules/auth/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions modules/auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 6e9b71d

Please sign in to comment.