Compare commits
3 Commits
84ab8949ec
...
40a5b4e878
| Author | SHA1 | Date | |
|---|---|---|---|
| 40a5b4e878 | |||
| 50536caa00 | |||
| bf12ba76b6 |
@ -220,6 +220,18 @@ func (sl *servicelist) add(s *serviceDescription) {
|
||||
atomic.StorePointer(&sl.services, unsafe.Pointer(&next))
|
||||
}
|
||||
|
||||
func (sl *servicelist) getByCode(code string) *serviceDescription {
|
||||
ptr := atomic.LoadPointer(&sl.services)
|
||||
src := *(*map[string]*serviceDescription)(ptr)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ServiceCode == code {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sl *servicelist) get(sn any) *serviceDescription {
|
||||
ptr := atomic.LoadPointer(&sl.services)
|
||||
src := *(*map[string]*serviceDescription)(ptr)
|
||||
@ -553,7 +565,6 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
}
|
||||
|
||||
logger.Println("RegisterHandlers...")
|
||||
|
||||
mg.services.init(allServices)
|
||||
for _, service := range allServices {
|
||||
if service.Closed {
|
||||
@ -564,11 +575,23 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
serveMux.Handle(common.MakeHttpHandlerPattern(prefix, service.ServiceCode, "/"), service)
|
||||
}
|
||||
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "api", "/"), mg.api)
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "query", "/"), mg.query)
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "api/"), mg.api)
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "query/"), mg.query)
|
||||
|
||||
configraw, _ := json.Marshal(mg.maingateConfig)
|
||||
var convertedConfig map[string]any
|
||||
if err := json.Unmarshal(configraw, &convertedConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "config"), func(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
s := recover()
|
||||
if s != nil {
|
||||
logger.Error(s)
|
||||
}
|
||||
}()
|
||||
|
||||
apitoken := r.Header.Get("MG-X-API-TOKEN")
|
||||
if len(apitoken) == 0 {
|
||||
logger.Println("MG-X-API-TOKEN is missing")
|
||||
@ -576,14 +599,18 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
return
|
||||
}
|
||||
|
||||
_, exists := mg.apiTokenToService.get(apitoken)
|
||||
code, exists := mg.apiTokenToService.get(apitoken)
|
||||
if !exists {
|
||||
logger.Println("MG-X-API-TOKEN is invalid :", apitoken)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(configraw)
|
||||
service := mg.services.getByCode(code)
|
||||
convertedConfig["divisions"] = service.Divisions
|
||||
|
||||
enc := json.NewEncoder(w)
|
||||
enc.Encode(convertedConfig)
|
||||
})
|
||||
|
||||
if err := os.MkdirAll("static", os.ModePerm); err != nil {
|
||||
@ -592,10 +619,10 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
}
|
||||
|
||||
fsx := http.FileServer(http.Dir("./console"))
|
||||
serveMux.Handle(common.MakeHttpHandlerPattern(prefix, "console", "/"), http.StripPrefix("/console/", fsx))
|
||||
serveMux.Handle(common.MakeHttpHandlerPattern(prefix, "console/"), http.StripPrefix("/console/", fsx))
|
||||
|
||||
ssx := http.FileServer(http.Dir("./static"))
|
||||
serveMux.Handle(common.MakeHttpHandlerPattern(prefix, "static", "/"), http.StripPrefix("/static/", ssx))
|
||||
serveMux.Handle(common.MakeHttpHandlerPattern(prefix, "static/"), http.StripPrefix("/static/", ssx))
|
||||
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformGoogle), mg.platform_google_get_login_url)
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformGoogle), mg.platform_google_authorize)
|
||||
|
||||
@ -289,7 +289,7 @@ func (mg *Maingate) platform_apple_getuserinfo(refreshToken string) (bool, strin
|
||||
}
|
||||
|
||||
if respReferesh.Error != "" {
|
||||
logger.Error("apple returned an error: %s - %s\n", respReferesh.Error, respReferesh.ErrorDescription)
|
||||
logger.Errorf("apple returned an error: %s - %s\n", respReferesh.Error, respReferesh.ErrorDescription)
|
||||
return false, "", ""
|
||||
}
|
||||
|
||||
|
||||
@ -263,7 +263,7 @@ func (mg *Maingate) platform_gamepot_authorize_raw(w http.ResponseWriter, brinfo
|
||||
// fmt.Println("==============================")
|
||||
|
||||
if respLoginCheck.Status != 0 {
|
||||
logger.Errorf("gamepot login fail:", respLoginCheck.Message)
|
||||
logger.Error("gamepot login fail:", respLoginCheck.Message)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return false, ""
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
go.mongodb.org/mongo-driver v1.11.6
|
||||
google.golang.org/api v0.123.0
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230614091557-9b877d9a732c
|
||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230616032216-378bc19f3742
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
4
go.sum
4
go.sum
@ -262,3 +262,7 @@ repositories.action2quare.com/ayo/gocommon v0.0.0-20230612013915-5950ff4bb82e h1
|
||||
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=
|
||||
|
||||
Reference in New Issue
Block a user