to_upstream #1

Closed
mountain wants to merge 12 commits from ws:to_upstream into master
6 changed files with 282 additions and 21 deletions
Showing only changes of commit 0c744d634d - Show all commits

View File

@ -387,6 +387,58 @@ func (caller apiCaller) couponAPI(w http.ResponseWriter, r *http.Request) error
return nil return nil
} }
type accountlinkinfo struct {
Uid string `json:"uid"`
Platform string `json:"platform"`
}
func (caller apiCaller) userinfoAPI(w http.ResponseWriter, r *http.Request) error {
mg := caller.mg
if r.Method == "GET" {
// 계정 조회
accid, _ := gocommon.ReadObjectIDFormValue(r.Form, "accid")
if len(accid) == 0 {
logger.Println("[userinfoAPI] accid is empty")
w.WriteHeader(http.StatusBadRequest)
return nil
}
all, err := mg.mongoClient.FindAll(CollectionAccount, bson.M{
"accid": accid,
}, options.Find().SetProjection(bson.M{"_id": 1, "accid": 1}))
if err != nil {
return err
}
var linkinfos []accountlinkinfo
for _, doc := range all {
id := doc["_id"].(primitive.ObjectID)
link, err := mg.mongoClient.FindOne(CollectionLink, bson.M{
"_id": id,
}, options.FindOne().SetProjection(bson.M{"_id": 1, "platform": 1, "uid": 1}))
if err != nil {
logger.Error("link failed. FindOneAndUpdate link err:", err)
w.WriteHeader(http.StatusInternalServerError)
return err
}
var info accountlinkinfo
info.Platform = link["platform"].(string)
info.Uid = link["uid"].(string)
linkinfos = append(linkinfos, info)
}
enc := json.NewEncoder(w)
enc.Encode(linkinfos)
}
return nil
}
var errApiTokenMissing = errors.New("mg-x-api-token is missing") var errApiTokenMissing = errors.New("mg-x-api-token is missing")
func (caller apiCaller) configAPI(w http.ResponseWriter, r *http.Request) error { func (caller apiCaller) configAPI(w http.ResponseWriter, r *http.Request) error {
@ -513,6 +565,8 @@ func (mg *Maingate) api(w http.ResponseWriter, r *http.Request) {
err = caller.blockAPI(w, r) err = caller.blockAPI(w, r)
} else if strings.HasSuffix(r.URL.Path, "/coupon") { } else if strings.HasSuffix(r.URL.Path, "/coupon") {
err = caller.couponAPI(w, r) err = caller.couponAPI(w, r)
} else if strings.HasSuffix(r.URL.Path, "/userinfo") {
err = caller.userinfoAPI(w, r)
} }
if err != nil { if err != nil {