flag를 flagx로 대체
This commit is contained in:
@ -18,8 +18,8 @@ import (
|
||||
"unsafe"
|
||||
|
||||
common "repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/maingate/flag"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -32,6 +32,9 @@ import (
|
||||
"google.golang.org/api/option"
|
||||
)
|
||||
|
||||
var devflag = flagx.Bool("dev", false, "")
|
||||
var noauth = flagx.Bool("noauth", false, "")
|
||||
|
||||
var (
|
||||
CollectionLink = common.CollectionName("link")
|
||||
CollectionAuth = common.CollectionName("auth")
|
||||
@ -60,7 +63,7 @@ const (
|
||||
)
|
||||
|
||||
func SessionTTL() time.Duration {
|
||||
if *flag.Devflag {
|
||||
if *devflag {
|
||||
return sessionTTLDev
|
||||
}
|
||||
|
||||
@ -71,22 +74,6 @@ type mongoAuthCell struct {
|
||||
src *common.Authinfo
|
||||
}
|
||||
|
||||
func init() {
|
||||
if *flag.Devflag {
|
||||
hostname, _ := os.Hostname()
|
||||
CollectionLink = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionLink)))
|
||||
CollectionAuth = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionAuth)))
|
||||
CollectionWhitelist = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionWhitelist)))
|
||||
CollectionService = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionService)))
|
||||
CollectionAccount = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionAccount)))
|
||||
CollectionBlock = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionBlock)))
|
||||
CollectionPlatformLoginToken = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionPlatformLoginToken)))
|
||||
CollectionUserToken = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionUserToken)))
|
||||
CollectionGamepotUserInfo = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionGamepotUserInfo)))
|
||||
CollectionFirebaseUserInfo = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionFirebaseUserInfo)))
|
||||
}
|
||||
}
|
||||
|
||||
func (ac *mongoAuthCell) ToAuthinfo() *common.Authinfo {
|
||||
if ac.src == nil {
|
||||
logger.Error("mongoAuthCell ToAuthinfo failed. ac.src is nil")
|
||||
@ -187,8 +174,24 @@ type Maingate struct {
|
||||
firebaseAppContext context.Context
|
||||
}
|
||||
|
||||
var collectionNameMod = int32(0)
|
||||
|
||||
// New :
|
||||
func New(ctx context.Context) (*Maingate, error) {
|
||||
if *devflag && atomic.AddInt32(&collectionNameMod, 1) == 1 {
|
||||
hostname, _ := os.Hostname()
|
||||
CollectionLink = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionLink)))
|
||||
CollectionAuth = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionAuth)))
|
||||
CollectionWhitelist = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionWhitelist)))
|
||||
CollectionService = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionService)))
|
||||
CollectionAccount = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionAccount)))
|
||||
CollectionBlock = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionBlock)))
|
||||
CollectionPlatformLoginToken = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionPlatformLoginToken)))
|
||||
CollectionUserToken = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionUserToken)))
|
||||
CollectionGamepotUserInfo = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionGamepotUserInfo)))
|
||||
CollectionFirebaseUserInfo = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionFirebaseUserInfo)))
|
||||
}
|
||||
|
||||
var config maingateConfig
|
||||
if err := common.LoadConfig(&config); err != nil {
|
||||
return nil, err
|
||||
@ -218,7 +221,7 @@ func New(ctx context.Context) (*Maingate, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !*flag.Noauth {
|
||||
if !*noauth {
|
||||
opt := option.WithCredentialsFile(mg.FirebaseAdminSDKCredentialFile)
|
||||
firebaseApp, err := firebase.NewApp(context.Background(), nil, opt)
|
||||
if err != nil {
|
||||
@ -446,7 +449,7 @@ func whitelistKey(email string) string {
|
||||
func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMux, prefix string) error {
|
||||
var allServices []*serviceDescription
|
||||
|
||||
if *flag.Noauth {
|
||||
if *noauth {
|
||||
host, _ := os.Hostname()
|
||||
empty := serviceDescription{
|
||||
ServiceDescriptionSummary: ServiceDescriptionSummary{
|
||||
@ -576,7 +579,7 @@ func (mg *Maingate) query(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !*flag.Noauth {
|
||||
if !*noauth {
|
||||
apitoken := r.Header.Get("MG-X-API-TOKEN")
|
||||
if len(apitoken) == 0 {
|
||||
logger.Println("MG-X-API-TOKEN is missing")
|
||||
|
||||
Reference in New Issue
Block a user