feat: update template

This commit is contained in:
2026-08-19 22:05:49 +08:00
parent 0e674e9d56
commit 5a71093b0c
67 changed files with 2070 additions and 585 deletions

View File

@@ -0,0 +1,57 @@
package middleware
import (
"context"
"net/netip"
"time"
)
type requestContextKey struct{}
type RequestContext struct {
RequestID string
StartTime time.Time
Method string
Path string
ClientIp netip.Addr
UserAgent string
Referer string
}
func WithRequestContext(ctx context.Context, req *RequestContext) context.Context {
return context.WithValue(ctx, requestContextKey{}, req)
}
func GetRequestContext(ctx context.Context) *RequestContext {
v, ok := ctx.Value(requestContextKey{}).(*RequestContext)
if !ok {
return nil
}
return v
}
// ----------------------------------------------------------------------------------------
type userContextKey struct{}
type UserContext struct {
UserID int32
IsAdmin bool
TokenVersion int32
}
func WithUserContext(ctx context.Context, user *UserContext) context.Context {
return context.WithValue(ctx, userContextKey{}, user)
}
func GetUserContext(ctx context.Context) *UserContext {
v, ok := ctx.Value(userContextKey{}).(*UserContext)
if !ok {
return nil
}
return v
}