top

Package hprose client example:

package main

import (
	"fmt"
	"hprose"
)

type testUser struct {
	Name     string
	Sex      int
	Birthday time.Time
	Age      int
	Married  bool
}

type testRemoteObject struct {
	Hello               func(string) string
	HelloWithError      func(string) (string, error)               `name:"hello"`
	AsyncHello          func(string) <-chan string                 `name:"hello"`
	AsyncHelloWithError func(string) (<-chan string, <-chan error) `name:"hello"`
	Sum                 func(...int) int
	SwapKeyAndValue     func(*map[string]string) map[string]string `byref:"true"`
	SwapInt             func(int, int) (int, int)                  `name:"swap"`
	SwapFloat           func(float64, float64) (float64, float64)  `name:"swap"`
	Swap                func(interface{}, interface{}) (interface{}, interface{})
	GetUserList         func() []testUser
}

func main() {
	client := hprose.NewClient("http://www.hprose.com/example/")
	var ro *RemoteObject
	client.UseService(&ro)

	// If an error occurs, it will panic
	fmt.Println(ro.Hello("World"))

	// If an error occurs, an error value will be returned
	if result, err := ro.HelloWithError("World"); err == nil {
		fmt.Println(result)
	} else {
		fmt.Println(err.Error())
	}

	// If an error occurs, it will be ignored
	result := ro.AsyncHello("World")
	fmt.Println(<-result)

	// If an error occurs, an error chan will be returned
	result, err := ro.AsyncHelloWithError("World")
	if e := <-err; e == nil {
		fmt.Println(<-result)
	} else {
		fmt.Println(e.Error())
	}
	fmt.Println(ro.Sum(1, 2, 3, 4, 5))

	m := make(map[string]string)
	m["Jan"] = "January"
	m["Feb"] = "February"
	m["Mar"] = "March"
	m["Apr"] = "April"
	m["May"] = "May"
	m["Jun"] = "June"
	m["Jul"] = "July"
	m["Aug"] = "August"
	m["Sep"] = "September"
	m["Oct"] = "October"
	m["Nov"] = "November"
	m["Dec"] = "December"

	fmt.Println(m)
	mm := ro.SwapKeyAndValue(&m)
	fmt.Println(m)
	fmt.Println(mm)

	fmt.Println(ro.GetUserList())
	fmt.Println(ro.SwapInt(1, 2))
	fmt.Println(ro.SwapFloat(1.2, 3.4))
	fmt.Println(ro.Swap("Hello", "World"))
}

Package hprose is a High Performance Remote Object Service Engine.

It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.

Hprose supports many programming languages, for example:

* AAuto Quicker
* ActionScript
* ASP
* C++
* Dart
* Delphi/Free Pascal
* dotNET(C#, Visual Basic...)
* Golang
* Java
* JavaScript
* Node.js
* Objective-C
* Perl
* PHP
* Python
* Ruby
* ...

Through Hprose, You can conveniently and efficiently intercommunicate between those programming languages.

This project is the implementation of Hprose for Golang.

Imports 1 package(s) ΒΆ

  1. github.com/gorilla/websocket