Skip to content

Commit e393089

Browse files
committed
update
1 parent f220691 commit e393089

File tree

8 files changed

+18
-28
lines changed

8 files changed

+18
-28
lines changed

codegen/tml/config/template_config.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,11 @@ import (
113113
// AppConfig can hot update
114114
// this is the config used for this app
115115
type AppConfig struct {
116-
HandlerTimeout map[string]map[string]ctime.Duration $json:"handler_timeout"$ //first key path,second key method(GET,POST,PUT,PATCH,DELETE,CRPC,GRPC),value timeout
117-
WebPathRewrite map[string]map[string]string $json:"web_path_rewrite"$ //first key method(GET,POST,PUT,PATCH,DELETE),second key origin url,value new url
118-
HandlerRate publicmids.MultiPathRateConfigs $json:"handler_rate"$ //key:path
119-
Accesses publicmids.MultiPathAccessConfigs $json:"accesses"$ //key:path
120-
TokenSecret string $json:"token_secret"$ //if don't need token check,this can be ingored
121-
SessionTokenExpire ctime.Duration $json:"session_token_expire"$ //if don't need session and token check,this can be ignored
116+
HandlerTimeout map[string]map[string]ctime.Duration $json:"handler_timeout"$ //first key path,second key method(GET,POST,PUT,PATCH,DELETE,CRPC,GRPC),value timeout
117+
WebPathRewrite map[string]map[string]string $json:"web_path_rewrite"$ //first key method(GET,POST,PUT,PATCH,DELETE),second key origin url,value new url
118+
HandlerRate publicmids.MultiPathRateConfigs $json:"handler_rate"$ //key:path
119+
Accesses publicmids.MultiPathAccessConfigs $json:"accesses"$ //key:path
120+
TokenSecret string $json:"token_secret"$ //if don't need token check,this can be ingored
122121
Service *ServiceConfig $json:"service"$
123122
}
124123
type ServiceConfig struct {

codegen/tml/configfile/template_configfile.go

-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ const app = `{
147147
}]
148148
},
149149
"token_secret":"test",
150-
"session_token_expire":"24h",
151150
"service":{
152151
153152
}

codegen/tml/mainfile/template_main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ func main() {
9797
xweb.UpdateHandlerTimeout(ac.HandlerTimeout)
9898
xweb.UpdateWebPathRewrite(ac.WebPathRewrite)
9999
publicmids.UpdateRateConfig(ac.HandlerRate)
100-
publicmids.UpdateTokenConfig(ac.TokenSecret, ac.SessionTokenExpire.StdDuration())
101-
publicmids.UpdateSessionConfig(ac.SessionTokenExpire.StdDuration())
100+
publicmids.UpdateTokenConfig(ac.TokenSecret)
102101
publicmids.UpdateAccessConfig(ac.Accesses)
103102
})
104103
if rateredis := config.GetRedis("rate_redis"); rateredis != nil {

internal/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "fmt"
44

55
var major = 0
66
var minor = 0
7-
var patch = 119
7+
var patch = 120
88
var status = ""
99

1010
func String() string {

mids/session.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ import (
1414
)
1515

1616
var sessionredis *redis.Client
17-
var sessionexpire time.Duration
1817

19-
func UpdateSessionConfig(expire time.Duration) {
20-
sessionexpire = expire
21-
}
2218
func UpdateSessionRedisInstance(c *redis.Client) {
2319
if c == nil {
2420
slog.WarnContext(nil, "[session] redis missing,all session event will be failed")
@@ -31,7 +27,7 @@ func UpdateSessionRedisInstance(c *redis.Client) {
3127

3228
// return empty means make session failed
3329
// user should put the return data in web's Session header or metadata's Session field
34-
func MakeSession(ctx context.Context, userid, data string) string {
30+
func MakeSession(ctx context.Context, userid, data string,expire time.Duration) string {
3531
redisclient := sessionredis
3632
if redisclient == nil {
3733
slog.ErrorContext(ctx, "[session.make] redis missing")
@@ -40,7 +36,7 @@ func MakeSession(ctx context.Context, userid, data string) string {
4036
result := make([]byte, 8)
4137
rand.Read(result)
4238
sessionid := hex.EncodeToString(result)
43-
if _, e := redisclient.SetEx(ctx, "session_"+userid, sessionid+"_"+data, sessionexpire).Result(); e != nil {
39+
if _, e := redisclient.SetEx(ctx, "session_"+userid, sessionid+"_"+data, expire).Result(); e != nil {
4440
slog.ErrorContext(ctx, "[session.make] write session data failed", slog.String("userid", userid), slog.String("error", e.Error()))
4541
return ""
4642
}

mids/session_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ func Test_Session(t *testing.T) {
1919
IOTimeout: ctime.Duration(time.Second),
2020
}, nil)
2121
UpdateSessionRedisInstance(client)
22-
UpdateSessionConfig(time.Second)
23-
sessionstr := MakeSession(context.Background(), "1", "123")
22+
sessionstr := MakeSession(context.Background(), "1", "123",time.Second)
2423
if sessionstr == "" {
2524
t.Fatal("should make session success")
2625
}
@@ -39,7 +38,7 @@ func Test_Session(t *testing.T) {
3938
if status {
4039
t.Fatal("should not verify success")
4140
}
42-
sessionstr = MakeSession(context.Background(), "1", "123")
41+
sessionstr = MakeSession(context.Background(), "1", "123",time.Second)
4342
if sessionstr == "" {
4443
t.Fatal("should make session success")
4544
}

mids/token.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@ type Token struct {
2020
}
2121

2222
var tokensecret string
23-
var tokenexpire time.Duration
2423

25-
func UpdateTokenConfig(secret string, expire time.Duration) {
24+
func UpdateTokenConfig(secret string) {
2625
tokensecret = secret
27-
tokenexpire = expire
2826
}
2927

3028
// return empty means make token failed
3129
// put the return data in web's Token header or metadata's Token field
32-
func MakeToken(ctx context.Context, puber, deployenv, runenv, userid, data string) string {
30+
func MakeToken(ctx context.Context, puber, deployenv, runenv, userid, data string, expire time.Duration) string {
3331
start := time.Now()
34-
end := start.Add(tokenexpire)
32+
end := start.Add(expire)
3533
t, _ := json.Marshal(&Token{
3634
Puber: puber,
3735
DeployEnv: deployenv,

mids/token_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
func Test_Token(t *testing.T) {
1010
userid := "userid1"
1111
data := "dajsldjlashdohasobncasbjkdhaosjdoasjdoiajsodjnlajsnckjbakjsdashdjkasdoqhwofhbihdbvisadofjaoasdjlasjdlajsldjoaisjdoajsodijasdjlaksjdlkajsldjlaksjdlaslsdlaksjdlajsldjalsjdlasjdlajlsdjalsjdlasjdlasjdlkasjldkajsldkjalskdjlkjdlsjdoas"
12-
UpdateTokenConfig("123", time.Second)
13-
tokenstr := MakeToken(context.Background(), "corelib", "ali", "test", userid, data)
12+
UpdateTokenConfig("123")
13+
tokenstr := MakeToken(context.Background(), "corelib", "ali", "test", userid, data, time.Second)
1414
if tokenstr == "" {
1515
t.Fatal("should make token success")
1616
}
@@ -24,12 +24,12 @@ func Test_Token(t *testing.T) {
2424
if token.Data != data {
2525
t.Fatal("data broken")
2626
}
27-
UpdateTokenConfig("abc", time.Second)
27+
UpdateTokenConfig("abc")
2828
token = VerifyToken(context.Background(), tokenstr)
2929
if token != nil {
3030
t.Fatal("should not verify token success")
3131
}
32-
UpdateTokenConfig("123", time.Second)
32+
UpdateTokenConfig("123")
3333
time.Sleep(time.Second * 2)
3434
token = VerifyToken(context.Background(), tokenstr)
3535
if token != nil {

0 commit comments

Comments
 (0)