diff --git a/core/cloud/commCloud/api.go b/core/cloud/commCloud/api.go index 90a0144..cfe773f 100644 --- a/core/cloud/commCloud/api.go +++ b/core/cloud/commCloud/api.go @@ -4,27 +4,25 @@ import ( "fmt" hbtp "github.com/mgr9525/HyperByte-Transfer-Protocol" gocloud "github.com/mgr9525/go-cloud" + "net/url" + "time" ) const ( RPCHostCode = 1 ) -func NewReq(method string, ipr string) (*hbtp.Request, error) { +func NewReq(cmds string, iprs string, tmots ...time.Duration) *hbtp.Request { host := fmt.Sprintf("%v", gocloud.CloudConf.Custom["sysHbtpHost"]) - return hbtp.NewDoRPCReq(host, RPCHostCode, method, ipr, nil) + pars := url.Values{} + pars.Set("iprs", iprs) + return hbtp.NewRequest(host, RPCHostCode, tmots...).Command(cmds).Args(pars) } -func DoJson(method string, in, out interface{}, hd ...map[string]interface{}) error { - req, err := NewReq(method, "") - if err != nil { - return err - } +func DoJson(cmds string, in, out interface{}, hd ...hbtp.Map) error { + req := NewReq(cmds, "") return hbtp.DoJson(req, in, out, hd...) } -func DoString(method string, in interface{}, hd ...hbtp.Mp) (int, []byte, error) { - req, err := NewReq(method, "") - if err != nil { - return 0, nil, err - } +func DoString(cmds string, in interface{}, hd ...hbtp.Map) (int32, []byte, error) { + req := NewReq(cmds, "") return hbtp.DoString(req, in, hd...) } diff --git a/core/cloud/userCloud/api.go b/core/cloud/userCloud/api.go index 8e3eca7..a5f6f5c 100644 --- a/core/cloud/userCloud/api.go +++ b/core/cloud/userCloud/api.go @@ -4,27 +4,25 @@ import ( "fmt" hbtp "github.com/mgr9525/HyperByte-Transfer-Protocol" gocloud "github.com/mgr9525/go-cloud" + "net/url" + "time" ) const ( RPCHostCode = 2 ) -func NewReq(method string, ipr string) (*hbtp.Request, error) { +func NewReq(cmds string, iprs string, tmots ...time.Duration) *hbtp.Request { host := fmt.Sprintf("%v", gocloud.CloudConf.Custom["sysHbtpHost"]) - return hbtp.NewDoRPCReq(host, RPCHostCode, method, ipr, nil) + pars := url.Values{} + pars.Set("iprs", iprs) + return hbtp.NewRequest(host, RPCHostCode, tmots...).Command(cmds).Args(pars) } -func DoJson(method string, in, out interface{}, hd ...map[string]interface{}) error { - req, err := NewReq(method, "") - if err != nil { - return err - } +func DoJson(cmds string, in, out interface{}, hd ...hbtp.Map) error { + req := NewReq(cmds, "") return hbtp.DoJson(req, in, out, hd...) } -func DoString(method string, in interface{}, hd ...hbtp.Mp) (int, []byte, error) { - req, err := NewReq(method, "") - if err != nil { - return 0, nil, err - } +func DoString(cmds string, in interface{}, hd ...hbtp.Map) (int32, []byte, error) { + req := NewReq(cmds, "") return hbtp.DoString(req, in, hd...) } diff --git a/go.mod b/go.mod index b67924d..f80fce3 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/gin-gonic/gin v1.7.1 github.com/go-sql-driver/mysql v1.5.0 - github.com/mgr9525/HyperByte-Transfer-Protocol v0.0.0-20210428085206-8dfaf346081f + github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20210721160012-eb78dcc77894 github.com/mgr9525/go-cloud v1.0.6-0.20210501052806-55406cd08e82 github.com/mgr9525/go-ruisutil v1.0.8-0.20210317093428-f69295935056 github.com/qiniu/qmgo v0.9.2 diff --git a/go.sum b/go.sum index 9155053..42fe700 100644 --- a/go.sum +++ b/go.sum @@ -97,8 +97,8 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= -github.com/mgr9525/HyperByte-Transfer-Protocol v0.0.0-20210428085206-8dfaf346081f h1:LWtr7NrrPqDUAU4Z4MJFHkLpVUSidZwZ/Oo2h+JYEDw= -github.com/mgr9525/HyperByte-Transfer-Protocol v0.0.0-20210428085206-8dfaf346081f/go.mod h1:U2OZ06VD1PHu3ZLZ8tuEHooaOZnoke/4ZKAZfL44bUQ= +github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20210721160012-eb78dcc77894 h1:9KGDivwjA9R7v4CheGqPlhnWm/Jr9xSqPVJFuHtu3T0= +github.com/mgr9525/HyperByte-Transfer-Protocol v1.1.6-0.20210721160012-eb78dcc77894/go.mod h1:U2OZ06VD1PHu3ZLZ8tuEHooaOZnoke/4ZKAZfL44bUQ= github.com/mgr9525/go-cloud v1.0.6-0.20210501052806-55406cd08e82 h1:ItYkGXk9RxTx2o+GYdJ9QtuHko8a9D/Hx8FO7z41IUA= github.com/mgr9525/go-cloud v1.0.6-0.20210501052806-55406cd08e82/go.mod h1:VkCKgivVD2OX75Zwh+AO3zuJyxGCsuo0zdy+UXCYy9I= github.com/mgr9525/go-ruisutil v1.0.8-0.20210317093428-f69295935056 h1:JhXsFUB3mFWwiDc8c//E/6cUazJUX1lIiLgiM0asNjA= diff --git a/webs/sys/main.go b/webs/sys/main.go index 787ad7f..0522468 100644 --- a/webs/sys/main.go +++ b/webs/sys/main.go @@ -65,8 +65,8 @@ func runHbtp(host string) { os.Exit(1) } eng := hbtp.NewEngine(context.Background()) - eng.RegFun(1, hbtp.RPCFunHandle(&routehb.CommRPC{})) - eng.RegFun(2, hbtp.RPCFunHandle(&routehb.UserRPC{})) + eng.RegFun(1, hbtp.GrpcFunHandle(&routehb.CommRPC{})) + eng.RegFun(2, hbtp.GrpcFunHandle(&routehb.UserRPC{})) if err := eng.Run(host); err != nil { logrus.Error("StartConnEngine run err:" + err.Error()) os.Exit(1)