to options mode

This commit is contained in:
yanghao05
2023-04-27 18:30:39 +08:00
parent 8ae3d19aa9
commit 574736a878
20 changed files with 180 additions and 50 deletions

View File

@@ -6,7 +6,8 @@ import (
"time"
"github.com/rogeecn/atom/container"
"go.uber.org/dig"
"github.com/rogeecn/atom/providers"
"github.com/rogeecn/atom/providers/log"
jwt "github.com/golang-jwt/jwt/v4"
"golang.org/x/sync/singleflight"
@@ -43,13 +44,17 @@ var (
TokenInvalid = errors.New("Couldn't handle this token:")
)
func Provide(config *Config, opts ...dig.ProvideOption) error {
func Provide(o *providers.Options) error {
var config Config
if err := o.UnmarshalConfig(&config); err != nil {
log.Fatal(err)
}
return container.Container.Provide(func() (*JWT, error) {
return &JWT{
config: config,
config: &config,
SigningKey: []byte(config.SigningKey),
}, nil
}, opts...)
}, o.DiOptions()...)
}
func (j *JWT) CreateClaims(baseClaims BaseClaims) *Claims {