ServiceCode제거

This commit is contained in:
2024-03-29 09:06:38 +09:00
parent e38e8a91e5
commit eace5933a1
3 changed files with 9 additions and 34 deletions

View File

@ -286,9 +286,7 @@ func (caller apiCaller) serviceAPI(w http.ResponseWriter, r *http.Request) error
if mg.service().Id.IsZero() {
logger.Println(" id is zero")
newService := serviceDescription{
ServiceDescriptionSummary: ServiceDescriptionSummary{
Id: primitive.NewObjectID(),
},
Id: primitive.NewObjectID(),
}
if err := newService.prepare(caller.mg); err != nil {
logger.Println(" prepare failed :", err)

View File

@ -411,9 +411,7 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
atomic.StorePointer(&mg.serviceptr, unsafe.Pointer(only))
} else {
empty := serviceDescription{
ServiceDescriptionSummary: ServiceDescriptionSummary{
Id: primitive.NewObjectID(),
},
Id: primitive.NewObjectID(),
}
if *devflag {
@ -455,14 +453,13 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
}
}
logger.Println("Service is registered :", mg.service().ServiceCode)
if *devflag {
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, mg.service().ServiceCode, "/"), func(w http.ResponseWriter, r *http.Request) {
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "/"), 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) {
serveMux.HandleFunc(gocommon.MakeHttpHandlerPattern(prefix, "/"), func(w http.ResponseWriter, r *http.Request) {
// mg.service()를 요청마다 불러야 함
mg.service().serveHTTP(w, r)
})

View File

@ -2,7 +2,6 @@ package core
import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
@ -93,17 +92,12 @@ type Division struct {
Url string `bson:"url" json:"url"`
}
type ServiceDescriptionSummary struct {
Id primitive.ObjectID `bson:"_id" json:"_id"`
ServiceCode string `bson:"code" json:"code"`
}
type serviceDescription struct {
ServiceDescriptionSummary `bson:",inline" json:",inline"`
Divisions map[string]*Division `bson:"divisions" json:"divisions"`
ServerApiTokens []primitive.ObjectID `bson:"api_tokens" json:"api_tokens"`
MaximumNumLinkAccount int64
VersionSplits map[string]string `bson:"version_splits" json:"version_splits"`
Id primitive.ObjectID `bson:"_id" json:"_id"`
Divisions map[string]*Division `bson:"divisions" json:"divisions"`
ServerApiTokens []primitive.ObjectID `bson:"api_tokens" json:"api_tokens"`
MaximumNumLinkAccount int64
VersionSplits map[string]string `bson:"version_splits" json:"version_splits"`
sessionProvider session.Provider
wl *memberContainerPtr[string, *whitelistmember]
@ -111,7 +105,6 @@ type serviceDescription struct {
mongoClient gocommon.MongoClient
sessionTTL time.Duration
serviceCodeBytes []byte
getUserBrowserInfo func(r *http.Request) (string, error)
getUserTokenWithCheck func(platform string, userid string, brinfo string) (usertokeninfo, error)
updateUserinfo func(info usertokeninfo) (bool, string, string)
@ -173,13 +166,6 @@ func (sh *serviceDescription) readProfile(authtype string, id string, binfo stri
func (sh *serviceDescription) prepare(mg *Maingate) error {
divs := sh.Divisions
if len(sh.ServiceCode) == 0 {
sh.ServiceCode = hex.EncodeToString(sh.Id[6:])
}
if *noauth {
sh.ServiceCode = "000000000000"
}
divsForUsers := make(map[string]*DivisionForUser)
defaultDivNames := make(map[string]bool)
@ -250,7 +236,6 @@ func (sh *serviceDescription) prepare(mg *Maingate) error {
sh.mongoClient = mg.mongoClient
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
@ -276,8 +261,6 @@ func (sh *serviceDescription) prepare(mg *Maingate) error {
sh.bl = &mg.bl
sh.serviceSerialized, _ = json.Marshal(sh)
logger.Println("service is ready :", sh.ServiceCode, string(sh.serviceSerialized))
return nil
}
@ -711,9 +694,6 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
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{