diff --git a/core/maingate.go b/core/maingate.go index 04ed098..295d6f5 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -18,7 +18,7 @@ import ( "time" "unsafe" - common "repositories.action2quare.com/ayo/gocommon" + "repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon/flagx" "repositories.action2quare.com/ayo/gocommon/logger" @@ -37,17 +37,17 @@ var devflag = flagx.Bool("dev", false, "") var noauth = flagx.Bool("noauth", false, "") var ( - CollectionLink = common.CollectionName("link") - CollectionAuth = common.CollectionName("auth") - CollectionWhitelist = common.CollectionName("whitelist") - CollectionService = common.CollectionName("service") - CollectionAccount = common.CollectionName("account") - CollectionFile = common.CollectionName("file") - CollectionBlock = common.CollectionName("block") - CollectionPlatformLoginToken = common.CollectionName("platform_login_token") //-- 각 플랫폼에 로그인 및 권한 받아오는 과정에 사용하는 Key - CollectionUserToken = common.CollectionName("usertoken") - CollectionGamepotUserInfo = common.CollectionName("gamepot_userinfo") //-- 클라로부터 수집된 gamepot 정보 - server to server로 유효성이 검증되진 않았지만 수집은 한다. - CollectionFirebaseUserInfo = common.CollectionName("firebase_userinfo") //-- Firebase UserInfo + CollectionLink = gocommon.CollectionName("link") + CollectionAuth = gocommon.CollectionName("auth") + CollectionWhitelist = gocommon.CollectionName("whitelist") + CollectionService = gocommon.CollectionName("service") + CollectionAccount = gocommon.CollectionName("account") + CollectionFile = gocommon.CollectionName("file") + CollectionBlock = gocommon.CollectionName("block") + CollectionPlatformLoginToken = gocommon.CollectionName("platform_login_token") //-- 각 플랫폼에 로그인 및 권한 받아오는 과정에 사용하는 Key + CollectionUserToken = gocommon.CollectionName("usertoken") + CollectionGamepotUserInfo = gocommon.CollectionName("gamepot_userinfo") //-- 클라로부터 수집된 gamepot 정보 - server to server로 유효성이 검증되진 않았지만 수집은 한다. + CollectionFirebaseUserInfo = gocommon.CollectionName("firebase_userinfo") //-- Firebase UserInfo ) const ( @@ -72,10 +72,10 @@ func SessionTTL() time.Duration { } type mongoAuthCell struct { - src *common.Authinfo + src *gocommon.Authinfo } -func (ac *mongoAuthCell) ToAuthinfo() *common.Authinfo { +func (ac *mongoAuthCell) ToAuthinfo() *gocommon.Authinfo { if ac.src == nil { logger.Error("mongoAuthCell ToAuthinfo failed. ac.src is nil") } @@ -87,15 +87,15 @@ func (ac *mongoAuthCell) ToBytes() []byte { return bt } -func makeAuthCollection(mongoClient common.MongoClient, sessionTTL time.Duration) *common.AuthCollection { - authcoll := common.MakeAuthCollection(sessionTTL) +func makeAuthCollection(mongoClient gocommon.MongoClient, sessionTTL time.Duration) *gocommon.AuthCollection { + authcoll := gocommon.MakeAuthCollection(sessionTTL) authcoll.SessionRemoved = func(sk string) { skid, _ := primitive.ObjectIDFromHex(sk) mongoClient.Delete(CollectionAuth, bson.M{ "sk": skid, }) } - authcoll.QuerySession = func(sk string, token string) common.AuthinfoCell { + authcoll.QuerySession = func(sk string, token string) gocommon.AuthinfoCell { skid, _ := primitive.ObjectIDFromHex(sk) var outcell mongoAuthCell err := mongoClient.FindOneAs(CollectionAuth, bson.M{ @@ -152,16 +152,16 @@ func (ga *globalAdmins) parse() { parsed[admin] = true } ga.emails = parsed - ga.modtime = common.ConfigModTime() + ga.modtime = gocommon.ConfigModTime() } // Maingate : type Maingate struct { maingateConfig - mongoClient common.MongoClient + mongoClient gocommon.MongoClient - auths *common.AuthCollection + auths *gocommon.AuthCollection //services servicelist serviceptr unsafe.Pointer admins unsafe.Pointer @@ -178,12 +178,12 @@ type Maingate struct { // New : func New(ctx context.Context) (*Maingate, error) { var config maingateConfig - if err := common.LoadConfig(&config); err != nil { + if err := gocommon.LoadConfig(&config); err != nil { return nil, err } var admins globalAdmins - if err := common.LoadConfig(&admins); err == nil { + if err := gocommon.LoadConfig(&admins); err == nil { admins.parse() } @@ -291,7 +291,7 @@ func (mg *Maingate) prepare(context context.Context) (err error) { } // redis에서 env를 가져온 후에 - mg.mongoClient, err = common.NewMongoClient(context, mg.Mongo, "maingate") + mg.mongoClient, err = gocommon.NewMongoClient(context, mg.Mongo, "maingate") if err != nil { return err } @@ -397,7 +397,7 @@ func (mg *Maingate) prepare(context context.Context) (err error) { } logger.Println("saving files :", pre.Link) - var fulldoc fileDocumentDesc + var fulldoc FileDocumentDesc err = mg.mongoClient.FindOneAs(CollectionFile, bson.M{ "_id": pre.Id, }, &fulldoc) @@ -490,9 +490,9 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu } logger.Println("Service is registered :", mg.service().ServiceCode) - serveMux.Handle(common.MakeHttpHandlerPattern(prefix, mg.service().ServiceCode, "/"), mg.service()) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "api/"), mg.api) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "query/"), mg.query) + serveMux.Handle(gocommon.MakeHttpHandlerPattern(prefix, mg.service().ServiceCode, "/"), mg.service()) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "api/"), mg.api) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "query/"), mg.query) configraw, _ := json.Marshal(mg.maingateConfig) var convertedConfig map[string]any @@ -500,7 +500,7 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu return err } - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "config"), func(w http.ResponseWriter, r *http.Request) { + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "config"), func(w http.ResponseWriter, r *http.Request) { defer func() { s := recover() if s != nil { @@ -534,29 +534,29 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu } fsx := http.FileServer(http.Dir("./console")) - serveMux.Handle(common.MakeHttpHandlerPattern(prefix, "console/"), http.StripPrefix("/console/", fsx)) + serveMux.Handle(gocommon.MakeHttpHandlerPattern(prefix, "console/"), http.StripPrefix("/console/", fsx)) ssx := http.FileServer(http.Dir("./static")) - serveMux.Handle(common.MakeHttpHandlerPattern(prefix, "static/"), http.StripPrefix("/static/", ssx)) + serveMux.Handle(gocommon.MakeHttpHandlerPattern(prefix, "static/"), http.StripPrefix("/static/", ssx)) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformGoogle), mg.platform_google_get_login_url) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformGoogle), mg.platform_google_authorize) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize_result", AuthPlatformGoogle), mg.platform_google_authorize_result) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformGoogle), mg.platform_google_get_login_url) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformGoogle), mg.platform_google_authorize) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize_result", AuthPlatformGoogle), mg.platform_google_authorize_result) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformMicrosoft), mg.platform_microsoft_get_login_url) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformMicrosoft), mg.platform_microsoft_authorize) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize_result", AuthPlatformMicrosoft), mg.platform_microsoft_authorize_result) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformMicrosoft), mg.platform_microsoft_get_login_url) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformMicrosoft), mg.platform_microsoft_authorize) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize_result", AuthPlatformMicrosoft), mg.platform_microsoft_authorize_result) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformTwitter), mg.platform_twitter_get_login_url) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformTwitter), mg.platform_twitter_authorize) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize_result", AuthPlatformTwitter), mg.platform_twitter_authorize_result) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformTwitter), mg.platform_twitter_get_login_url) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformTwitter), mg.platform_twitter_authorize) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize_result", AuthPlatformTwitter), mg.platform_twitter_authorize_result) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformApple), mg.platform_apple_get_login_url) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformApple), mg.platform_apple_authorize) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize_result", AuthPlatformApple), mg.platform_apple_authorize_result) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformApple), mg.platform_apple_get_login_url) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformApple), mg.platform_apple_authorize) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize_result", AuthPlatformApple), mg.platform_apple_authorize_result) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformFirebaseAuth), mg.platform_firebaseauth_get_login_url) - serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize_sdk", AuthPlatformFirebaseAuth), mg.platform_firebaseauth_authorize_sdk) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformFirebaseAuth), mg.platform_firebaseauth_get_login_url) + serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "authorize_sdk", AuthPlatformFirebaseAuth), mg.platform_firebaseauth_authorize_sdk) go mg.watchServiceCollection(ctx, serveMux, prefix) go mg.watchFileCollection(ctx, serveMux, prefix) diff --git a/core/watch.go b/core/watch.go index 06ecacf..ef22356 100644 --- a/core/watch.go +++ b/core/watch.go @@ -42,7 +42,7 @@ type filePipelineDocument struct { DocumentKey struct { Id primitive.ObjectID `bson:"_id"` } `bson:"documentKey"` - File *fileDocumentDesc `bson:"fullDocument"` + File *FileDocumentDesc `bson:"fullDocument"` } type whilelistPipelineDocument struct {