From bbe7e8e05350d692b3f8cc21c731436900754d47 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 11 Feb 2024 16:32:19 -0500 Subject: [PATCH] refactor: run config in a lifecycle --- api/oauth.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/api/oauth.go b/api/oauth.go index 843f1c0..420f5a0 100644 --- a/api/oauth.go +++ b/api/oauth.go @@ -6,6 +6,7 @@ import ( "fmt" "git.lumeweb.com/LumeWeb/gitea-github-proxy/config" "github.com/golang-jwt/jwt" + "go.uber.org/fx" "go.uber.org/zap" "golang.org/x/oauth2" "time" @@ -19,8 +20,18 @@ type Oauth struct { keepAliveRunning bool } -func NewOauth(cfg *config.Config, logger *zap.Logger) *Oauth { - return &Oauth{cfg: cfg, logger: logger} +func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth { + oa := &Oauth{cfg: cfg, logger: logger} + + lc.Append(fx.Hook{ + OnStart: func(ctx context.Context) error { + oa.config() + + return nil + }, + }) + + return oa } func (o Oauth) config() *oauth2.Config {