코드 정리
This commit is contained in:
@ -12,7 +12,6 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -244,57 +243,53 @@ func (mg *Maingate) discoverOpenIdConfiguration(name string, url string) error {
|
||||
|
||||
}
|
||||
|
||||
func makeErrorWithStack(err error) error {
|
||||
return fmt.Errorf("%s\n%s", err.Error(), string(debug.Stack()))
|
||||
}
|
||||
|
||||
func (mg *Maingate) prepare(context context.Context) (err error) {
|
||||
if err := mg.discoverOpenIdConfiguration(AuthPlatformMicrosoft, "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration"); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
if err := mg.discoverOpenIdConfiguration("google", "https://accounts.google.com/.well-known/openid-configuration"); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
// redis에서 env를 가져온 후에
|
||||
mg.mongoClient, err = gocommon.NewMongoClient(context, mg.Mongo)
|
||||
if err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionCouponUse, map[string]bson.D{
|
||||
"idrounds": {{Key: "_id", Value: 1}, {Key: "rounds", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionLink, map[string]bson.D{
|
||||
"platformuid": {{Key: "platform", Value: 1}, {Key: "uid", Value: 1}},
|
||||
}); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionLink, map[string]bson.D{
|
||||
"emailplatform": {{Key: "email", Value: 1}, {Key: "platform", Value: 1}},
|
||||
}); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeIndices(CollectionAccount, map[string]bson.D{
|
||||
"accid": {{Key: "accid", Value: 1}},
|
||||
}); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionFile, map[string]bson.D{
|
||||
"keyonly": {{Key: "key", Value: 1}},
|
||||
}); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
// Delete대신 _ts로 expire시킴. pipeline에 삭제 알려주기 위함
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionWhitelist, 10); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if *devflag {
|
||||
@ -303,40 +298,40 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionBlock, int32(3)); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionPlatformLoginToken, map[string]bson.D{
|
||||
"platformauthtoken": {{Key: "platform", Value: 1}, {Key: "key", Value: 1}},
|
||||
}); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionPlatformLoginToken, int32(mg.SessionTTL+300)); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionUserToken, map[string]bson.D{
|
||||
"platformusertoken": {{Key: "platform", Value: 1}, {Key: "userid", Value: 1}},
|
||||
}); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionGamepotUserInfo, map[string]bson.D{
|
||||
"gamepotuserid": {{Key: "gamepotuserid", Value: 1}},
|
||||
}); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionFirebaseUserInfo, map[string]bson.D{
|
||||
"firebaseuserid": {{Key: "firebaseuserid", Value: 1}},
|
||||
}); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
mg.sessionProvider, err = session.NewProviderWithConfig(context, mg.SessionConfig)
|
||||
if err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
var preall []struct {
|
||||
@ -346,7 +341,7 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
||||
if err = mg.mongoClient.FindAllAs(CollectionFile, nil, &preall, options.Find().SetProjection(bson.M{
|
||||
"link": 1,
|
||||
})); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
for _, pre := range preall {
|
||||
@ -361,23 +356,23 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
||||
"_id": pre.Id,
|
||||
}, &fulldoc)
|
||||
if err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
err = fulldoc.Save()
|
||||
if err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
var whites []*whitelistmember
|
||||
if err := mg.mongoClient.AllAs(CollectionWhitelist, &whites, options.Find().SetReturnKey(false)); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
mg.wl.init(whites)
|
||||
|
||||
var blocks []*blockinfo
|
||||
if err := mg.mongoClient.AllAs(CollectionBlock, &blocks); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
mg.bl.init(blocks)
|
||||
|
||||
@ -390,7 +385,7 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
||||
func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMux, prefix string) error {
|
||||
var allServices []*serviceDescription
|
||||
if err := mg.mongoClient.AllAs(CollectionService, &allServices, options.Find().SetReturnKey(false)); err != nil {
|
||||
return err
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if len(allServices) > 0 {
|
||||
@ -409,7 +404,7 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
host, _ := os.Hostname()
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return err
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
ipaddr := "127.0.0.1"
|
||||
for _, addr := range addrs {
|
||||
@ -441,7 +436,7 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
}, options.Update().SetUpsert(true))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -454,7 +449,7 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
configraw, _ := json.Marshal(mg.maingateConfig)
|
||||
var convertedConfig map[string]any
|
||||
if err := json.Unmarshal(configraw, &convertedConfig); err != nil {
|
||||
return err
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "config"), func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -487,7 +482,7 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
|
||||
if err := os.MkdirAll("static", os.ModePerm); err != nil {
|
||||
// 일반 엔드유저한테 오픈할 static 페이지
|
||||
return err
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
cfsx := http.FileServer(http.Dir("console"))
|
||||
@ -548,7 +543,7 @@ func (mg *Maingate) GetUserBrowserInfo(r *http.Request) (string, error) {
|
||||
|
||||
cookie, err := r.Cookie("ActionSquareSessionExtraInfo")
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
//requestinfo := fmt.Sprintf("%s_%s", cookie.Value, host) //-- RemoteAddr체크는 로드밸런서 IP 찍히는 문제 때문에 제외한다.
|
||||
@ -570,7 +565,7 @@ func (mg *Maingate) setUserToken(info usertokeninfo) error {
|
||||
"accesstoken_expire_time": info.accesstoken_expire_time,
|
||||
},
|
||||
}, options.Update().SetUpsert(true))
|
||||
return err
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
func (mg *Maingate) getUserTokenWithCheck(platform string, userid string, brinfo string) (usertokeninfo, error) {
|
||||
|
||||
Reference in New Issue
Block a user