GithubHelp home page GithubHelp logo

go-hessian's Introduction

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: "[email protected]",
    }))
}

Result:

2019/04/18 16:46:13 &{ ggwhite [email protected] <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

go-hessian's People

Contributors

ggwhite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

go-hessian's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.