6 changed files with 21 additions and 71 deletions
-
60core/cloud/api.go
-
12core/cloud/commCloud/api.go
-
12core/cloud/userCloud/api.go
-
2go.mod
-
2go.sum
-
4webs/sys/main.go
@ -1,60 +0,0 @@ |
|||
package cloud |
|||
|
|||
import ( |
|||
"fmt" |
|||
hbtp "github.com/mgr9525/HyperByte-Transfer-Protocol" |
|||
gocloud "github.com/mgr9525/go-cloud" |
|||
"time" |
|||
) |
|||
|
|||
func NewReq(code int, method string, ipr ...string) (*hbtp.Request, error) { |
|||
host := fmt.Sprintf("%v", gocloud.CloudConf.Custom["sysHbtpHost"]) |
|||
req, err := hbtp.NewRPCReq(host, code, method) |
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
hd := req.ReqHeader() |
|||
if len(ipr) > 0 { |
|||
hd.RelIp = ipr[1] |
|||
} |
|||
hd.Times = time.Now().Format(time.RFC3339Nano) |
|||
//hd.Token = ruisUtil.Md5String(hd.Path + hd.RelIp + hd.Times + HbtpMD5Token)
|
|||
return req, err |
|||
} |
|||
func DoJson(code int, method string, in, out interface{}, hd ...map[string]interface{}) error { |
|||
req, err := NewReq(code, method) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
defer req.Close() |
|||
if len(hd) > 0 && hd[0] != nil { |
|||
for k, v := range hd[0] { |
|||
req.ReqHeader().Set(k, v) |
|||
} |
|||
} |
|||
err = req.Do(in) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
if req.ResCode() != hbtp.ResStatusOk { |
|||
return fmt.Errorf("res err(%d):%s", req.ResCode(), string(req.ResBodyBytes())) |
|||
} |
|||
return req.ResBodyJson(out) |
|||
} |
|||
func DoString(code int, method string, in interface{}, hd ...hbtp.Mp) (int, []byte, error) { |
|||
req, err := NewReq(code, method) |
|||
if err != nil { |
|||
return 0, nil, err |
|||
} |
|||
defer req.Close() |
|||
if len(hd) > 0 && hd[0] != nil { |
|||
for k, v := range hd[0] { |
|||
req.ReqHeader().Set(k, v) |
|||
} |
|||
} |
|||
err = req.Do(in) |
|||
if err != nil { |
|||
return 0, nil, err |
|||
} |
|||
return req.ResCode(), req.ResBodyBytes(), nil |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue