refactor: run config in a lifecycle

This commit is contained in:
Derrick Hammer 2024-02-11 16:32:19 -05:00
parent 34898771ab
commit bbe7e8e053
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 13 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"git.lumeweb.com/LumeWeb/gitea-github-proxy/config" "git.lumeweb.com/LumeWeb/gitea-github-proxy/config"
"github.com/golang-jwt/jwt" "github.com/golang-jwt/jwt"
"go.uber.org/fx"
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"time" "time"
@ -19,8 +20,18 @@ type Oauth struct {
keepAliveRunning bool keepAliveRunning bool
} }
func NewOauth(cfg *config.Config, logger *zap.Logger) *Oauth { func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth {
return &Oauth{cfg: cfg, logger: logger} 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 { func (o Oauth) config() *oauth2.Config {