common

package module
v0.0.0-...-cfb0821 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

公共代码

Build Status Coverage Status Go Report Card

RPC

客户端
package main

import (
	"fmt"

	"github.com/gunsluo/common/example/rpc/model"
	"github.com/gunsluo/common/rpc"
)

func main() {

	client := rpc.NewClient("127.0.0.1:9999", 10)

	req := new(model.RequestArg)
	req.ArgOne = "test"
	var resp model.ResponseArg
	fmt.Printf("send: %+v\n", req)
	err := client.Call("Handle.Test", req, &resp)
	if err != nil {
		fmt.Println("err:", err)
	} else {
		fmt.Printf("resp: %+v\n", resp)
	}
}
服务端
package main

import (
	"fmt"

	"github.com/gunsluo/common/example/rpc/model"
	"github.com/gunsluo/common/rpc"
)

// Handle define handle
type Handle int

// Test  test is example
func (t *Handle) Test(args *model.RequestArg, reply *model.ResponseArg) error {

	fmt.Println("receive:", args)

	reply.RespArgOne = "response"
	reply.Code = 200
	reply.Msg = "Success"

	fmt.Println("response:", reply)

	return nil
}

func main() {

	server := rpc.NewServer("0.0.0.0:9999")
	server.Register(new(Handle))

	server.Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HmacSha1

func HmacSha1(message []byte, secret string) []byte

HmacSha1 to byte slice

func HmacSha1ToHex

func HmacSha1ToHex(message []byte, secret string) string

HmacSha1ToHex to hex num

func ToString

func ToString(filePath string) (string, error)

ToString read file content from filepath

func ToTrimString

func ToTrimString(filePath string) (string, error)

ToTrimString read file content from filepath and replace space

func VerifyHmacSha1

func VerifyHmacSha1(message []byte, secret string, signature string) bool

VerifyHmacSha1 verify hmacsha1 result

Types

This section is empty.

Directories

Path Synopsis
example
rpc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL