# 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{}) ``` * `hessian:""` as tag of field unite field name of java and go, eg: ```go type User struct { A int `hessian:"b"` // name of A is b in the java, default a } ``` ### 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 jsonrpc 2.0 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.