package auth import ( "time" "github.com/gin-gonic/gin" ) type AuthenticationRequest struct { Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` Token string `json:"token,omitempty"` Captcha string `json:"captcha,omitempty"` Phone string `json:"phone,omitempty"` IP string `json:"ip,omitempty"` } type AuthenticationResponse struct { Token string `json:"token,omitempty"` UID uint64 `json:"uid,omitempty"` Username string `json:"username,omitempty"` Nickname string `json:"nickname,omitempty"` Avatar string `json:"avatar,omitempty"` Phone string `json:"phone,omitempty"` Email string `json:"email,omitempty"` CreatedAt uint `json:"created_at,omitempty"` UpdatedAt uint `json:"updated_at,omitempty"` Code int `json:"-"` } // type IdentifyResult struct { // KubernetesToken string // Cert string // } // 验证账号密码的方法,这里想把这一块单独剥离出去,这样不同的auth就更加抽象化 type IdentifyFunc func(*AuthenticationRequest) (*AuthenticationResponse, error) type AuthManager interface { Login(IdentifyFunc, *AuthenticationRequest) (*AuthenticationResponse, error) Logout(*AuthenticationRequest) error Refresh(*AuthenticationRequest) (string, error) MiddleWare() gin.HandlerFunc // InitAuthRoute(IdentifyFunc, *gin.RouterGroup) ExpireAt(uint64, time.Time) error Expire(uint64, time.Duration) error TTL(uint64) (time.Duration, error) }