From bdae4eeb485dad1a56e5f267dad73b1bab8fbed7 Mon Sep 17 00:00:00 2001 From: mountain Date: Sat, 20 Jul 2024 12:26:51 +0900 Subject: [PATCH] =?UTF-8?q?url=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/maingate.go | 4 +++- core/service.go | 29 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/core/maingate.go b/core/maingate.go index 784d4fe..3294202 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -469,7 +469,9 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu State: DivisionState_FullOpen, }, - Url: fmt.Sprintf("http://%s:%d/warehouse", ipaddr, *portptr), + Urls: bson.M{ + "warehouse": fmt.Sprintf("http://%s:%d/warehouse", ipaddr, *portptr), + }, }, } } diff --git a/core/service.go b/core/service.go index c9b4647..41a6cfa 100644 --- a/core/service.go +++ b/core/service.go @@ -91,7 +91,9 @@ type DivisionForUser struct { type Division struct { DivisionForUser `bson:",inline" json:",inline"` - Url string `bson:"url" json:"url"` + Url_Deprecated string `bson:"url" json:"url"` + Urls bson.M `bson:"urls" json:"urls"` + urlsSerialized []byte } type serviceDescription struct { @@ -177,6 +179,14 @@ func (sh *serviceDescription) prepare(mg *Maingate) error { defaultDivNames[dn] = true } + if len(div.Url_Deprecated) > 0 && len(div.Urls) == 0 { + div.Urls = bson.M{"warehouse": div.Url_Deprecated} + } + + div.urlsSerialized, _ = json.Marshal(bson.M{ + "service": div.Urls, + }) + divsForUsers[dn] = &div.DivisionForUser if len(div.State) == 0 { div.State = DivisionState_FullOpen @@ -1014,14 +1024,13 @@ 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 + var addrresp []byte if div != nil { logger.Println("/addr :", divname, div.State) switch div.State { case DivisionState_FullOpen: - addrresp = fmt.Sprintf(`{"service":"%s"}`, div.Url) - //w.Write([]byte(fmt.Sprintf(`{"service":"%s"}`, div.Url))) + addrresp = div.urlsSerialized case DivisionState_RestrictedOpen: // 점검중이면 whitelist만 입장 가능 @@ -1035,12 +1044,9 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request) wm := &whitelistmember{Email: authInfo.Email, Platform: authInfo.Platform} if _, ok := sh.wl.get(wm.Key()); ok { // qa 권한이면 입장 가능 - addrresp = fmt.Sprintf(`{"service":"%s"}`, div.Url) - //w.Write([]byte(fmt.Sprintf(`{"service":"%s"}`, div.Url))) + addrresp = div.urlsSerialized } else if div.Maintenance != nil { // 권한이 없으므로 공지 - 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) } @@ -1049,14 +1055,13 @@ func (sh *serviceDescription) serveHTTP(w http.ResponseWriter, r *http.Request) // 점검중. 아무도 못들어감 if div.Maintenance != nil { 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))) + addrresp = []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)) + logger.Println("/addr resp :", string(addrresp)) + w.Write(addrresp) } else { logger.Println("div is not found :", divname, sh.Divisions) logger.Println("check maingate database 'service.divisions' :", config.Mongo)