Skip to content

Commit

Permalink
Perf config
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Sep 15, 2024
1 parent c304e15 commit ccfc540
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
7 changes: 2 additions & 5 deletions cmd/web_server/middleware/login_session.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package middleware

import (
"time"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
auth_module "github.com/oj-lab/platform/modules/auth"
gin_utils "github.com/oj-lab/platform/modules/utils/gin"
)

const (
loginSessionCookieMaxAge = time.Hour * 24 * 7
loginSessionKeyIdCookieName = "LS_KEY_ID"
loginSessionKeyAccountCookieName = "LS_KEY_ACCOUNT"
loginSessionGinCtxKey = "login_session"
Expand Down Expand Up @@ -70,7 +67,7 @@ func GetLoginSessionFromGinCtx(ginCtx *gin.Context) (*auth_module.LoginSession,

func SetLoginSessionKeyCookie(ginCtx *gin.Context, key auth_module.LoginSessionKey) {
ginCtx.SetCookie(loginSessionKeyAccountCookieName, key.Account,
int(loginSessionCookieMaxAge.Seconds()), "/", "", false, true)
int(auth_module.LoginSessionDuration.Seconds()), "/", "", false, true)
ginCtx.SetCookie(loginSessionKeyIdCookieName, key.Id.String(),
int(loginSessionCookieMaxAge.Seconds()), "/", "", false, true)
int(auth_module.LoginSessionDuration.Seconds()), "/", "", false, true)
}
6 changes: 3 additions & 3 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ port = 50051

[minio]
endpoint = "localhost:9000"
accessKeyID = "minio-root-user"
secretAccessKey = "minio-root-password"
access_key_id = "minio-root-user"
secret_access_key = "minio-root-password"
useSSL = false
bucketName = "oj-lab-problem-package"
bucket_name = "oj-lab-problem-package"
8 changes: 4 additions & 4 deletions modules/agent/minio/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

const (
minioEndpointProp = "minio.endpoint"
minioAccessKeyProp = "minio.accessKeyID"
minioSecretAccessKeyProp = "minio.secretAccessKey"
minioUseSSLProp = "minio.useSSL"
minioAccessKeyProp = "minio.access_key_id"
minioSecretAccessKeyProp = "minio.secret_access_key"
minioUseSSLProp = "minio.use_ssl"
minioRegionProp = "minio.region"
minioBucketNameProp = "minio.bucketName"
minioBucketNameProp = "minio.bucket_name"
)

var (
Expand Down
13 changes: 13 additions & 0 deletions modules/auth/login_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@ package auth_module
import (
"context"
"encoding/json"
"time"

"github.com/google/uuid"
config_module "github.com/oj-lab/platform/modules/config"
)

const defaultLoginSessionDuration = time.Hour * 24 * 7

var LoginSessionDuration time.Duration

func init() {
LoginSessionDuration = config_module.AppConfig().GetDuration("service.login_session_duration")
if LoginSessionDuration == 0 {
LoginSessionDuration = defaultLoginSessionDuration
}
}

type LoginSessionKey struct {
Account string
Id uuid.UUID
Expand Down
4 changes: 1 addition & 3 deletions modules/auth/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package auth_module
import (
"context"
"fmt"
"time"

redis_agent "github.com/oj-lab/platform/modules/agent/redis"
log_module "github.com/oj-lab/platform/modules/log"
"github.com/redis/go-redis/v9"
)

const loginSessionKeyFormat = "LS_%s_%s" // "LS_<account>_<uuid>"
const loginSessionDuration = time.Minute * 15

func getLoginSessionRedisKey(key LoginSessionKey) string {
return fmt.Sprintf(loginSessionKeyFormat, key.Account, key.Id.String())
Expand All @@ -25,7 +23,7 @@ func SetLoginSession(ctx context.Context, key LoginSessionKey, data LoginSession
return err
}
// TODO: Watch Redis JSON SET usage, currently not support atomic SETEX
err = redisClient.Set(ctx, getLoginSessionRedisKey(key), value, loginSessionDuration).Err()
err = redisClient.Set(ctx, getLoginSessionRedisKey(key), value, LoginSessionDuration).Err()
if err != nil {
return err
}
Expand Down

0 comments on commit ccfc540

Please sign in to comment.