You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by xi...@apache.org on 2020/02/29 06:16:24 UTC

[dubbo-go.wiki] 25/35: Created Guide for Use (markdown)

This is an automated email from the ASF dual-hosted git repository.

xinminghe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go.wiki.git

commit 888bff0455a9ec3800f9e9df59f937d58c31ceb9
Author: fangyincheng <fa...@gmail.com>
AuthorDate: Wed Jun 5 14:52:54 2019 +0800

    Created Guide for Use (markdown)
---
 Guide-for-Use.md | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 158 insertions(+)

diff --git a/Guide-for-Use.md b/Guide-for-Use.md
new file mode 100644
index 0000000..3eb376c
--- /dev/null
+++ b/Guide-for-Use.md
@@ -0,0 +1,158 @@
+# Guide for Use
+
+## How to start quick?
+
+---
+
+### STEP 1: Define struct and provider
+
+> go-for-apache-dubbo/examples/dubbo/go-client/app/user.go
+> go-for-apache-dubbo/examples/dubbo/go-server/app/user.go
+
+```go
+// all structs must implements hessian.POJO
+type User struct {}
+func (User) JavaClassName string {
+    return "com.Xxx.User" // same to the java class name
+}
+
+// for server
+func init() {
+	config.SetProviderService(new(UserProvider))
+}
+UserProvider struct {}
+// args list reference "What to pay attention to?/function"
+func (u *UserProvider) YourMethod(ctx context.Context, req []interface{}, rsp *User) error {
+    // do your any things
+}
+
+// for client
+func init() {
+	config.SetConsumerService(new(UserProvider))
+}
+type UserProvider struct {
+    YourMethod func(ctx context.Context, req []interface{}, rsp *User) error
+}
+```
+
+### STEP 2: Code client.go
+
+> go-for-apache-dubbo/examples/dubbo/go-client/app/client.go
+
+```go
+// must import package you will use
+// reference "What to pay attention to?/package"
+
+// register pojo 
+hessian.RegisterPOJO(&User{})
+// Load
+conMap, _ := config.Load()
+// call
+conMap["com.Xxx.User"].GetRPCService().YourMethod(...)
+```
+
+### STEP 3: Code server.go
+
+> go-for-apache-dubbo/examples/dubbo/go-server/app/server.go
+
+```go
+// must import package you will use
+// reference "What to pay attention to?/package"
+
+// register pojo 
+hessian.RegisterPOJO(&User{})
+// Load
+_, proMap := config.Load()
+```
+
+### STEP 4: Make client.yml and server.yml
+
+> go-for-apache-dubbo/config/testdata/consumer_config.yml
+
+> go-for-apache-dubbo/config/testdata/provider_config.yml
+
+## What to pay attention to?
+
+---
+
+### hessian2
+
+* all structs must implements hessian.POJO
+* JavaEnum type should be: 
+```go
+const (
+	MAN hessian.JavaEnum = iota
+	WOMAN
+)
+var genderName = map[hessian.JavaEnum]string{
+	MAN:   "MAN",
+	WOMAN: "WOMAN",
+}
+
+var genderValue = map[string]hessian.JavaEnum{
+	"MAN":   MAN,
+	"WOMAN": WOMAN,
+}
+type Gender hessian.JavaEnum
+func (g Gender) JavaClassName() string {
+	return "com.Xxx.Gender"
+}
+func (g Gender) String() string {
+	return genderName[hessian.JavaEnum(g)]
+}
+
+func (g Gender) EnumValue(s string) hessian.JavaEnum {
+    return genderValue[s]
+}
+```
+
+```go
+hessian.RegisterJavaEnum(Gender(MAN))
+hessian.RegisterJavaEnum(Gender(WOMAN))
+```
+
+* JavaClass type should be:
+```go
+type User struct {}
+func (User) JavaClassName string {
+    return "com.Xxx.User" // same to the java class name
+}
+```
+
+```go
+hessian.RegisterPOJO(&User{})
+```
+
+### function
+
+* support these argslist in the `dubbo protocol`
+
+```go
+Method_1(ctx context.Context, req []interface{}, rsp *User) error
+Method_2(id string, name string) (User, error)
+Method_3(ctx context.Context, req []interface{}, rsp *[]interface{}) error
+Method_4(ctx context.Context, req []interface{}) ([]interface{}, error)
+Method_5(ctx context.Context, req []interface{}) (map[interface{}]interface{}, error)
+```
+
+### package
+
+* must import
+```go
+_ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory"
+_ "github.com/dubbo/go-for-apache-dubbo/registry/protocol"
+_ "github.com/dubbo/go-for-apache-dubbo/filter/impl"
+_ "github.com/dubbo/go-for-apache-dubbo/cluster/cluster_impl"
+_ "github.com/dubbo/go-for-apache-dubbo/cluster/loadbalance"
+```
+
+* other
+```go
+_ "github.com/dubbo/go-for-apache-dubbo/protocol/dubbo" // when using dubbo protocol
+_ "github.com/dubbo/go-for-apache-dubbo/protocol/jsonrpc" // when using dubbo protocol
+_ "github.com/dubbo/go-for-apache-dubbo/registry/zookeeper" // when using zookeeper registry
+```
+
+### config
+
+* when you want to get local ip, you can delete `ip` field.
\ No newline at end of file