Compare commits
52 Commits
f9a146321c
...
e38e8a91e5
| Author | SHA1 | Date | |
|---|---|---|---|
| e38e8a91e5 | |||
| 2076fb1b81 | |||
| f734ef099b | |||
| c0e1e229cd | |||
| b5114b5224 | |||
| a3b4ac47b8 | |||
| 45e7169c3a | |||
| 3444c17026 | |||
| 98340db8df | |||
| e7b3f59dd0 | |||
| bc82cb123c | |||
| 2165a4400b | |||
| 6ca3905fed | |||
| d5708a964f | |||
| bb9b3a9735 | |||
| da68071e97 | |||
| 2e60fac840 | |||
| dab5a35870 | |||
| a35512e327 | |||
| 8a8bd50e28 | |||
| db90ce931f | |||
| 7639c749dc | |||
| 63461676f4 | |||
| eebd3fb746 | |||
| ba4b4eea94 | |||
| e583904693 | |||
| a2def0af79 | |||
| 6ccf76d1b2 | |||
| bc58249483 | |||
| 95a7972835 | |||
| e37aaff9cb | |||
| 77cffbbe9a | |||
| d623196c10 | |||
| 06e40853ad | |||
| d873965d37 | |||
| 275b9b12e3 | |||
| 81689f7512 | |||
| e3ad826826 | |||
| 9e98b581e4 | |||
| 41641b88e9 | |||
| a4d297a944 | |||
| 418713b0c7 | |||
| 087743453c | |||
| caed2b5925 | |||
| e18dc74dc2 | |||
| 9afa1d87e7 | |||
| 3cf9466cdb | |||
| 6c73e9990e | |||
| e8aa6189be | |||
| 47284a79c2 | |||
| 0121310941 | |||
| 76a4818a66 |
37
backup/firebase-jssdk/fb-ga.js
Normal file
37
backup/firebase-jssdk/fb-ga.js
Normal file
@ -0,0 +1,37 @@
|
||||
// Import the functions you need from the SDKs you need
|
||||
import { initializeApp } from './firebase-app.js';
|
||||
import { getAnalytics, logEvent } from './firebase-analytics.js';
|
||||
|
||||
// TODO: Add SDKs for Firebase products that you want to use
|
||||
// https://firebase.google.com/docs/web/setup#available-libraries
|
||||
|
||||
// Your web app's Firebase configuration
|
||||
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
|
||||
const firebaseConfig = {
|
||||
apiKey: "{{.FBA_apiKey}}",
|
||||
authDomain: "{{.FBA_authDomain}}",
|
||||
databaseURL: "{{.FBA_databaseURL}}",
|
||||
projectId: "{{.FBA_projectId}}",
|
||||
storageBucket: "{{.FBA_storageBucket}}",
|
||||
messagingSenderId: "{{.FBA_messagingSenderId}}",
|
||||
appId: "{{.FBA_appId}}",
|
||||
measurementId: "{{.FBA_measurementId}}"
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Initialize Firebase
|
||||
const app = initializeApp(firebaseConfig);
|
||||
const analytics = getAnalytics(app);
|
||||
|
||||
// LogEvent('DESKTOP_TEST8');
|
||||
|
||||
export function LogEvent(args){
|
||||
|
||||
if ( arguments.length == 1) {
|
||||
logEvent(analytics, arguments[0]);
|
||||
} else {
|
||||
logEvent(analytics, arguments[0], arguments[1]);
|
||||
}
|
||||
|
||||
}
|
||||
1
backup/firebase-jssdk/fb-ga.min.js
vendored
Normal file
1
backup/firebase-jssdk/fb-ga.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2376
backup/firebase-jssdk/fb-ga.rollup.js
Normal file
2376
backup/firebase-jssdk/fb-ga.rollup.js
Normal file
File diff suppressed because one or more lines are too long
3
backup/firebase-jssdk/firebase-analytics.js
Normal file
3
backup/firebase-jssdk/firebase-analytics.js
Normal file
File diff suppressed because one or more lines are too long
2522
backup/firebase-jssdk/firebase-app.js
Normal file
2522
backup/firebase-jssdk/firebase-app.js
Normal file
File diff suppressed because it is too large
Load Diff
537
backup/firebase-jssdk/js.js
Normal file
537
backup/firebase-jssdk/js.js
Normal file
File diff suppressed because one or more lines are too long
3
backup/firebase-jssdk/original/firebase-analytics.js
Normal file
3
backup/firebase-jssdk/original/firebase-analytics.js
Normal file
File diff suppressed because one or more lines are too long
2522
backup/firebase-jssdk/original/firebase-app.js
Normal file
2522
backup/firebase-jssdk/original/firebase-app.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,8 @@
|
||||
{
|
||||
"maingate_mongodb_url": "mongodb://...",
|
||||
"session_storage": "",
|
||||
"session_ttl" : 3600,
|
||||
|
||||
"autologin_ttl": 604800,
|
||||
"maximum_num_link_account": 10,
|
||||
"redirect_base_url": "",
|
||||
@ -25,6 +28,15 @@
|
||||
|
||||
"firebase_admin_sdk_credentialfile": "",
|
||||
|
||||
"firebase_google_analytics_jssdk_apikey": "",
|
||||
"firebase_google_analytics_jssdk_authdomain": "",
|
||||
"firebase_google_analytics_jssdk_databaseurl": "",
|
||||
"firebase_google_analytics_jssdk_projectid": "",
|
||||
"firebase_google_analytics_jssdk_storagebucket": "",
|
||||
"firebase_google_analytics_jssdk_messagingsenderid": "",
|
||||
"firebase_google_analytics_jssdk_apiid": "",
|
||||
"firebase_google_analytics_jssdk_measurementid": "",
|
||||
|
||||
"maingate_global_admins" : [
|
||||
"mountain@action2quare.com"
|
||||
]
|
||||
|
||||
70
core/api.go
70
core/api.go
@ -160,38 +160,49 @@ func (caller apiCaller) uploadAPI(w http.ResponseWriter, r *http.Request) error
|
||||
|
||||
func (caller apiCaller) blockAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
mg := caller.mg
|
||||
logger.Println("blockAPI :", r.Method)
|
||||
if r.Method == "GET" {
|
||||
enc := json.NewEncoder(w)
|
||||
enc.Encode(mg.bl.all())
|
||||
target, ok := gocommon.ReadObjectIDFormValue(r.Form, "accid")
|
||||
logger.Println("Get :", target, ok)
|
||||
if !ok {
|
||||
// 페이지네이션 해야할 듯
|
||||
json.NewEncoder(w).Encode(mg.bl.all())
|
||||
} else if !target.IsZero() {
|
||||
if blocked, ok := mg.bl.get(target); ok && blocked != nil {
|
||||
json.NewEncoder(w).Encode(blocked)
|
||||
}
|
||||
}
|
||||
} else if r.Method == "PUT" {
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
|
||||
var bipl blockinfoWithStringId
|
||||
if err := json.Unmarshal(body, &bipl); err != nil {
|
||||
var targets struct {
|
||||
Start primitive.DateTime
|
||||
End primitive.DateTime
|
||||
Accounts map[primitive.ObjectID]primitive.M // accid->meta
|
||||
}
|
||||
if err := gocommon.MakeDecoder(r).Decode(&targets); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
accid, err := primitive.ObjectIDFromHex(bipl.StrId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for accid, meta := range targets.Accounts {
|
||||
bi := blockinfo{
|
||||
Start: targets.Start,
|
||||
End: targets.End,
|
||||
Meta: meta,
|
||||
}
|
||||
|
||||
bi := blockinfo{
|
||||
Start: primitive.NewDateTimeFromTime(time.Unix(bipl.StartUnix, 0)),
|
||||
End: primitive.NewDateTimeFromTime(time.Unix(bipl.EndUnix, 0)),
|
||||
Reason: bipl.Reason,
|
||||
}
|
||||
_, _, err := mg.mongoClient.Update(CollectionBlock, bson.M{
|
||||
"_id": accid,
|
||||
}, bson.M{
|
||||
"$set": &bi,
|
||||
}, options.Update().SetUpsert(true))
|
||||
if err != nil {
|
||||
logger.Println("account is not blocked. err :", err)
|
||||
} else {
|
||||
logger.Println("account is blocked :", meta)
|
||||
|
||||
logger.Println("bi :", accid, bi)
|
||||
|
||||
_, _, err = mg.mongoClient.Update(CollectionBlock, bson.M{
|
||||
"_id": accid,
|
||||
}, bson.M{
|
||||
"$set": &bi,
|
||||
}, options.Update().SetUpsert(true))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
bi.Accid = accid
|
||||
caller.mg.bl.add(&bi)
|
||||
mg.sessionProvider.Invalidate(accid)
|
||||
}
|
||||
}
|
||||
} else if r.Method == "DELETE" {
|
||||
id := r.URL.Query().Get("id")
|
||||
@ -216,7 +227,7 @@ func (caller apiCaller) blockAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
return err
|
||||
}
|
||||
|
||||
mg.mongoClient.Delete(CollectionAuth, bson.M{"_id": idobj})
|
||||
caller.mg.bl.remove(idobj)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -233,9 +244,9 @@ func (caller apiCaller) whitelistAPI(w http.ResponseWriter, r *http.Request) err
|
||||
return err
|
||||
}
|
||||
member.ExpiredAt = 0
|
||||
|
||||
member.Id = primitive.NewObjectID()
|
||||
_, _, err := mg.mongoClient.Update(CollectionWhitelist, bson.M{
|
||||
"_id": primitive.NewObjectID(),
|
||||
"_id": member.Id,
|
||||
}, bson.M{
|
||||
"$set": &member,
|
||||
}, options.Update().SetUpsert(true))
|
||||
@ -271,13 +282,16 @@ func (caller apiCaller) whitelistAPI(w http.ResponseWriter, r *http.Request) err
|
||||
func (caller apiCaller) serviceAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
mg := caller.mg
|
||||
if r.Method == "GET" {
|
||||
logger.Println("serviceAPI :", r.URL.Path)
|
||||
if mg.service().Id.IsZero() {
|
||||
logger.Println(" id is zero")
|
||||
newService := serviceDescription{
|
||||
ServiceDescriptionSummary: ServiceDescriptionSummary{
|
||||
Id: primitive.NewObjectID(),
|
||||
},
|
||||
}
|
||||
if err := newService.prepare(caller.mg); err != nil {
|
||||
logger.Println(" prepare failed :", err)
|
||||
return err
|
||||
}
|
||||
atomic.StorePointer(&mg.serviceptr, unsafe.Pointer(&newService))
|
||||
|
||||
@ -44,17 +44,17 @@ func makeCouponKey(roundnum uint32, uid []byte) string {
|
||||
return fmt.Sprintf("%s-%s-%s-%s", hex.EncodeToString(final[0:2]), hex.EncodeToString(final[2:4]), hex.EncodeToString(final[4:6]), hex.EncodeToString(final[6:8]))
|
||||
}
|
||||
|
||||
var r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
func makeCouponCodes(name string, count int) (string, map[string]string) {
|
||||
checkunique := make(map[string]bool)
|
||||
keys := make(map[string]string)
|
||||
uid := make([]byte, 4)
|
||||
|
||||
roundHash, roundnum := coupon.MakeCouponRoundHash(name)
|
||||
seed := time.Now().UnixNano()
|
||||
|
||||
for len(keys) < count {
|
||||
rand.Seed(seed)
|
||||
rand.Read(uid)
|
||||
r.Read(uid)
|
||||
|
||||
code := makeCouponKey(roundnum, uid)
|
||||
|
||||
@ -62,7 +62,6 @@ func makeCouponCodes(name string, count int) (string, map[string]string) {
|
||||
checkunique[code] = true
|
||||
keys[hex.EncodeToString(uid)] = code
|
||||
}
|
||||
seed = int64(binary.BigEndian.Uint32(uid))
|
||||
}
|
||||
return roundHash, keys
|
||||
}
|
||||
@ -198,7 +197,12 @@ func downloadCoupons(mongoClient gocommon.MongoClient, w http.ResponseWriter, r
|
||||
roundnum := binary.BigEndian.Uint32(roundObj[:])
|
||||
var coupons []string
|
||||
for _, uid := range coupon.Remains {
|
||||
coupons = append(coupons, makeCouponKey(roundnum, []byte(uid)))
|
||||
decUid, err := hex.DecodeString(uid)
|
||||
if err != nil {
|
||||
logger.Println("downloadCoupons Fail", err)
|
||||
continue
|
||||
}
|
||||
coupons = append(coupons, makeCouponKey(roundnum, decUid))
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(w)
|
||||
@ -275,8 +279,8 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
|
||||
round, _ = coupon.MakeCouponRoundHash(code)
|
||||
}
|
||||
|
||||
// 1. 내가 이 라운드의 쿠폰을 쓴 적이 있나
|
||||
already, err := mongoClient.Exists(CollectionCouponUse, bson.M{
|
||||
// 쿠폰 사용 유무 검사
|
||||
alreadyused, err := mongoClient.Exists(CollectionCouponUse, bson.M{
|
||||
"_id": acc,
|
||||
"rounds": round,
|
||||
})
|
||||
@ -286,7 +290,7 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
|
||||
return
|
||||
}
|
||||
|
||||
if already {
|
||||
if alreadyused {
|
||||
// 이미 이 라운드의 쿠폰을 사용한 적이 있다.
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
return
|
||||
@ -312,7 +316,8 @@ func useCoupon(mongoClient gocommon.MongoClient, w http.ResponseWriter, r *http.
|
||||
} else {
|
||||
// 2. 쿠폰을 하나 꺼냄
|
||||
matched, _, err := mongoClient.Update(CollectionCoupon, bson.M{
|
||||
"_id": roundObj,
|
||||
"_id": roundObj,
|
||||
"remains": key,
|
||||
}, bson.M{
|
||||
"$pull": bson.M{"remains": key},
|
||||
})
|
||||
|
||||
@ -1,39 +1,9 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
)
|
||||
|
||||
func TestMakeLocalUniqueId(t *testing.T) {
|
||||
ts := int64(1690815600)
|
||||
start := primitive.NewDateTimeFromTime(time.Unix(ts, 0))
|
||||
ts = int64(1693493999)
|
||||
end := primitive.NewDateTimeFromTime(time.Unix(ts, 0))
|
||||
|
||||
fmt.Println(start.Time().Format(time.RFC3339))
|
||||
fmt.Println(end.Time().Format(time.RFC3339))
|
||||
|
||||
mongoClient, err := gocommon.NewMongoClient(context.Background(), "mongodb://121.134.91.160:27018/?replicaSet=rs0&retrywrites=true", "mountain-maingate")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
bi := blockinfo{
|
||||
Start: start,
|
||||
End: end,
|
||||
Reason: "test",
|
||||
}
|
||||
mongoClient.Update(CollectionBlock, bson.M{
|
||||
"_id": primitive.NewObjectID(),
|
||||
}, bson.M{
|
||||
"$set": &bi,
|
||||
}, options.Update().SetUpsert(true))
|
||||
}
|
||||
|
||||
263
core/maingate.go
263
core/maingate.go
@ -9,19 +9,19 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"text/template"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/session"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -39,7 +39,6 @@ var noauth = flagx.Bool("noauth", false, "")
|
||||
|
||||
var (
|
||||
CollectionLink = gocommon.CollectionName("link")
|
||||
CollectionAuth = gocommon.CollectionName("auth")
|
||||
CollectionWhitelist = gocommon.CollectionName("whitelist")
|
||||
CollectionService = gocommon.CollectionName("service")
|
||||
CollectionAccount = gocommon.CollectionName("account")
|
||||
@ -73,55 +72,9 @@ func SessionTTL() time.Duration {
|
||||
return sessionTTL
|
||||
}
|
||||
|
||||
type mongoAuthCell struct {
|
||||
src *gocommon.Authinfo
|
||||
}
|
||||
|
||||
func (ac *mongoAuthCell) ToAuthinfo() *gocommon.Authinfo {
|
||||
if ac.src == nil {
|
||||
logger.Error("mongoAuthCell ToAuthinfo failed. ac.src is nil")
|
||||
}
|
||||
return ac.src
|
||||
}
|
||||
|
||||
func (ac *mongoAuthCell) ToBytes() []byte {
|
||||
bt, _ := json.Marshal(ac.src)
|
||||
return bt
|
||||
}
|
||||
|
||||
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) gocommon.AuthinfoCell {
|
||||
skid, _ := primitive.ObjectIDFromHex(sk)
|
||||
var outcell mongoAuthCell
|
||||
err := mongoClient.FindOneAs(CollectionAuth, bson.M{
|
||||
"sk": skid,
|
||||
}, &outcell.src, options.FindOne().SetHint("skonly"))
|
||||
|
||||
if err != nil {
|
||||
logger.Error("QuerySession failed :", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if outcell.src == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &outcell
|
||||
}
|
||||
|
||||
return authcoll
|
||||
}
|
||||
|
||||
type maingateConfig struct {
|
||||
session.SessionConfig `json:",inline"`
|
||||
Mongo string `json:"maingate_mongodb_url"`
|
||||
SessionTTL int64 `json:"maingate_session_ttl"`
|
||||
Autologin_ttl int64 `json:"autologin_ttl"`
|
||||
MaximumNumLinkAccount int64 `json:"maximum_num_link_account"`
|
||||
RedirectBaseUrl string `json:"redirect_base_url"`
|
||||
@ -143,6 +96,19 @@ type maingateConfig struct {
|
||||
FirebaseAdminSDKCredentialFile string `json:"firebase_admin_sdk_credentialfile"`
|
||||
SteamAppId string `json:"steam_app_id"`
|
||||
SteamPublisherAuthKey string `json:"steam_publisher_authkey"`
|
||||
GlobalMaingateToken string `json:"maingate_api_token"`
|
||||
Firebase_Google_Analytics_JS_SDK_Config
|
||||
}
|
||||
|
||||
type Firebase_Google_Analytics_JS_SDK_Config struct {
|
||||
FGA_apiKey string `json:"firebase_google_analytics_jssdk_apikey"`
|
||||
FGA_authDomain string `json:"firebase_google_analytics_jssdk_authdomain"`
|
||||
FGA_databaseURL string `json:"firebase_google_analytics_jssdk_databaseurl"`
|
||||
FGA_projectId string `json:"firebase_google_analytics_jssdk_projectid"`
|
||||
FGA_storageBucket string `json:"firebase_google_analytics_jssdk_storagebucket"`
|
||||
FGA_messagingSenderId string `json:"firebase_google_analytics_jssdk_messagingsenderid"`
|
||||
FGA_appId string `json:"firebase_google_analytics_jssdk_apiid"`
|
||||
FGA_measurementId string `json:"ffirebase_google_analytics_jssdk_measurementid"`
|
||||
}
|
||||
|
||||
type globalAdmins struct {
|
||||
@ -162,11 +128,9 @@ func (ga *globalAdmins) parse() {
|
||||
|
||||
// Maingate :
|
||||
type Maingate struct {
|
||||
maingateConfig
|
||||
|
||||
mongoClient gocommon.MongoClient
|
||||
|
||||
auths *gocommon.AuthCollection
|
||||
sessionProvider session.Provider
|
||||
//services servicelist
|
||||
serviceptr unsafe.Pointer
|
||||
admins unsafe.Pointer
|
||||
@ -181,9 +145,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
|
||||
}
|
||||
@ -193,12 +158,15 @@ func New(ctx context.Context) (*Maingate, error) {
|
||||
admins.parse()
|
||||
}
|
||||
|
||||
if len(config.SessionStorage) == 0 {
|
||||
return nil, errors.New("maingate_session_storage is missing")
|
||||
}
|
||||
|
||||
if config.SessionTTL == 0 {
|
||||
config.SessionTTL = 3600
|
||||
}
|
||||
|
||||
mg := Maingate{
|
||||
maingateConfig: config,
|
||||
admins: unsafe.Pointer(&admins),
|
||||
tokenEndpoints: make(map[string]string),
|
||||
authorizationEndpoints: make(map[string]string),
|
||||
@ -212,7 +180,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)
|
||||
@ -287,67 +255,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, "maingate")
|
||||
mg.mongoClient, err = gocommon.NewMongoClient(context, config.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
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionAuth, map[string]bson.D{
|
||||
"skonly": {{Key: "sk", Value: 1}},
|
||||
}); err != nil {
|
||||
return makeErrorWithStack(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)
|
||||
}
|
||||
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionAuth, int32(mg.SessionTTL+300)); err != nil {
|
||||
return makeErrorWithStack(err)
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
if *devflag {
|
||||
@ -356,38 +310,41 @@ 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)
|
||||
if err = mg.mongoClient.MakeExpireIndex(CollectionPlatformLoginToken, int32(config.SessionTTL+300)); err != nil {
|
||||
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.auths = makeAuthCollection(mg.mongoClient, time.Duration(mg.SessionTTL*int64(time.Second)))
|
||||
mg.sessionProvider, err = session.NewProviderWithConfig(context, config.SessionConfig)
|
||||
if err != nil {
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
|
||||
var preall []struct {
|
||||
Link string `bson:"link"`
|
||||
@ -396,7 +353,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 {
|
||||
@ -411,37 +368,40 @@ 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)
|
||||
}
|
||||
|
||||
logger.Println("allblocks :", blocks)
|
||||
mg.bl.init(blocks)
|
||||
|
||||
go watchAuthCollection(context, mg.auths, mg.mongoClient)
|
||||
go mg.wl.watchCollection(context, CollectionWhitelist, mg.mongoClient)
|
||||
go mg.bl.watchCollection(context, CollectionBlock, mg.mongoClient)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var portptr = flagx.Int("port", 80, "")
|
||||
|
||||
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 {
|
||||
@ -457,10 +417,9 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
}
|
||||
|
||||
if *devflag {
|
||||
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 {
|
||||
@ -472,13 +431,13 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
}
|
||||
|
||||
empty.Divisions = map[string]*Division{
|
||||
host: {
|
||||
"default": {
|
||||
DivisionForUser: DivisionForUser{
|
||||
Priority: 0,
|
||||
State: DivisionState_FullOpen,
|
||||
},
|
||||
|
||||
Url: fmt.Sprintf("http://%s/warehouse", ipaddr),
|
||||
Url: fmt.Sprintf("http://%s:%d/warehouse", ipaddr, *portptr),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -492,21 +451,28 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
}, options.Update().SetUpsert(true))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return logger.ErrorWithCallStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Println("Service is registered :", mg.service().ServiceCode)
|
||||
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, mg.service().ServiceCode, "/"), func(w http.ResponseWriter, r *http.Request) {
|
||||
mg.service().serveHTTP(w, r)
|
||||
})
|
||||
if *devflag {
|
||||
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, mg.service().ServiceCode, "/"), func(w http.ResponseWriter, r *http.Request) {
|
||||
// mg.service()를 요청마다 불러야 함
|
||||
mg.service().serveHTTP_dev(w, r)
|
||||
})
|
||||
} else {
|
||||
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, mg.service().ServiceCode, "/"), func(w http.ResponseWriter, r *http.Request) {
|
||||
// mg.service()를 요청마다 불러야 함
|
||||
mg.service().serveHTTP(w, r)
|
||||
})
|
||||
}
|
||||
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "api/"), mg.api)
|
||||
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "query/"), mg.query)
|
||||
|
||||
configraw, _ := json.Marshal(mg.maingateConfig)
|
||||
configraw, _ := json.Marshal(config)
|
||||
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) {
|
||||
@ -539,7 +505,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"))
|
||||
@ -552,6 +518,14 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
serveMux.Handle(pattern, http.StripPrefix(pattern, staticfs))
|
||||
logger.Println("maingate static registered :", pattern)
|
||||
|
||||
fbafs := http.FileServer(http.Dir("fba"))
|
||||
pattern = gocommon.MakeHttpHandlerPattern(prefix, "fba", "/")
|
||||
serveMux.Handle(pattern, http.StripPrefix(pattern, fbafs))
|
||||
logger.Println("google_analytics static registered :", pattern)
|
||||
|
||||
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "fba", "fb-ga.min.js"), mg.google_analytics_js)
|
||||
logger.Println("google_analytics.js static registered :", pattern)
|
||||
|
||||
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)
|
||||
@ -582,59 +556,11 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mg *Maingate) query(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
if s != nil {
|
||||
logger.Error(s)
|
||||
}
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
io.Copy(io.Discard, r.Body)
|
||||
r.Body.Close()
|
||||
}()
|
||||
|
||||
queryvals := r.URL.Query()
|
||||
sk := queryvals.Get("sk")
|
||||
|
||||
if len(sk) == 0 {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
info := mg.auths.Find(sk)
|
||||
if info == nil {
|
||||
logger.Println("session key is not valid :", sk)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if !*devflag {
|
||||
apitoken := r.Header.Get("MG-X-API-TOKEN")
|
||||
if len(apitoken) == 0 {
|
||||
logger.Println("MG-X-API-TOKEN is missing")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
apitokenObj, _ := primitive.ObjectIDFromHex(apitoken)
|
||||
if !mg.service().isValidToken(apitokenObj) {
|
||||
logger.Println("MG-X-API-TOKEN is invalid :", apitoken)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
bt, _ := json.Marshal(info)
|
||||
w.Write(bt)
|
||||
}
|
||||
|
||||
func (mg *Maingate) GeneratePlatformLoginNonceKey() string {
|
||||
const allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
b := make([]byte, 52)
|
||||
for i := range b {
|
||||
b[i] = allowed[rand.Intn(len(allowed))]
|
||||
b[i] = allowed[r.Intn(len(allowed))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
@ -648,7 +574,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 찍히는 문제 때문에 제외한다.
|
||||
@ -670,7 +596,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) {
|
||||
@ -695,7 +621,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
|
||||
@ -953,3 +879,22 @@ func JWTparseCode(keyurl string, code string) (string, string, string) {
|
||||
//--- nonce 체크 필요하다.
|
||||
return claims["sub"].(string), email, nonce
|
||||
}
|
||||
|
||||
func (mg *Maingate) google_analytics_js(w http.ResponseWriter, r *http.Request) {
|
||||
fgaconfig := Firebase_Google_Analytics_JS_SDK_Config{
|
||||
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)
|
||||
if err != nil {
|
||||
logger.Error("Error executing template :", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,14 @@ func (p *memberContainerPtr[K, T]) add(m T) {
|
||||
atomic.StorePointer(&p.ptr, unsafe.Pointer(&next))
|
||||
}
|
||||
|
||||
func (p *memberContainerPtr[K, T]) get(key K) (T, bool) {
|
||||
ptr := atomic.LoadPointer(&p.ptr)
|
||||
src := (*map[K]T)(ptr)
|
||||
|
||||
out, found := (*src)[key]
|
||||
return out, found
|
||||
}
|
||||
|
||||
func (p *memberContainerPtr[K, T]) remove(key K) {
|
||||
ptr := atomic.LoadPointer(&p.ptr)
|
||||
src := (*map[K]T)(ptr)
|
||||
@ -76,24 +84,6 @@ func (p *memberContainerPtr[K, T]) all() []T {
|
||||
return out
|
||||
}
|
||||
|
||||
func (p *memberContainerPtr[K, T]) contains(key K, out *T) bool {
|
||||
ptr := atomic.LoadPointer(&p.ptr)
|
||||
src := (*map[K]T)(ptr)
|
||||
|
||||
found, exists := (*src)[key]
|
||||
if exists {
|
||||
if found.Expired() {
|
||||
p.remove(key)
|
||||
return false
|
||||
}
|
||||
if out != nil {
|
||||
out = &found
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *memberContainerPtr[K, T]) watchCollection(parentctx context.Context, coll gocommon.CollectionName, mc gocommon.MongoClient) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
|
||||
@ -95,8 +95,8 @@ func (mg *Maingate) platform_apple_get_login_url(w http.ResponseWriter, r *http.
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("client_id", mg.AppleCientId)
|
||||
params.Add("redirect_uri", mg.RedirectBaseUrl+"/authorize/"+AuthPlatformApple)
|
||||
params.Add("client_id", config.AppleCientId)
|
||||
params.Add("redirect_uri", config.RedirectBaseUrl+"/authorize/"+AuthPlatformApple)
|
||||
|
||||
params.Add("response_type", "code id_token")
|
||||
params.Add("scope", "name email")
|
||||
@ -146,7 +146,7 @@ func (mg *Maingate) platform_apple_authorize(w http.ResponseWriter, r *http.Requ
|
||||
}
|
||||
http.SetCookie(w, &cookie)
|
||||
|
||||
http.Redirect(w, r, mg.RedirectBaseUrl+"/authorize_result/"+AuthPlatformApple, http.StatusSeeOther) //-- 바로 받으니까 쿠키 안와서 한번 더 Redirect 시킨다.
|
||||
http.Redirect(w, r, config.RedirectBaseUrl+"/authorize_result/"+AuthPlatformApple, http.StatusSeeOther) //-- 바로 받으니까 쿠키 안와서 한번 더 Redirect 시킨다.
|
||||
}
|
||||
|
||||
func (mg *Maingate) platform_apple_authorize_result(w http.ResponseWriter, r *http.Request) {
|
||||
@ -208,17 +208,17 @@ func (mg *Maingate) platform_apple_authorize_result(w http.ResponseWriter, r *ht
|
||||
}
|
||||
|
||||
// Generate the client secret used to authenticate with Apple's validation servers
|
||||
secret, err := generateClientSecret(mg.ApplePrivateKey, mg.AppleTeamId, mg.AppleServiceId, mg.AppleKeyId)
|
||||
secret, err := generateClientSecret(config.ApplePrivateKey, config.AppleTeamId, config.AppleServiceId, config.AppleKeyId)
|
||||
if err != nil {
|
||||
logger.Error("error generating secret: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
vReq := Apple_WebValidationTokenRequest{
|
||||
ClientID: mg.AppleServiceId,
|
||||
ClientID: config.AppleServiceId,
|
||||
ClientSecret: secret,
|
||||
Code: code,
|
||||
RedirectURI: mg.RedirectBaseUrl + "/authorize/" + AuthPlatformApple, // This URL must be validated with apple in your service
|
||||
RedirectURI: config.RedirectBaseUrl + "/authorize/" + AuthPlatformApple, // This URL must be validated with apple in your service
|
||||
}
|
||||
|
||||
var resp Apple_ValidationResponse
|
||||
@ -268,14 +268,14 @@ func (mg *Maingate) platform_apple_authorize_result(w http.ResponseWriter, r *ht
|
||||
|
||||
func (mg *Maingate) platform_apple_getuserinfo(refreshToken string) (bool, string, string) {
|
||||
//=================================RefreshToken을 사용해서 정보 가져 온다. 이미 인증된 사용자의 업데이트 목적
|
||||
secret, err := generateClientSecret(mg.ApplePrivateKey, mg.AppleTeamId, mg.AppleServiceId, mg.AppleKeyId)
|
||||
secret, err := generateClientSecret(config.ApplePrivateKey, config.AppleTeamId, config.AppleServiceId, config.AppleKeyId)
|
||||
if err != nil {
|
||||
logger.Error("error generating secret: ", err)
|
||||
return false, "", ""
|
||||
}
|
||||
|
||||
vReqRefreshToken := Apple_WebRefreshTokenRequest{
|
||||
ClientID: mg.AppleServiceId,
|
||||
ClientID: config.AppleServiceId,
|
||||
ClientSecret: secret,
|
||||
RefreshToken: refreshToken,
|
||||
}
|
||||
|
||||
@ -84,9 +84,9 @@ func (mg *Maingate) platform_google_get_login_url(w http.ResponseWriter, r *http
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("client_id", mg.GoogleClientId)
|
||||
params.Add("client_id", config.GoogleClientId)
|
||||
params.Add("response_type", "code")
|
||||
params.Add("redirect_uri", mg.RedirectBaseUrl+"/authorize/"+AuthPlatformGoogle)
|
||||
params.Add("redirect_uri", config.RedirectBaseUrl+"/authorize/"+AuthPlatformGoogle)
|
||||
params.Add("scope", "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email")
|
||||
params.Add("access_type", "offline")
|
||||
params.Add("prompt", "consent")
|
||||
@ -140,7 +140,7 @@ func (mg *Maingate) platform_google_authorize(w http.ResponseWriter, r *http.Req
|
||||
}
|
||||
http.SetCookie(w, &cookie2)
|
||||
|
||||
http.Redirect(w, r, mg.RedirectBaseUrl+"/authorize_result/"+AuthPlatformGoogle, http.StatusSeeOther) //-- 바로 받으니까 쿠키 안와서 한번 더 Redirect 시킨다.
|
||||
http.Redirect(w, r, config.RedirectBaseUrl+"/authorize_result/"+AuthPlatformGoogle, http.StatusSeeOther) //-- 바로 받으니까 쿠키 안와서 한번 더 Redirect 시킨다.
|
||||
}
|
||||
|
||||
func (mg *Maingate) platform_google_authorize_result(w http.ResponseWriter, r *http.Request) {
|
||||
@ -211,9 +211,9 @@ func (mg *Maingate) platform_google_authorize_result(w http.ResponseWriter, r *h
|
||||
|
||||
//=================
|
||||
params := url.Values{}
|
||||
params.Add("client_id", mg.GoogleClientId)
|
||||
params.Add("redirect_uri", mg.RedirectBaseUrl+"/authorize/"+AuthPlatformGoogle)
|
||||
params.Add("client_secret", mg.GoogleClientSecret)
|
||||
params.Add("client_id", config.GoogleClientId)
|
||||
params.Add("redirect_uri", config.RedirectBaseUrl+"/authorize/"+AuthPlatformGoogle)
|
||||
params.Add("client_secret", config.GoogleClientSecret)
|
||||
params.Add("code", code)
|
||||
params.Add("grant_type", "authorization_code")
|
||||
|
||||
@ -285,9 +285,9 @@ func (mg *Maingate) platform_google_getuserinfo(info usertokeninfo) (bool, strin
|
||||
if time.Now().Unix() > info.accesstoken_expire_time {
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("client_id", mg.GoogleClientId)
|
||||
params.Add("redirect_uri", mg.RedirectBaseUrl+"/authorize/"+AuthPlatformGoogle)
|
||||
params.Add("client_secret", mg.GoogleClientSecret)
|
||||
params.Add("client_id", config.GoogleClientId)
|
||||
params.Add("redirect_uri", config.RedirectBaseUrl+"/authorize/"+AuthPlatformGoogle)
|
||||
params.Add("client_secret", config.GoogleClientSecret)
|
||||
params.Add("scope", "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email")
|
||||
params.Add("refresh_token", info.token)
|
||||
params.Add("grant_type", "refresh_token")
|
||||
|
||||
@ -83,9 +83,9 @@ func (mg *Maingate) platform_microsoft_get_login_url(w http.ResponseWriter, r *h
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("client_id", mg.MicrosoftClientId)
|
||||
params.Add("client_id", config.MicrosoftClientId)
|
||||
params.Add("response_type", "code")
|
||||
params.Add("redirect_uri", mg.RedirectBaseUrl+"/authorize/"+AuthPlatformMicrosoft)
|
||||
params.Add("redirect_uri", config.RedirectBaseUrl+"/authorize/"+AuthPlatformMicrosoft)
|
||||
params.Add("response_mode", "query")
|
||||
params.Add("scope", "openid offline_access https://graph.microsoft.com/mail.read")
|
||||
|
||||
@ -127,7 +127,7 @@ func (mg *Maingate) platform_microsoft_authorize(w http.ResponseWriter, r *http.
|
||||
}
|
||||
http.SetCookie(w, &cookie)
|
||||
|
||||
http.Redirect(w, r, mg.RedirectBaseUrl+"/authorize_result/"+AuthPlatformMicrosoft, http.StatusSeeOther) //-- 바로 받으니까 쿠키 안와서 한번 더 Redirect 시킨다.
|
||||
http.Redirect(w, r, config.RedirectBaseUrl+"/authorize_result/"+AuthPlatformMicrosoft, http.StatusSeeOther) //-- 바로 받으니까 쿠키 안와서 한번 더 Redirect 시킨다.
|
||||
}
|
||||
|
||||
func (mg *Maingate) platform_microsoft_authorize_result(w http.ResponseWriter, r *http.Request) {
|
||||
@ -191,13 +191,13 @@ func (mg *Maingate) platform_microsoft_authorize_result(w http.ResponseWriter, r
|
||||
//=================
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("client_id", mg.MicrosoftClientId)
|
||||
params.Add("redirect_uri", mg.RedirectBaseUrl+"/authorize/"+AuthPlatformMicrosoft)
|
||||
params.Add("client_id", config.MicrosoftClientId)
|
||||
params.Add("redirect_uri", config.RedirectBaseUrl+"/authorize/"+AuthPlatformMicrosoft)
|
||||
params.Add("code", code)
|
||||
params.Add("scope", "openid offline_access https://graph.microsoft.com/mail.read")
|
||||
params.Add("grant_type", "authorization_code")
|
||||
|
||||
params.Add("client_secret", mg.MicrosoftClientSecret)
|
||||
params.Add("client_secret", config.MicrosoftClientSecret)
|
||||
|
||||
var respReferesh Microsoft_ValidationResponse
|
||||
acceestoken_expire_time := time.Now().Unix()
|
||||
@ -263,13 +263,13 @@ func (mg *Maingate) platform_microsoft_getuserinfo(info usertokeninfo) (bool, st
|
||||
if time.Now().Unix() > info.accesstoken_expire_time {
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("client_id", mg.MicrosoftClientId)
|
||||
params.Add("redirect_uri", mg.RedirectBaseUrl+"/authorize/"+AuthPlatformMicrosoft)
|
||||
params.Add("client_id", config.MicrosoftClientId)
|
||||
params.Add("redirect_uri", config.RedirectBaseUrl+"/authorize/"+AuthPlatformMicrosoft)
|
||||
params.Add("refresh_token", info.token)
|
||||
params.Add("scope", "openid offline_access https://graph.microsoft.com/mail.read")
|
||||
params.Add("grant_type", "refresh_token")
|
||||
|
||||
params.Add("client_secret", mg.MicrosoftClientSecret)
|
||||
params.Add("client_secret", config.MicrosoftClientSecret)
|
||||
|
||||
var respReferesh Microsoft_ValidationResponse
|
||||
acceestoken_expire_time := time.Now().Unix()
|
||||
|
||||
@ -40,7 +40,7 @@ func (mg *Maingate) platform_steamsdk_authorize(w http.ResponseWriter, r *http.R
|
||||
}
|
||||
|
||||
if !*noauth {
|
||||
err = authenticateSteamUser(mg.SteamPublisherAuthKey, mg.SteamAppId, authinfo.UserSteamId, authinfo.UserAuthToken)
|
||||
err = authenticateSteamUser(config.SteamPublisherAuthKey, config.SteamAppId, authinfo.UserSteamId, authinfo.UserAuthToken)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
@ -118,9 +118,8 @@ func authenticateSteamUser(pubkey, appid, playerid, ticket string) error {
|
||||
}
|
||||
|
||||
func (mg *Maingate) platform_steamsdk_getuserinfo(info usertokeninfo) (bool, string, string) {
|
||||
|
||||
// Steam은 이메일 정보를 받을수 없기 때문에 dummy임시 주소 할당하여 리턴한다.
|
||||
dummyEmail := fmt.Sprintf("__dummy_%s@steamtemp__", info.userid)
|
||||
// Steam은 이메일 정보를 받을수 없기 때문에 userid로 리턴한다.
|
||||
dummyEmail := fmt.Sprintf("%s@steam.id", info.userid)
|
||||
return true, info.userid, dummyEmail
|
||||
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ func (mg *Maingate) platform_twitter_authorize(w http.ResponseWriter, r *http.Re
|
||||
}
|
||||
http.SetCookie(w, &cookie)
|
||||
|
||||
http.Redirect(w, r, mg.RedirectBaseUrl+"/authorize_result/"+AuthPlatformTwitter, http.StatusSeeOther) //-- 바로 받으니까 쿠키 안와서 한번 더 Redirect 시킨다.
|
||||
http.Redirect(w, r, config.RedirectBaseUrl+"/authorize_result/"+AuthPlatformTwitter, http.StatusSeeOther) //-- 바로 받으니까 쿠키 안와서 한번 더 Redirect 시킨다.
|
||||
}
|
||||
|
||||
func (mg *Maingate) platform_twitter_authorize_result(w http.ResponseWriter, r *http.Request) {
|
||||
@ -249,7 +249,7 @@ func (mg *Maingate) platform_twitter_getuserinfo(token, secret string) (bool, st
|
||||
}
|
||||
|
||||
func (mg *Maingate) CallTwitterAPI_WithAPPKey(requesturl, method, nonce string) string {
|
||||
return mg.CallTwitterAPI(requesturl, method, mg.TwitterOAuthKey, mg.TwitterOAuthSecret, nonce)
|
||||
return mg.CallTwitterAPI(requesturl, method, config.TwitterOAuthKey, config.TwitterOAuthSecret, nonce)
|
||||
}
|
||||
|
||||
func (mg *Maingate) CallTwitterAPI(requesturl, method, oauth_token, oauth_secret, nonce string) string {
|
||||
@ -272,8 +272,8 @@ func (mg *Maingate) CallTwitterAPI(requesturl, method, oauth_token, oauth_secret
|
||||
//vals.Add("oauth_callback", "actionclient://callback")
|
||||
//vals.Add("oauth_callback", "http://127.0.0.1:7770/auth")
|
||||
|
||||
vals.Add("oauth_callback", mg.RedirectBaseUrl+"/authorize/"+AuthPlatformTwitter)
|
||||
vals.Add("oauth_consumer_key", mg.TwitterCustomerKey)
|
||||
vals.Add("oauth_callback", config.RedirectBaseUrl+"/authorize/"+AuthPlatformTwitter)
|
||||
vals.Add("oauth_consumer_key", config.TwitterCustomerKey)
|
||||
vals.Add("oauth_token", oauth_token)
|
||||
vals.Add("oauth_signature_method", "HMAC-SHA1")
|
||||
vals.Add("oauth_timestamp", strconv.Itoa(int(time.Now().Unix())))
|
||||
@ -282,7 +282,7 @@ func (mg *Maingate) CallTwitterAPI(requesturl, method, oauth_token, oauth_secret
|
||||
|
||||
parameterString := strings.Replace(vals.Encode(), "+", "%20", -1)
|
||||
signatureBase := strings.ToUpper(method) + "&" + url.QueryEscape(strings.Split(requesturl, "?")[0]) + "&" + url.QueryEscape(parameterString)
|
||||
signingKey := url.QueryEscape(mg.TwitterCustomerSecret) + "&" + url.QueryEscape(oauth_secret)
|
||||
signingKey := url.QueryEscape(config.TwitterCustomerSecret) + "&" + url.QueryEscape(oauth_secret)
|
||||
signature := calculateTwitterSignature(signatureBase, signingKey)
|
||||
|
||||
headerString := "OAuth oauth_callback=\"" + url.QueryEscape(vals.Get("oauth_callback")) + "\", oauth_consumer_key=\"" + url.QueryEscape(vals.Get("oauth_consumer_key")) + "\", oauth_nonce=\"" + url.QueryEscape(vals.Get("oauth_nonce")) +
|
||||
|
||||
478
core/service.go
478
core/service.go
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/session"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -21,17 +22,10 @@ import (
|
||||
)
|
||||
|
||||
type blockinfo struct {
|
||||
Start primitive.DateTime `bson:"start" json:"start"`
|
||||
End primitive.DateTime `bson:"_ts" json:"_ts"`
|
||||
Reason string `bson:"reason" json:"reason"`
|
||||
Accid primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
|
||||
}
|
||||
|
||||
type blockinfoWithStringId struct {
|
||||
Reason string `bson:"reason" json:"reason"`
|
||||
StrId string `bson:"id" json:"id"`
|
||||
StartUnix int64 `bson:"start_unix" json:"start_unix"`
|
||||
EndUnix int64 `bson:"end_unix" json:"end_unix"`
|
||||
Start primitive.DateTime `bson:"start" json:"start"`
|
||||
End primitive.DateTime `bson:"_ts" json:"_ts"`
|
||||
Accid primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
|
||||
Meta primitive.M `bson:"meta,omitempty" json:"meta,omitempty"`
|
||||
}
|
||||
|
||||
type whitelistmember struct {
|
||||
@ -111,11 +105,11 @@ type serviceDescription struct {
|
||||
MaximumNumLinkAccount int64
|
||||
VersionSplits map[string]string `bson:"version_splits" json:"version_splits"`
|
||||
|
||||
auths *gocommon.AuthCollection
|
||||
wl memberContainerPtr[string, *whitelistmember]
|
||||
bl memberContainerPtr[primitive.ObjectID, *blockinfo]
|
||||
mongoClient gocommon.MongoClient
|
||||
sessionTTL time.Duration
|
||||
sessionProvider session.Provider
|
||||
wl *memberContainerPtr[string, *whitelistmember]
|
||||
bl *memberContainerPtr[primitive.ObjectID, *blockinfo]
|
||||
mongoClient gocommon.MongoClient
|
||||
sessionTTL time.Duration
|
||||
|
||||
serviceCodeBytes []byte
|
||||
getUserBrowserInfo func(r *http.Request) (string, error)
|
||||
@ -123,11 +117,9 @@ type serviceDescription struct {
|
||||
updateUserinfo func(info usertokeninfo) (bool, string, string)
|
||||
getProviderInfo func(platform string, uid string) (string, string, error)
|
||||
|
||||
divisionsForUsersSerialized []byte
|
||||
divisionsSerialized []byte
|
||||
serviceSerialized []byte
|
||||
serviceSummarySerialized []byte
|
||||
divisionsSplits map[string][]byte
|
||||
divisionsSerialized []byte
|
||||
serviceSerialized []byte
|
||||
divisionsSplits map[string][]byte
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) isValidToken(apiToken primitive.ObjectID) bool {
|
||||
@ -164,6 +156,7 @@ func (sh *serviceDescription) readProfile(authtype string, id string, binfo stri
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(userinfo.token) == 0 {
|
||||
return "", errors.New("refreshtoken token not found")
|
||||
}
|
||||
@ -189,11 +182,10 @@ func (sh *serviceDescription) prepare(mg *Maingate) error {
|
||||
}
|
||||
|
||||
divsForUsers := make(map[string]*DivisionForUser)
|
||||
var namesOnly []string
|
||||
defaultDivNames := make(map[string]bool)
|
||||
for dn, div := range divs {
|
||||
namesOnly = append(namesOnly, dn)
|
||||
if div.State == DivisionState_Closed {
|
||||
continue
|
||||
if div.State != DivisionState_Closed {
|
||||
defaultDivNames[dn] = true
|
||||
}
|
||||
|
||||
divsForUsers[dn] = &div.DivisionForUser
|
||||
@ -230,38 +222,58 @@ func (sh *serviceDescription) prepare(mg *Maingate) error {
|
||||
}
|
||||
|
||||
sh.divisionsSerialized, _ = json.Marshal(divs)
|
||||
sh.divisionsForUsersSerialized, _ = json.Marshal(divsForUsers)
|
||||
|
||||
if len(sh.VersionSplits) == 0 {
|
||||
sh.VersionSplits = map[string]string{
|
||||
"default": strings.Join(namesOnly, ","),
|
||||
}
|
||||
}
|
||||
|
||||
sh.divisionsSplits = make(map[string][]byte)
|
||||
for ver, divnamesT := range sh.VersionSplits {
|
||||
if ver == "default" {
|
||||
continue
|
||||
}
|
||||
divnames := strings.Split(divnamesT, ",")
|
||||
split := make(map[string]*DivisionForUser)
|
||||
for _, divname := range divnames {
|
||||
split[divname] = divsForUsers[divname]
|
||||
|
||||
// 스플릿 된 버전은 default에서 제거해야 한다.
|
||||
delete(defaultDivNames, divname)
|
||||
}
|
||||
splitMarshaled, _ := json.Marshal(split)
|
||||
sh.divisionsSplits[ver] = splitMarshaled
|
||||
}
|
||||
|
||||
sh.MaximumNumLinkAccount = mg.maingateConfig.MaximumNumLinkAccount
|
||||
defaultsDivs := make(map[string]*DivisionForUser)
|
||||
for divname := range defaultDivNames {
|
||||
defaultsDivs[divname] = divsForUsers[divname]
|
||||
}
|
||||
defaultMarshaled, _ := json.Marshal(defaultsDivs)
|
||||
sh.divisionsSplits["default"] = defaultMarshaled
|
||||
|
||||
sh.MaximumNumLinkAccount = config.MaximumNumLinkAccount
|
||||
sh.mongoClient = mg.mongoClient
|
||||
sh.auths = mg.auths
|
||||
sh.sessionTTL = time.Duration(mg.SessionTTL * int64(time.Second))
|
||||
sh.sessionProvider = mg.sessionProvider
|
||||
sh.sessionTTL = time.Duration(config.SessionTTL * int64(time.Second))
|
||||
sh.serviceCodeBytes, _ = hex.DecodeString(sh.ServiceCode)
|
||||
sh.getUserBrowserInfo = mg.GetUserBrowserInfo
|
||||
sh.getUserTokenWithCheck = mg.getUserTokenWithCheck
|
||||
sh.updateUserinfo = mg.updateUserinfo
|
||||
sh.getProviderInfo = mg.getProviderInfo
|
||||
|
||||
sh.wl = mg.wl
|
||||
sh.bl = mg.bl
|
||||
sh.serviceSummarySerialized, _ = json.Marshal(sh.ServiceDescriptionSummary)
|
||||
if globalApiToken, err := primitive.ObjectIDFromHex(config.GlobalMaingateToken); err == nil {
|
||||
if !globalApiToken.IsZero() {
|
||||
f := func() bool {
|
||||
for _, t := range sh.ServerApiTokens {
|
||||
if t == globalApiToken {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}()
|
||||
if !f {
|
||||
sh.ServerApiTokens = append(sh.ServerApiTokens, globalApiToken)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sh.wl = &mg.wl
|
||||
sh.bl = &mg.bl
|
||||
sh.serviceSerialized, _ = json.Marshal(sh)
|
||||
|
||||
logger.Println("service is ready :", sh.ServiceCode, string(sh.serviceSerialized))
|
||||
@ -291,11 +303,10 @@ func (sh *serviceDescription) link(w http.ResponseWriter, r *http.Request) {
|
||||
newType := queryvals.Get("ntype")
|
||||
newId := queryvals.Get("nid")
|
||||
|
||||
oldAuth := sh.auths.Find(sk)
|
||||
if oldAuth == nil {
|
||||
// 잘못된 세션
|
||||
logger.Println("link failed. session key is not valid :", sk)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
oldAuth, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@ -312,7 +323,7 @@ func (sh *serviceDescription) link(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
//if oldAuth.Token != oldToken || oldAuth.Uid != oldId || oldAuth.Platform != oldType {
|
||||
if oldAuth.Uid != oldId || oldAuth.Platform != oldType {
|
||||
logger.Println("link failed. session key is not correct :", *oldAuth, queryvals)
|
||||
logger.Println("link failed. session key is not correct :", oldAuth, queryvals)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -370,7 +381,7 @@ func (sh *serviceDescription) link(w http.ResponseWriter, r *http.Request) {
|
||||
"_id": link["_id"].(primitive.ObjectID),
|
||||
}, bson.M{
|
||||
"$setOnInsert": bson.M{
|
||||
"accid": oldAuth.Accid,
|
||||
"accid": oldAuth.Account,
|
||||
"create": createtime,
|
||||
},
|
||||
}, options.Update().SetUpsert(true))
|
||||
@ -410,11 +421,10 @@ func (sh *serviceDescription) unlink(w http.ResponseWriter, r *http.Request) {
|
||||
sId := queryvals.Get("sid")
|
||||
sk := queryvals.Get("sk")
|
||||
|
||||
authInfo := sh.auths.Find(sk)
|
||||
if authInfo == nil {
|
||||
// 잘못된 세션
|
||||
logger.Println("linkinfo failed. session key is not valid :", sk)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@ -427,13 +437,13 @@ func (sh *serviceDescription) unlink(w http.ResponseWriter, r *http.Request) {
|
||||
// fmt.Println("=================")
|
||||
|
||||
if authInfo.Uid != sId || authInfo.Platform != sType {
|
||||
logger.Println("unlink failed. session key is not correct :", *authInfo, queryvals)
|
||||
logger.Println("unlink failed. session key is not correct :", authInfo, queryvals)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
numRecord, err := sh.mongoClient.Collection(CollectionAccount).CountDocuments(context.Background(), bson.M{
|
||||
"accid": authInfo.Accid,
|
||||
"accid": authInfo.Account,
|
||||
}, options.Count().SetLimit(2))
|
||||
|
||||
if err != nil {
|
||||
@ -502,11 +512,10 @@ func (sh *serviceDescription) linkinfo(w http.ResponseWriter, r *http.Request) {
|
||||
sId := queryvals.Get("sid")
|
||||
sk := queryvals.Get("sk")
|
||||
|
||||
authInfo := sh.auths.Find(sk)
|
||||
if authInfo == nil {
|
||||
// 잘못된 세션
|
||||
logger.Println("linkinfo failed. session key is not valid :", sk)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@ -520,13 +529,13 @@ func (sh *serviceDescription) linkinfo(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
//if oldAuth.Token != oldToken || oldAuth.Uid != oldId || oldAuth.Platform != oldType {
|
||||
if authInfo.Uid != sId || authInfo.Platform != sType {
|
||||
logger.Println("linkinfo failed. session key is not correct :", *authInfo, queryvals)
|
||||
logger.Println("linkinfo failed. session key is not correct :", authInfo, queryvals)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
numRecord, err := sh.mongoClient.Collection(CollectionAccount).CountDocuments(context.Background(), bson.M{
|
||||
"accid": authInfo.Accid,
|
||||
"accid": authInfo.Account,
|
||||
}, options.Count().SetLimit(sh.MaximumNumLinkAccount))
|
||||
|
||||
if err != nil {
|
||||
@ -540,6 +549,71 @@ func (sh *serviceDescription) linkinfo(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
// == 계정 이메일 조회
|
||||
func (sh *serviceDescription) emailinfo(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
if s != nil {
|
||||
logger.Error(s)
|
||||
}
|
||||
}()
|
||||
|
||||
if r.Method != "GET" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
queryvals := r.URL.Query()
|
||||
sk := queryvals.Get("sk")
|
||||
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
email := authInfo.Email
|
||||
|
||||
if strings.HasPrefix(email, "__dummy_") && strings.HasSuffix(email, "temp__") {
|
||||
email = ""
|
||||
}
|
||||
|
||||
if strings.HasSuffix(email, "@noauth.flag") || strings.HasSuffix(email, "@guest.flag") {
|
||||
email = ""
|
||||
}
|
||||
|
||||
// fmt.Println("=================")
|
||||
// fmt.Println(email)
|
||||
// fmt.Println("=================")
|
||||
//logger.Println("Email :", email)
|
||||
|
||||
w.Write([]byte(fmt.Sprintf(`{"email":"%s"}`, email)))
|
||||
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) authorize_dev(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "DELETE" {
|
||||
sk := r.Header.Get("AS-X-SESSION")
|
||||
if authinfo, err := sh.sessionProvider.Query(sk); err == nil {
|
||||
bt := r.Header.Get("AS-X-BLOCK")
|
||||
if len(bt) > 0 {
|
||||
dur, _ := strconv.ParseInt(bt, 10, 0)
|
||||
sh.bl.add(&blockinfo{
|
||||
Start: primitive.NewDateTimeFromTime(time.Now().UTC()),
|
||||
End: primitive.NewDateTimeFromTime(time.Now().UTC().Add(time.Second * time.Duration(dur))),
|
||||
Accid: authinfo.Account,
|
||||
})
|
||||
}
|
||||
sh.sessionProvider.Invalidate(authinfo.Account)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
sh.authorize(w, r)
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
@ -556,8 +630,26 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
|
||||
queryvals := r.URL.Query()
|
||||
authtype := queryvals.Get("type")
|
||||
uid := queryvals.Get("id")
|
||||
//accesstoken := queryvals.Get("token") //-- 이거 이제 받지마라
|
||||
session := queryvals.Get("sk")
|
||||
if sk := queryvals.Get("sk"); len(sk) > 0 {
|
||||
success, err := sh.sessionProvider.Touch(sk)
|
||||
if err != nil {
|
||||
logger.Error("authorize failed. sessionProvider.Touch err:", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// !success일 때 빈 body를 보내면 클라이언트는 로그아웃 된다.
|
||||
if success {
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"sk": sk,
|
||||
"expirein": sh.sessionTTL.Seconds(),
|
||||
})
|
||||
} else {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var email string
|
||||
|
||||
if !*noauth {
|
||||
@ -581,142 +673,96 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
|
||||
if err != nil {
|
||||
logger.Error("getProviderInfo failed :", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if authtype != newType || uid != newId {
|
||||
authtype = newType
|
||||
uid = newId
|
||||
logger.Println("auth success ( redirect ) :", authtype, uid, email, session)
|
||||
}
|
||||
} else {
|
||||
} else if *devflag {
|
||||
email = fmt.Sprintf("%s@guest.flag", uid)
|
||||
} else {
|
||||
// authtype이 없으면 입장 불가
|
||||
logger.Error("authorize failed. 'type' query parameter is missing")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
email = fmt.Sprintf("%s@noauth.flag", uid)
|
||||
}
|
||||
|
||||
//if len(session) == 0 && len(email) > 0 {
|
||||
if len(session) == 0 {
|
||||
// platform + id -> account id
|
||||
createtime := primitive.NewDateTimeFromTime(time.Now().UTC())
|
||||
link, err := sh.mongoClient.FindOneAndUpdate(CollectionLink, bson.M{
|
||||
"platform": authtype,
|
||||
"uid": uid,
|
||||
}, bson.M{
|
||||
"$setOnInsert": bson.M{
|
||||
"create": createtime,
|
||||
"email": email,
|
||||
},
|
||||
}, options.FindOneAndUpdate().SetReturnDocument(options.After).SetUpsert(true).SetProjection(bson.M{"_id": 1}))
|
||||
if err != nil {
|
||||
logger.Error("authorize failed :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
linkid := link["_id"].(primitive.ObjectID)
|
||||
newaccid := primitive.NewObjectID()
|
||||
for i := 0; i < len(sh.serviceCodeBytes); i++ {
|
||||
newaccid[i] ^= sh.serviceCodeBytes[i]
|
||||
}
|
||||
account, err := sh.mongoClient.FindOneAndUpdate(CollectionAccount, bson.M{
|
||||
"_id": linkid,
|
||||
}, bson.M{
|
||||
"$setOnInsert": bson.M{
|
||||
"accid": newaccid,
|
||||
"create": createtime,
|
||||
},
|
||||
}, options.FindOneAndUpdate().SetReturnDocument(options.After).SetUpsert(true).SetProjection(bson.M{"accid": 1, "create": 1}))
|
||||
if err != nil {
|
||||
logger.Error("authorize failed. Update sh.ServiceName err:", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
accid := account["accid"].(primitive.ObjectID)
|
||||
oldcreate := account["create"].(primitive.DateTime)
|
||||
newaccount := oldcreate == createtime
|
||||
|
||||
var bi *blockinfo
|
||||
if sh.bl.contains(accid, &bi) {
|
||||
// 블럭된 계정. 블락 정보를 알려준다.
|
||||
w.Header().Add("MG-ACCOUNTBLOCK-START", strconv.FormatInt(bi.Start.Time().Unix(), 10))
|
||||
w.Header().Add("MG-ACCOUNTBLOCK-END", strconv.FormatInt(bi.End.Time().Unix(), 10))
|
||||
w.Header().Add("MG-ACCOUNTBLOCK-REASON", bi.Reason)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
newsession := primitive.NewObjectID()
|
||||
expired := primitive.NewDateTimeFromTime(time.Now().UTC().Add(sh.sessionTTL))
|
||||
newauth := gocommon.Authinfo{
|
||||
Accid: accid,
|
||||
ServiceCode: sh.ServiceCode,
|
||||
Platform: authtype,
|
||||
Uid: uid,
|
||||
Email: email,
|
||||
Sk: newsession,
|
||||
Expired: expired,
|
||||
//RefreshToken: queryvals.Get("rt"),
|
||||
}
|
||||
|
||||
_, _, err = sh.mongoClient.UpsertOne(CollectionAuth, bson.M{"_id": newauth.Accid}, &newauth)
|
||||
if err != nil {
|
||||
logger.Error("authorize failed :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
output := map[string]any{
|
||||
"sk": newsession.Hex(),
|
||||
"expirein": sh.sessionTTL.Seconds(),
|
||||
"newAccount": newaccount,
|
||||
"accid": newauth.Accid.Hex(),
|
||||
}
|
||||
if *noauth {
|
||||
output["noauth"] = true
|
||||
}
|
||||
bt, _ := json.Marshal(output)
|
||||
w.Write(bt)
|
||||
} else if len(session) > 0 {
|
||||
sessionobj, _ := primitive.ObjectIDFromHex(session)
|
||||
if !sessionobj.IsZero() {
|
||||
updated, _, err := sh.mongoClient.Update(CollectionAuth,
|
||||
bson.M{
|
||||
"sk": sessionobj,
|
||||
},
|
||||
bson.M{
|
||||
"$currentDate": bson.M{
|
||||
"_ts": bson.M{"$type": "date"},
|
||||
},
|
||||
}, options.Update().SetUpsert(false))
|
||||
if err != nil {
|
||||
logger.Error("update auth collection failed")
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if !updated {
|
||||
// 세션이 없네?
|
||||
logger.Println("authorize failed. session not exists in database :", session)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
output := map[string]any{
|
||||
"sk": session,
|
||||
"expirein": sh.sessionTTL.Seconds(),
|
||||
}
|
||||
bt, _ := json.Marshal(output)
|
||||
w.Write(bt)
|
||||
} else {
|
||||
logger.Println("authorize failed. sk is not valid hex :", session)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
logger.Println("authorize failed. id empty :", queryvals)
|
||||
// platform + id -> account id
|
||||
createtime := primitive.NewDateTimeFromTime(time.Now().UTC())
|
||||
link, err := sh.mongoClient.FindOneAndUpdate(CollectionLink, bson.M{
|
||||
"platform": authtype,
|
||||
"uid": uid,
|
||||
}, bson.M{
|
||||
"$setOnInsert": bson.M{
|
||||
"create": createtime,
|
||||
"email": email,
|
||||
},
|
||||
}, options.FindOneAndUpdate().SetReturnDocument(options.After).SetUpsert(true).SetProjection(bson.M{"_id": 1}))
|
||||
if err != nil {
|
||||
logger.Error("authorize failed :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
linkid := link["_id"].(primitive.ObjectID)
|
||||
newaccid := primitive.NewObjectID()
|
||||
for i := 0; i < len(sh.serviceCodeBytes); i++ {
|
||||
newaccid[i] ^= sh.serviceCodeBytes[i]
|
||||
}
|
||||
account, err := sh.mongoClient.FindOneAndUpdate(CollectionAccount, bson.M{
|
||||
"_id": linkid,
|
||||
}, bson.M{
|
||||
"$setOnInsert": bson.M{
|
||||
"accid": newaccid,
|
||||
"create": createtime,
|
||||
},
|
||||
}, options.FindOneAndUpdate().SetReturnDocument(options.After).SetUpsert(true).SetProjection(bson.M{"accid": 1, "create": 1}))
|
||||
if err != nil {
|
||||
logger.Error("authorize failed. Update sh.ServiceName err:", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
accid := account["accid"].(primitive.ObjectID)
|
||||
oldcreate := account["create"].(primitive.DateTime)
|
||||
newaccount := oldcreate == createtime
|
||||
|
||||
if bi, ok := sh.bl.get(accid); ok {
|
||||
// 블럭된 계정. 블락 정보를 알려준다.
|
||||
w.Header().Add("MG-ACCOUNTBLOCK-START", strconv.FormatInt(bi.Start.Time().Unix(), 10))
|
||||
w.Header().Add("MG-ACCOUNTBLOCK-END", strconv.FormatInt(bi.End.Time().Unix(), 10))
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
sk, err := sh.sessionProvider.New(&session.Authorization{
|
||||
Account: accid,
|
||||
Platform: authtype,
|
||||
Uid: uid,
|
||||
Email: email,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("authorize failed. sessionProvider.New err:", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
output := map[string]any{
|
||||
"sk": sk,
|
||||
"expirein": sh.sessionTTL.Seconds(),
|
||||
"newAccount": newaccount,
|
||||
"accid": accid.Hex(),
|
||||
}
|
||||
if *noauth {
|
||||
output["noauth"] = true
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(output)
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) findVersionSplit(version string) []byte {
|
||||
@ -732,6 +778,14 @@ func (sh *serviceDescription) findVersionSplit(version string) []byte {
|
||||
return sh.divisionsSplits["default"]
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) serveHTTP_dev(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasSuffix(r.URL.Path, "/auth") {
|
||||
sh.authorize_dev(w, r)
|
||||
} else {
|
||||
sh.serveHTTP(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
@ -753,6 +807,8 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request)
|
||||
sh.unlink(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/linkinfo") {
|
||||
sh.linkinfo(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/emailinfo") {
|
||||
sh.emailinfo(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/divs") {
|
||||
// TODO : 세션키와 authtoken을 헤더로 받아서 accid 조회
|
||||
queryvals := r.URL.Query()
|
||||
@ -767,7 +823,14 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request)
|
||||
// TODO : 각 서버에 있는 자산? 캐릭터 정보를 보여줘야 하나. 뭘 보여줄지는 프로젝트에 문의
|
||||
// 일단 서버 종류만 내려보내자
|
||||
// 세션키가 있는지 확인
|
||||
if _, ok := sh.auths.IsValid(sk, ""); !ok {
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if authInfo.Account.IsZero() {
|
||||
logger.Println("sessionkey is not valid :", sk)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
@ -788,7 +851,14 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request)
|
||||
// TODO : 각 서버에 있는 자산? 캐릭터 정보를 보여줘야 하나. 뭘 보여줄지는 프로젝트에 문의
|
||||
// 일단 서버 종류만 내려보내자
|
||||
// 세션키가 있는지 확인
|
||||
if _, ok := sh.auths.IsValid(sk, ""); !ok {
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if authInfo.Account.IsZero() {
|
||||
logger.Println("sessionkey is not valid :", sk)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
@ -797,26 +867,33 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request)
|
||||
divname := queryvals.Get("div")
|
||||
divname = strings.Trim(divname, `"`)
|
||||
div := sh.Divisions[divname]
|
||||
var addrresp string
|
||||
if div != nil {
|
||||
logger.Println("/addr :", divname, div.State)
|
||||
|
||||
switch div.State {
|
||||
case DivisionState_FullOpen:
|
||||
w.Write([]byte(fmt.Sprintf(`{"service":"%s"}`, div.Url)))
|
||||
addrresp = fmt.Sprintf(`{"service":"%s"}`, div.Url)
|
||||
//w.Write([]byte(fmt.Sprintf(`{"service":"%s"}`, div.Url)))
|
||||
|
||||
case DivisionState_RestrictedOpen:
|
||||
// 점검중이면 whitelist만 입장 가능
|
||||
cell := sh.auths.QuerySession(sk, "")
|
||||
if cell == nil {
|
||||
logger.Println("sessionkey is not valid :", sk)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
authInfo, err := sh.sessionProvider.Query(sk)
|
||||
if err != nil {
|
||||
logger.Println("sessionProvider.Query return err :", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
wm := &whitelistmember{Email: cell.ToAuthinfo().Email, Platform: cell.ToAuthinfo().Platform}
|
||||
if sh.wl.contains(wm.Key(), nil) {
|
||||
|
||||
wm := &whitelistmember{Email: authInfo.Email, Platform: authInfo.Platform}
|
||||
if _, ok := sh.wl.get(wm.Key()); ok {
|
||||
// qa 권한이면 입장 가능
|
||||
w.Write([]byte(fmt.Sprintf(`{"service":"%s"}`, div.Url)))
|
||||
addrresp = fmt.Sprintf(`{"service":"%s"}`, div.Url)
|
||||
//w.Write([]byte(fmt.Sprintf(`{"service":"%s"}`, div.Url)))
|
||||
} else if div.Maintenance != nil {
|
||||
// 권한이 없으므로 공지
|
||||
w.Write([]byte(fmt.Sprintf(`{"notice":"%s"}`, div.Maintenance.link)))
|
||||
addrresp = fmt.Sprintf(`{"notice":"%s"}`, div.Maintenance.link)
|
||||
//w.Write([]byte(fmt.Sprintf(`{"notice":"%s"}`, div.Maintenance.link)))
|
||||
} else {
|
||||
logger.Println("div.Maintenance is nil :", divname)
|
||||
}
|
||||
@ -824,13 +901,18 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request)
|
||||
case DivisionState_Maintenance:
|
||||
// 점검중. 아무도 못들어감
|
||||
if div.Maintenance != nil {
|
||||
w.Write([]byte(fmt.Sprintf(`{"notice":"%s"}`, div.Maintenance.link)))
|
||||
logger.Println("/addr :", divname, div.State, *div.Maintenance)
|
||||
addrresp = fmt.Sprintf(`{"notice":"%s"}`, div.Maintenance.link)
|
||||
//w.Write([]byte(fmt.Sprintf(`{"notice":"%s"}`, div.Maintenance.link)))
|
||||
} else {
|
||||
logger.Println("div.Maintenance is nil :", divname)
|
||||
}
|
||||
}
|
||||
logger.Println("/addr resp :", addrresp)
|
||||
w.Write([]byte(addrresp))
|
||||
} else {
|
||||
logger.Println("div is not found :", divname)
|
||||
logger.Println("div is not found :", divname, sh.Divisions)
|
||||
logger.Println("check maingate database 'service.divisions' :", config.Mongo)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -19,14 +18,6 @@ import (
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type authPipelineDocument struct {
|
||||
OperationType string `bson:"operationType"`
|
||||
DocumentKey struct {
|
||||
Id primitive.ObjectID `bson:"_id"`
|
||||
} `bson:"documentKey"`
|
||||
Authinfo *gocommon.Authinfo `bson:"fullDocument"`
|
||||
}
|
||||
|
||||
type servicePipelineDocument struct {
|
||||
OperationType string `bson:"operationType"`
|
||||
DocumentKey struct {
|
||||
@ -222,87 +213,3 @@ func (mg *Maingate) watchServiceCollection(parentctx context.Context, serveMux *
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func watchAuthCollection(parentctx context.Context, ac *gocommon.AuthCollection, mongoClient gocommon.MongoClient) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
if s != nil {
|
||||
logger.Error(s)
|
||||
}
|
||||
}()
|
||||
|
||||
matchStage := bson.D{
|
||||
{
|
||||
Key: "$match", Value: bson.D{
|
||||
{Key: "operationType", Value: bson.D{
|
||||
{Key: "$in", Value: bson.A{
|
||||
"delete",
|
||||
"insert",
|
||||
"update",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
}}
|
||||
projectStage := bson.D{
|
||||
{
|
||||
Key: "$project", Value: bson.D{
|
||||
{Key: "documentKey", Value: 1},
|
||||
{Key: "operationType", Value: 1},
|
||||
{Key: "fullDocument", Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var stream *mongo.ChangeStream
|
||||
var err error
|
||||
var ctx context.Context
|
||||
|
||||
for {
|
||||
if stream == nil {
|
||||
stream, err = mongoClient.Watch(CollectionAuth, mongo.Pipeline{matchStage, projectStage})
|
||||
if err != nil {
|
||||
logger.Error("watchAuthCollection watch failed :", err)
|
||||
time.Sleep(time.Minute)
|
||||
continue
|
||||
}
|
||||
ctx = context.TODO()
|
||||
}
|
||||
|
||||
changed := stream.TryNext(ctx)
|
||||
if ctx.Err() != nil {
|
||||
logger.Error("watchAuthCollection stream.TryNext failed. process should be restarted! :", ctx.Err().Error())
|
||||
break
|
||||
}
|
||||
|
||||
if changed {
|
||||
var data authPipelineDocument
|
||||
if err := stream.Decode(&data); err == nil {
|
||||
ot := data.OperationType
|
||||
switch ot {
|
||||
case "insert":
|
||||
ac.AddRaw(&mongoAuthCell{src: data.Authinfo})
|
||||
case "update":
|
||||
ac.AddRaw(&mongoAuthCell{src: data.Authinfo})
|
||||
case "delete":
|
||||
ac.RemoveByAccId(data.DocumentKey.Id)
|
||||
}
|
||||
} else {
|
||||
logger.Error("watchAuthCollection stream.Decode failed :", err)
|
||||
}
|
||||
} else if stream.Err() != nil || stream.ID() == 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
logger.Println("watchAuthCollection is done")
|
||||
stream.Close(ctx)
|
||||
return
|
||||
|
||||
case <-time.After(time.Second):
|
||||
logger.Error("watchAuthCollection stream error :", stream.Err())
|
||||
stream.Close(ctx)
|
||||
stream = nil
|
||||
}
|
||||
} else {
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
fba/track-event.html
Normal file
11
fba/track-event.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" src="./fb-ga.min.js">
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<!-- <body> -->
|
||||
<!-- <body onload="window.FBA.TrackLogEvent('DESKTOP-TEST');"> -->
|
||||
<!-- <script type="cjs" src="./fb-ga.rollup.js"> -->
|
||||
8
go.mod
8
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
go.mongodb.org/mongo-driver v1.11.7
|
||||
google.golang.org/api v0.128.0
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230825015501-e4527aa5b3ff
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20240201092859-c71a74762de7
|
||||
)
|
||||
|
||||
require (
|
||||
@ -42,7 +42,7 @@ require (
|
||||
golang.org/x/net v0.11.0 // indirect
|
||||
golang.org/x/oauth2 v0.9.0 // indirect
|
||||
golang.org/x/sync v0.3.0 // indirect
|
||||
golang.org/x/sys v0.9.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
golang.org/x/text v0.10.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||
@ -51,7 +51,5 @@ require (
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
|
||||
google.golang.org/grpc v1.56.0 // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
)
|
||||
|
||||
replace repositories.action2quare.com/ayo/maingate => ./
|
||||
|
||||
77
go.sum
77
go.sum
@ -2,24 +2,16 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.110.2 h1:sdFPBr6xG9/wkBbfhmUz/JmZC7X6LavQgcrVINrKiVA=
|
||||
cloud.google.com/go v0.110.2/go.mod h1:k04UEeEtb6ZBRTv3dZz4CeJC3jKGxyhl0sAiVVquxiw=
|
||||
cloud.google.com/go/compute v1.19.0 h1:+9zda3WGgW1ZSTlVppLCYFIr48Pa35q1uG2N1itbCEQ=
|
||||
cloud.google.com/go/compute v1.19.0/go.mod h1:rikpw2y+UMidAe9tISo04EHNOIf42RLYF/q8Bs93scU=
|
||||
cloud.google.com/go/compute v1.20.1 h1:6aKEtlUiwEpJzM001l0yFkpXmUVXaN8W+fbkb2AZNbg=
|
||||
cloud.google.com/go/compute v1.20.1/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM=
|
||||
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
|
||||
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
|
||||
cloud.google.com/go/firestore v1.10.0 h1:FG5C49ukKKqyljY+XNRZGae1HZaiVe7aoqi2BipnBuM=
|
||||
cloud.google.com/go/firestore v1.10.0/go.mod h1:eAeoQCV8F35Mcy4k8ZrQbcSYZOayIwoiU7ZJ6xzH1+o=
|
||||
cloud.google.com/go/iam v0.13.0 h1:+CmB+K0J/33d0zSQ9SlFWUeCCEn5XJA0ZMZ3pHE9u8k=
|
||||
cloud.google.com/go/iam v0.13.0/go.mod h1:ljOg+rcNfzZ5d6f1nAUJ8ZIxOaZUVoS14bKCtaLZ/D0=
|
||||
cloud.google.com/go/iam v1.1.1 h1:lW7fzj15aVIXYHREOqjRBV9PsH0Z6u8Y46a1YGvQP4Y=
|
||||
cloud.google.com/go/iam v1.1.1/go.mod h1:A5avdyVL2tCppe4unb0951eI9jreack+RJ0/d+KUZOU=
|
||||
cloud.google.com/go/longrunning v0.4.2 h1:WDKiiNXFTaQ6qz/G8FCOkuY9kJmOJGY67wPUC1M2RbE=
|
||||
cloud.google.com/go/longrunning v0.4.2/go.mod h1:OHrnaYyLUV6oqwh0xiS7e5sLQhP1m0QU9R+WhGDMgIQ=
|
||||
cloud.google.com/go/longrunning v0.5.1 h1:Fr7TXftcqTudoyRJa113hyaqlGdiBQkp0Gq7tErFDWI=
|
||||
cloud.google.com/go/longrunning v0.5.1/go.mod h1:spvimkwdz6SPWKEt/XBij79E9fiTkHSQl/fRUUQJYJc=
|
||||
cloud.google.com/go/storage v1.29.0 h1:6weCgzRvMg7lzuUurI4697AqIRPU1SvzHhynwpW31jI=
|
||||
cloud.google.com/go/storage v1.29.0/go.mod h1:4puEjyTKnku6gfKoTfNOU/W+a9JyuVNxjpS5GBrB8h4=
|
||||
cloud.google.com/go/storage v1.30.1 h1:uOdMxAs8HExqBlnLtnQyP0YkvbiDpdGShGKtx6U/oNM=
|
||||
cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7BiccwkR7+P7gN8E=
|
||||
firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4=
|
||||
@ -94,16 +86,11 @@ github.com/google/s2a-go v0.1.4/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkj
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.2.3 h1:yk9/cqRKtT9wXZSsRH9aurXEpJX+U6FLtpYTdC3R06k=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.2.5 h1:UR4rDjcgpgEnqpIEvkiqTYKBCKLNmlge2eVjoZfySzM=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.2.5/go.mod h1:RxW0N9901Cko1VOCW3SXCpWP+mlIEkk2tP7jnHy9a3w=
|
||||
github.com/googleapis/gax-go/v2 v2.8.0 h1:UBtEZqx1bjXtOQ5BVTkuYghXrr3N4V123VKJK67vJZc=
|
||||
github.com/googleapis/gax-go/v2 v2.8.0/go.mod h1:4orTrqY6hXxxaUL4LHIPl6lGo8vAE38/qKbhSAKP6QI=
|
||||
github.com/googleapis/gax-go/v2 v2.11.0 h1:9V9PWXEsWnPpQhu/PeQIkS4eGzMlTLGgt80cUUI8Ki4=
|
||||
github.com/googleapis/gax-go/v2 v2.11.0/go.mod h1:DxmR61SGKkGLa2xigwuZIQpkCI2S5iydzRfb3peWZJI=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk=
|
||||
github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
@ -112,7 +99,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
@ -141,21 +127,16 @@ github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E=
|
||||
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
||||
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
|
||||
github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
|
||||
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
|
||||
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
|
||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.mongodb.org/mongo-driver v1.11.6 h1:XM7G6PjiGAO5betLF13BIa5TlLUUE3uJ/2Ox3Lz1K+o=
|
||||
go.mongodb.org/mongo-driver v1.11.6/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY=
|
||||
go.mongodb.org/mongo-driver v1.11.7 h1:LIwYxASDLGUg/8wOhgOOZhX8tQa/9tgZPgzZoVqJvcs=
|
||||
go.mongodb.org/mongo-driver v1.11.7/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
@ -167,8 +148,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
|
||||
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
||||
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
|
||||
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
@ -189,14 +168,10 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
|
||||
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8=
|
||||
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
|
||||
golang.org/x/oauth2 v0.9.0 h1:BPpt2kU7oMRq3kCHAA1tbSEshXRw1LpG2ztgDwrzuAs=
|
||||
golang.org/x/oauth2 v0.9.0/go.mod h1:qYgFZaFiu6Wg24azG8bdV52QJXJGbZzIIsRCdVKzbLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@ -205,8 +180,6 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
|
||||
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@ -219,10 +192,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@ -231,8 +202,6 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||
@ -249,8 +218,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
|
||||
google.golang.org/api v0.123.0 h1:yHVU//vA+qkOhm4reEC9LtzHVUCN/IqqNRl1iQ9xE20=
|
||||
google.golang.org/api v0.123.0/go.mod h1:gcitW0lvnyWjSp9nKxAbdHKIZ6vF4aajGueeslZOyms=
|
||||
google.golang.org/api v0.128.0 h1:RjPESny5CnQRn9V6siglged+DZCgfu9l6mO9dkX9VOg=
|
||||
google.golang.org/api v0.128.0/go.mod h1:Y611qgqaE92On/7g65MQgxYul3c0rEB894kniWLY750=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
@ -261,8 +228,6 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
|
||||
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc h1:8DyZCyvI8mE1IdLy/60bS+52xfymkE72wv1asokgtao=
|
||||
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:xZnkP7mREFX5MORlOPEzLMr+90PPZQ2QWzrVTWfAq64=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc h1:kVKPf/IiYSBWEWtkIn6wZXwWGCnLKcC8oWfZvXjsGnM=
|
||||
@ -277,8 +242,6 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
|
||||
google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag=
|
||||
google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8=
|
||||
google.golang.org/grpc v1.56.0 h1:+y7Bs8rtMd07LeXmL3NxcTLn7mUkbKZqEpPhMNkwJEE=
|
||||
google.golang.org/grpc v1.56.0/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
@ -292,8 +255,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
@ -305,33 +268,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230612013915-5950ff4bb82e h1:m0jo1r+2NtBfxwj92e6EVaBZpzTDT6Hq7D93vWO4h9Y=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230612013915-5950ff4bb82e/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230614091557-9b877d9a732c h1:fhCuu0jFps8T1sN8hO0fGnatvNDW6VwM96PV26EA3T4=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230614091557-9b877d9a732c/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230616031450-0b2c9351a717 h1:WrkkEWN3bh1QAulNJZjAiwXx2aPAj39OoIyJFUXmDaE=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230616031450-0b2c9351a717/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230616032216-378bc19f3742 h1:qEbzwVDz1w2ewNHu+vipzV+a804wmwRWe+0vnhCbJr4=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230616032216-378bc19f3742/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230620005911-15ba3e93d621 h1:9Hzdn13l9U0RJn9mMXsZQr+jsmsgy3zQFsBHPSOJnxM=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230620005911-15ba3e93d621/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230621051330-0d8752e66161 h1:sgixcFwdLOqcvwqTaKcsMEepXsLmNEgaybyur3QHRgk=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230621051330-0d8752e66161/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230621052811-06ef97f11d22 h1:DImSGNxZrc+Q4WlS1OKMsLAScEfDYLX4XMJdjAaVnXc=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230621052811-06ef97f11d22/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710081612-3024a17b540f h1:MMA/6fqn76zSOkUQzG8v+IbWvrtY1mXN5xF1WOZonVc=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710081612-3024a17b540f/go.mod h1:rn6NA28Mej+qgLNx/Bu2wsdGyIycmacqlNP6gUXX2a0=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710084625-dd05ebf6ceb9 h1:dizJeTf3xt7wEeq72sYqlgdy7an8kezA6JuqALKPCBQ=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710084625-dd05ebf6ceb9/go.mod h1:rn6NA28Mej+qgLNx/Bu2wsdGyIycmacqlNP6gUXX2a0=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710085335-ead6543d95f9 h1:zJ+33DKEA6CObPii5c5l5IbUIws31+Ni5NzzC3oYRLw=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710085335-ead6543d95f9/go.mod h1:rn6NA28Mej+qgLNx/Bu2wsdGyIycmacqlNP6gUXX2a0=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710085810-8173216e9574 h1:Ha0d/sv/MzC3ASCTXfe2tAFJieLNJmTCBL8aETEOY14=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710085810-8173216e9574/go.mod h1:rn6NA28Mej+qgLNx/Bu2wsdGyIycmacqlNP6gUXX2a0=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b h1:yV1cBeu0GFxkDD6TDxzKv/rM3OMtyt1JXpeqDF5IO3Y=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230823084014-c34045e215fc h1:/nFKyjpcfMCdC7vrEZ7+IQOA5RoMmcBUHNRl40JN3ys=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230823084014-c34045e215fc/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230823134414-400c7f644333 h1:3QWHeK6eX1yhaeN/Lu88N4B2ORb/PdBkXUS+HzFOWgU=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230823134414-400c7f644333/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230825015501-e4527aa5b3ff h1:nTOqgPSfm0EANR1SFAi+Zi/KErAAlstVcEWWOnyDT5g=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230825015501-e4527aa5b3ff/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20240201092859-c71a74762de7 h1:ikDwKNiRXJlIBueAVmp9p2To+lRN9zTzGSvVHCXgFnI=
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20240201092859-c71a74762de7/go.mod h1:Gb418rT96M3K7L/XMPzp8IJj4UXVunq7dZzrxsMBz/8=
|
||||
|
||||
15
main.go
15
main.go
@ -2,9 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||
@ -21,26 +19,29 @@ func main() {
|
||||
flagx.Parse()
|
||||
|
||||
logger.Println("build revision =", revision)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
mg, err := core.New(ctx)
|
||||
if err != nil {
|
||||
logger.Error("core.New failed :", err)
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
defer mg.Destructor()
|
||||
|
||||
serveMux := http.NewServeMux()
|
||||
if err := mg.RegisterHandlers(ctx, serveMux, *prefix); err != nil {
|
||||
logger.Error("RegisterHandlers failed :", err)
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
|
||||
server := gocommon.NewHTTPServer(serveMux)
|
||||
logger.Println("maingate is started")
|
||||
|
||||
if err := server.Start(); err != nil {
|
||||
logger.Error("maingate is stopped with error :", err)
|
||||
}
|
||||
cancel()
|
||||
mg.Destructor()
|
||||
|
||||
logger.Println("maingate is terminated")
|
||||
}
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
# $ErrorActionPreference = 'SilentlyContinue'
|
||||
|
||||
$CurBranch = git branch --show-current
|
||||
|
||||
Remove-Item maingate.zip -Force -Recurse -ErrorAction SilentlyContinue
|
||||
|
||||
$Env:GOOS="linux"
|
||||
$Env:GOARCH="amd64"
|
||||
go build -ldflags="-s -w" .
|
||||
|
||||
Compress-Archive -Path maingate -Update -DestinationPath maingate.zip
|
||||
Compress-Archive -Path *-firebase-*.json -Update -DestinationPath maingate.zip
|
||||
1
template/fb-ga.min.js
vendored
Normal file
1
template/fb-ga.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user