bson, json 소문자로 변경
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@ -22,9 +23,9 @@ import (
|
||||
)
|
||||
|
||||
type blockinfo struct {
|
||||
Start primitive.DateTime
|
||||
Start primitive.DateTime `bson:"start" json:"start"`
|
||||
End primitive.DateTime `bson:"_ts"`
|
||||
Reason string
|
||||
Reason string `bson:"reason" json:"reason"`
|
||||
}
|
||||
|
||||
type whitelistAuthType = string
|
||||
@ -35,12 +36,12 @@ const (
|
||||
)
|
||||
|
||||
type whitelistmember struct {
|
||||
Service string
|
||||
Email string
|
||||
Platform string
|
||||
Desc string
|
||||
Auth []whitelistAuthType
|
||||
Expired primitive.DateTime `bson:"_ts,omitempty" json:"_ts,omitempty"`
|
||||
Service string `bson:"service" json:"service"`
|
||||
Email string `bson:"email" json:"email"`
|
||||
Platform string `bson:"platform" json:"platform"`
|
||||
Desc string `bson:"desc" json:"desc"`
|
||||
Auth []whitelistAuthType `bson:"auth" json:"auth"`
|
||||
Expired primitive.DateTime `bson:"_ts,omitempty" json:"_ts,omitempty"`
|
||||
}
|
||||
|
||||
type whitelist struct {
|
||||
@ -165,26 +166,30 @@ type Maintenance struct {
|
||||
link string
|
||||
}
|
||||
|
||||
type DivisionForUser struct {
|
||||
Priority int `bson:"priority" json:"priority"`
|
||||
State DivisionStateName `bson:"state" json:"state"`
|
||||
Maintenance *Maintenance `bson:",omitempty" json:",omitempty"`
|
||||
}
|
||||
|
||||
type Division struct {
|
||||
Url string // 요것은 클라이언트 빌드하고 나서 json:"-"으로 변경하자. 클라이언트에 직접 내려보내지 않음
|
||||
Priority int
|
||||
State DivisionStateName
|
||||
Maintenance *Maintenance `bson:",omitempty" json:",omitempty"`
|
||||
DivisionForUser `bson:",inline" json:",inline"`
|
||||
Url string `bson:"url" json:"url"`
|
||||
}
|
||||
|
||||
type ServiceDescriptionSummary struct {
|
||||
Id primitive.ObjectID `bson:"_id"`
|
||||
ServiceName string `bson:"service"`
|
||||
ServiceCode string `bson:"code"`
|
||||
UseWhitelist bool `bson:"use_whitelist"`
|
||||
Closed bool `bson:"closed"`
|
||||
Id primitive.ObjectID `bson:"_id" json:"_id"`
|
||||
ServiceName string `bson:"service" json:"service"`
|
||||
ServiceCode string `bson:"code" json:"code"`
|
||||
UseWhitelist bool `bson:"use_whitelist" json:"use_whitelist"`
|
||||
Closed bool `bson:"closed" json:"closed"`
|
||||
}
|
||||
|
||||
type serviceDescription struct {
|
||||
ServiceDescriptionSummary `bson:",inline"`
|
||||
Divisions map[string]*Division `bson:"divisions"`
|
||||
ServerApiTokens []primitive.ObjectID `bson:"api_tokens"`
|
||||
ApiUsers map[string][]string `bson:"api_users"`
|
||||
ServiceDescriptionSummary `bson:",inline" json:",inline"`
|
||||
Divisions map[string]*Division `bson:"divisions" json:"divisions"`
|
||||
ServerApiTokens []primitive.ObjectID `bson:"api_tokens" json:"api_tokens"`
|
||||
ApiUsers map[string][]string `bson:"api_users" json:"api_users"`
|
||||
|
||||
auths *common.AuthCollection
|
||||
wl whitelist
|
||||
@ -197,10 +202,11 @@ type serviceDescription struct {
|
||||
updateUserinfo func(info usertokeninfo) (bool, string, string)
|
||||
getProviderInfo func(platform string, uid string) (string, string, error)
|
||||
|
||||
apiUsers unsafe.Pointer
|
||||
divisionsSerialized unsafe.Pointer
|
||||
serviceSerialized unsafe.Pointer
|
||||
serviceSummarySerialized unsafe.Pointer
|
||||
apiUsers unsafe.Pointer
|
||||
divisionsForUsersSerialized unsafe.Pointer
|
||||
divisionsSerialized unsafe.Pointer
|
||||
serviceSerialized unsafe.Pointer
|
||||
serviceSummarySerialized unsafe.Pointer
|
||||
}
|
||||
|
||||
func (sh *serviceDescription) readProfile(authtype string, id string, binfo string) (email string, err error) {
|
||||
@ -240,13 +246,13 @@ func (sh *serviceDescription) prepare(mg *Maingate) error {
|
||||
sh.ServiceCode = hex.EncodeToString(sh.Id[6:])
|
||||
}
|
||||
|
||||
var closed []string
|
||||
divsForUsers := make(map[string]*DivisionForUser)
|
||||
for dn, div := range divs {
|
||||
if div.State == DivisionState_Closed {
|
||||
closed = append(closed, dn)
|
||||
continue
|
||||
}
|
||||
|
||||
divsForUsers[dn] = &div.DivisionForUser
|
||||
if len(div.State) == 0 {
|
||||
div.State = DivisionState_FullOpen
|
||||
}
|
||||
@ -262,7 +268,11 @@ func (sh *serviceDescription) prepare(mg *Maingate) error {
|
||||
} else if strings.HasPrefix(div.Maintenance.Notice, "http") {
|
||||
div.Maintenance.link = div.Maintenance.Notice
|
||||
} else {
|
||||
div.Maintenance.link = path.Join("static", sh.ServiceCode, div.Maintenance.Notice)
|
||||
hasher := md5.New()
|
||||
hasher.Write([]byte(sh.ServiceName))
|
||||
subfolder := hex.EncodeToString(hasher.Sum(nil))[:8]
|
||||
|
||||
div.Maintenance.link = path.Join("static", subfolder, div.Maintenance.Notice)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -270,14 +280,14 @@ func (sh *serviceDescription) prepare(mg *Maingate) error {
|
||||
}
|
||||
}
|
||||
|
||||
for _, dn := range closed {
|
||||
delete(divs, dn)
|
||||
}
|
||||
|
||||
divmarshaled, _ := json.Marshal(divs)
|
||||
devstr := string(divmarshaled)
|
||||
sh.divisionsSerialized = unsafe.Pointer(&devstr)
|
||||
|
||||
divmarshaled2, _ := json.Marshal(divsForUsers)
|
||||
devstr2 := string(divmarshaled2)
|
||||
sh.divisionsForUsersSerialized = unsafe.Pointer(&devstr2)
|
||||
|
||||
sh.mongoClient = mg.mongoClient
|
||||
sh.auths = mg.auths
|
||||
sh.sessionTTL = time.Duration(mg.SessionTTL * int64(time.Second))
|
||||
@ -764,7 +774,7 @@ func (sh *serviceDescription) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
divstrptr := atomic.LoadPointer(&sh.divisionsSerialized)
|
||||
divstrptr := atomic.LoadPointer(&sh.divisionsForUsersSerialized)
|
||||
divstr := *(*string)(divstrptr)
|
||||
w.Write([]byte(divstr))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user