Skip to content

LeakIX/go-hessian

 
 

Repository files navigation

Golang Hessian

Build Status codecov Go Report Card License GoDoc Release

Golang Hessian can use hessian proxy to connect to hessian service.

Reference:

How to use ?

No argument method call

package main

import (
    "log"
    "time"

    hessian "github.com/ggwhite/go-hessian"
)

func main() {
    var addr = "http://localhost:8080/simple"
    proxy, err := hessian.NewProxy(&hessian.ProxyConfig{
        Version: hessian.V1,
        URL:     addr,
    })
    if err != nil {
        panic(err)
    }
    
    args, err := proxy.Invoke("str")
    log.Println(args, err)
}

Result:

2019/04/18 16:20:52 [Hello] <nil>

Create a proxy to your hessian service, invoke from given method name, it return a slice of interface and error.

With argument method call

package main

import (
    "log"
    "time"

    hessian "github.com/ggwhite/go-hessian"
)

func main() {
    var addr = "http://localhost:8080/simple"
    proxy, err := hessian.NewProxy(&hessian.ProxyConfig{
        Version: hessian.V1,
        URL:     addr,
    })
    if err != nil {
        panic(err)
    }
    
    log.Println(proxy.Invoke("strI2", "ggwhite", "this is message"))
    log.Println(args, err)
}

Result:

2019/04/18 16:43:18 [Hello[ggwhite], this is message] <nil>

With struct argument method call

package main

import (
    "log"
    "time"

    hessian "github.com/ggwhite/go-hessian"
)

type User struct {
    hessian.Package `hessian:"lab.ggw.shs.service.User"`
    Name            string      `hessian:"name"`
    Email           interface{} `hessian:"email"`
    Father          *User       `hessian:"father"`
}

func main() {
    var addr = "http://localhost:8080/simple"
    proxy, err := hessian.NewProxy(&hessian.ProxyConfig{
        Version: hessian.V1,
        URL:     addr,
    })
    if err != nil {
        panic(err)
    }
    proxy.RegisterType(reflect.TypeOf(User{}))
    
    ans, err := proxy.Invoke("obj")
    log.Println(ans[0], err)
    
    log.Println(proxy.Invoke("objI", &User{
        Name:  "ggwhite",
        Email: "ggw.chang@gmail.com",
    }))
}

Result:

2019/04/18 16:46:13 &{ ggwhite ggw.chang@gmail.com <nil>} <nil>
2019/04/18 16:46:13 [ggwhite] <nil>

Give hessian.Package to your struct and add tag hessian to let proxy know what package(ClassName) of your POJO.

Mapping type can be a type of struct or a pointer of the struct.

Supported

Type Serialize Deserialize Syntax
null Y Y N
boolean Y Y T/F
int Y Y I b32 b24 b16 b8
long Y Y L b64 b56 b48 b40 b32 b24 b16 b8
double Y Y D b64 b56 b48 b40 b32 b24 b16 b8
date Y Y d b64 b56 b48 b40 b32 b24 b16 b8
string Y Y S b16 b8 utf-8-data
xml N N
binary Y Y B b16 b8 binary-data
list Y Y V type? length? object* z
map Y Y M t b16 b8 type-string (object, object)* z
ref N N
remote N N

About

A hessian proxy for Golang.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%