prepare 로그 자세히
This commit is contained in:
@ -13,6 +13,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -207,7 +208,6 @@ func New(ctx context.Context) (*Maingate, error) {
|
||||
|
||||
err := mg.prepare(ctx)
|
||||
if err != nil {
|
||||
logger.Error("mg.prepare() failed :", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -287,95 +287,98 @@ 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 err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
if err := mg.discoverOpenIdConfiguration("google", "https://accounts.google.com/.well-known/openid-configuration"); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
// redis에서 env를 가져온 후에
|
||||
mg.mongoClient, err = gocommon.NewMongoClient(context, mg.Mongo, "maingate")
|
||||
if err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionAuth, map[string]bson.D{
|
||||
"skonly": {{Key: "sk", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionLink, map[string]bson.D{
|
||||
"platformuid": {{Key: "platform", Value: 1}, {Key: "uid", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionLink, map[string]bson.D{
|
||||
"emailplatform": {{Key: "email", Value: 1}, {Key: "platform", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeIndices(CollectionAccount, map[string]bson.D{
|
||||
"accid": {{Key: "accid", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionFile, map[string]bson.D{
|
||||
"keyonly": {{Key: "key", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
// Delete대신 _ts로 expire시킴. pipeline에 삭제 알려주기 위함
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionWhitelist, 10); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionAuth, int32(mg.SessionTTL+300)); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if *devflag {
|
||||
if err = mg.mongoClient.DropIndex(CollectionBlock, "codeaccid"); err != nil {
|
||||
return err
|
||||
}
|
||||
// 에러 체크하지 말것
|
||||
mg.mongoClient.DropIndex(CollectionBlock, "codeaccid")
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionBlock, int32(3)); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionPlatformLoginToken, map[string]bson.D{
|
||||
"platformauthtoken": {{Key: "platform", Value: 1}, {Key: "key", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionPlatformLoginToken, int32(mg.SessionTTL+300)); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionUserToken, map[string]bson.D{
|
||||
"platformusertoken": {{Key: "platform", Value: 1}, {Key: "userid", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionGamepotUserInfo, map[string]bson.D{
|
||||
"gamepotuserid": {{Key: "gamepotuserid", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionFirebaseUserInfo, map[string]bson.D{
|
||||
"firebaseuserid": {{Key: "firebaseuserid", Value: 1}},
|
||||
}); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
mg.auths = makeAuthCollection(mg.mongoClient, time.Duration(mg.SessionTTL*int64(time.Second)))
|
||||
@ -387,7 +390,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 err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
|
||||
for _, pre := range preall {
|
||||
@ -402,23 +405,23 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
||||
"_id": pre.Id,
|
||||
}, &fulldoc)
|
||||
if err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
err = fulldoc.Save()
|
||||
if err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
var whites []*whitelistmember
|
||||
if err := mg.mongoClient.AllAs(CollectionWhitelist, &whites, options.Find().SetReturnKey(false)); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
mg.wl.init(whites)
|
||||
|
||||
var blocks []*blockinfo
|
||||
if err := mg.mongoClient.AllAs(CollectionBlock, &blocks); err != nil {
|
||||
return err
|
||||
return makeErrorWithStack(err)
|
||||
}
|
||||
mg.bl.init(blocks)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user