wip: 登录和认证

This commit is contained in:
loveuer
2025-07-13 22:57:57 +08:00
parent 48af538f98
commit b48fa05d9f
33 changed files with 1961 additions and 33 deletions

55
pkg/database/cache/option.go vendored Normal file
View File

@ -0,0 +1,55 @@
package cache
import (
"context"
"fmt"
"net/url"
)
type option struct {
ctx context.Context
redis *string
memory bool
}
type Option func(*option)
func WithCtx(ctx context.Context) Option {
return func(c *option) {
if ctx != nil {
c.ctx = ctx
}
}
}
func WithRedis(host string, port int, username, password string) Option {
return func(c *option) {
uri := fmt.Sprintf("redis://%s:%d", host, port)
if username != "" || password != "" {
uri = fmt.Sprintf("redis://%s:%s@%s:%d", username, password, host, port)
}
c.redis = &uri
}
}
func WithRedisURI(uri string) Option {
return func(c *option) {
ins, err := url.Parse(uri)
if err != nil {
return
}
if ins.Scheme != "redis" {
return
}
c.redis = &uri
}
}
func WithMemory() Option {
return func(c *option) {
c.memory = true
}
}