mg.config를 config로 변경
This commit is contained in:
@ -127,8 +127,6 @@ func (ga *globalAdmins) parse() {
|
||||
|
||||
// Maingate :
|
||||
type Maingate struct {
|
||||
maingateConfig
|
||||
|
||||
mongoClient gocommon.MongoClient
|
||||
|
||||
sessionProvider session.Provider
|
||||
@ -146,9 +144,10 @@ type Maingate struct {
|
||||
firebaseAppContext context.Context
|
||||
}
|
||||
|
||||
var config maingateConfig
|
||||
|
||||
// New :
|
||||
func New(ctx context.Context) (*Maingate, error) {
|
||||
var config maingateConfig
|
||||
if err := gocommon.LoadConfig(&config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -167,7 +166,6 @@ func New(ctx context.Context) (*Maingate, error) {
|
||||
}
|
||||
|
||||
mg := Maingate{
|
||||
maingateConfig: config,
|
||||
admins: unsafe.Pointer(&admins),
|
||||
tokenEndpoints: make(map[string]string),
|
||||
authorizationEndpoints: make(map[string]string),
|
||||
@ -181,7 +179,7 @@ func New(ctx context.Context) (*Maingate, error) {
|
||||
}
|
||||
|
||||
if !*noauth {
|
||||
opt := option.WithCredentialsFile(mg.FirebaseAdminSDKCredentialFile)
|
||||
opt := option.WithCredentialsFile(config.FirebaseAdminSDKCredentialFile)
|
||||
firebaseApp, err := firebase.NewApp(context.Background(), nil, opt)
|
||||
if err != nil {
|
||||
logger.Error("firebase admin error initializing app failed :", err)
|
||||
@ -265,7 +263,7 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
||||
}
|
||||
|
||||
// redis에서 env를 가져온 후에
|
||||
mg.mongoClient, err = gocommon.NewMongoClient(context, mg.Mongo)
|
||||
mg.mongoClient, err = gocommon.NewMongoClient(context, config.Mongo)
|
||||
if err != nil {
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
@ -320,7 +318,7 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionPlatformLoginToken, int32(mg.SessionTTL+300)); err != nil {
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionPlatformLoginToken, int32(config.SessionTTL+300)); err != nil {
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
@ -342,7 +340,7 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
mg.sessionProvider, err = session.NewProviderWithConfig(context, mg.SessionConfig)
|
||||
mg.sessionProvider, err = session.NewProviderWithConfig(context, config.SessionConfig)
|
||||
if err != nil {
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
@ -461,7 +459,7 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
})
|
||||
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "api/"), mg.api)
|
||||
|
||||
configraw, _ := json.Marshal(mg.maingateConfig)
|
||||
configraw, _ := json.Marshal(config)
|
||||
var convertedConfig map[string]any
|
||||
if err := json.Unmarshal(configraw, &convertedConfig); err != nil {
|
||||
return logger.ErrorWithCallStack(err)
|
||||
@ -613,7 +611,7 @@ func (mg *Maingate) getUserTokenWithCheck(platform string, userid string, brinfo
|
||||
|
||||
updatetime, ok := found["lastupdate"].(int64)
|
||||
|
||||
if !ok || time.Now().Unix()-updatetime < mg.maingateConfig.Autologin_ttl {
|
||||
if !ok || time.Now().Unix()-updatetime < config.Autologin_ttl {
|
||||
info.platform = platform
|
||||
info.userid = userid
|
||||
info.brinfo = brinfo
|
||||
@ -874,14 +872,14 @@ func JWTparseCode(keyurl string, code string) (string, string, string) {
|
||||
|
||||
func (mg *Maingate) google_analytics_js(w http.ResponseWriter, r *http.Request) {
|
||||
fgaconfig := Firebase_Google_Analytics_JS_SDK_Config{
|
||||
FGA_apiKey: mg.FGA_apiKey,
|
||||
FGA_authDomain: mg.FGA_authDomain,
|
||||
FGA_databaseURL: mg.FGA_databaseURL,
|
||||
FGA_projectId: mg.FGA_projectId,
|
||||
FGA_storageBucket: mg.FGA_storageBucket,
|
||||
FGA_messagingSenderId: mg.FGA_messagingSenderId,
|
||||
FGA_appId: mg.FGA_appId,
|
||||
FGA_measurementId: mg.FGA_measurementId,
|
||||
FGA_apiKey: config.FGA_apiKey,
|
||||
FGA_authDomain: config.FGA_authDomain,
|
||||
FGA_databaseURL: config.FGA_databaseURL,
|
||||
FGA_projectId: config.FGA_projectId,
|
||||
FGA_storageBucket: config.FGA_storageBucket,
|
||||
FGA_messagingSenderId: config.FGA_messagingSenderId,
|
||||
FGA_appId: config.FGA_appId,
|
||||
FGA_measurementId: config.FGA_measurementId,
|
||||
}
|
||||
parsedTemplate, _ := template.ParseFiles("template/fb-ga.min.js")
|
||||
err := parsedTemplate.Execute(w, fgaconfig)
|
||||
|
||||
Reference in New Issue
Block a user