package jwt import ( "git.0x7f.app/WOJ/woj-server/internal/e" "git.0x7f.app/WOJ/woj-server/internal/misc/config" "git.0x7f.app/WOJ/woj-server/internal/misc/log" "git.0x7f.app/WOJ/woj-server/internal/model" "git.0x7f.app/WOJ/woj-server/internal/repo/cache" "github.com/gin-gonic/gin" "github.com/samber/do" "go.uber.org/zap" ) var _ Service = (*service)(nil) type Service interface { ParseToken(tokenText string) (*model.Claim, e.Status) SignClaim(claim *model.Claim) (string, e.Status) Validate(claim *model.Claim) bool Handler(forced bool) gin.HandlerFunc HealthCheck() error } func NewService(i *do.Injector) (Service, error) { srv := &service{} srv.log = do.MustInvoke[log.Service](i).GetLogger("jwt") srv.cacheService = do.MustInvoke[cache.Service](i) // .Get().(*redis.Client) conf := do.MustInvoke[config.Service](i).GetConfig() srv.SigningKey = []byte(conf.WebServer.JWT.SigningKey) srv.ExpireHour = conf.WebServer.JWT.ExpireHour return srv, srv.err } type service struct { cacheService cache.Service log *zap.Logger SigningKey []byte ExpireHour int err error } func (s *service) HealthCheck() error { return s.err }