package siterpc import ( "encoding/json" "log" "strconv" "time" "git.tetele.net/tgo/conf" "git.tetele.net/tgo/crypter" "github.com/golang/protobuf/proto" ) type SiteInfoReq struct { Master string Host string } type SiteInfoRes struct { SiteId string `json:"site_id"` Dbname string `json:"database"` Domainname string `json:"domainname"` } /** * 由host取对应站点关键信息 * 请求及回均加密验签 * 2021/06/24 * GZ */ func GetSiteInfoByHost(host string, params ...string) (*SiteInfoRes, error) { var res_arr SiteInfoRes if conf.IS_PRIVATE { res_arr.Dbname = conf.DBNAME res_arr.SiteId = conf.SITE_ID res_arr.Domainname = conf.DOMAIN return &res_arr, nil } var url string = "" var master string = "" if len(params) > 1 { master = params[1] } if len(params) > 0 { url = params[0] } conn, err := rpc_server_conn(url) if err != nil { return nil, err } defer conn.Close() arg := SiteInfoReq{master, host} data_json, err := json.Marshal(arg) if err != nil { return nil, err } now_int64 := time.Now().Unix() encryData := crypter.DesEn(string(data_json), DES_KEY) now := strconv.FormatInt(now_int64, 10) sign := Sign(encryData, now) req := &Request{proto.String(encryData), proto.String(now), proto.String(sign), nil} res := &Response{} err = conn.GetSiteInfoByHost(req, res) if err != nil { return nil, err } res_data, err := GetOrgData(res) log.Println(res_data, err) if err != nil { return nil, err } err = json.Unmarshal([]byte(res_data), &res_arr) if err != nil { return nil, err } return &res_arr, nil }