/mast

mast 微服务框架落地生成grpc 配置化生成不同生产环境的 gRPC 服务,添加metrics,对接 Istio ,k8s 等

Primary LanguageGoGNU General Public License v3.0GPL-3.0

mast

Go Report Card

mast is a builder for rpc client and server.By use same options to reduce lines of code.

Usage

RPC

Server

package main

import (
    "errors"
    "github.com/silverswords/mast"
)

type Args struct { 
	A, B int
}

type Quotient struct {
	Quo, Rem int
}

type Arith int

func (t *Arith) Multiply(args *Args, reply *int) error {
	*reply = args.A * args.B
	return nil
}

func (t *Arith) Divide(args *Args, quo *Quotient) error {
	if args.B == 0 {
		return errors.New("divide by zero")
	}
	quo.Quo = args.A / args.B
	quo.Rem = args.A % args.B
	return nil
}


func main() {
	m := &mast.Mast{BuilderOptions: defaultRPCBuildOptions()}
	m.BuilderOptions.rcvrs["Arith"] = new(Arith)
	m.BuildServer("RPC")
}

Client.go

package main

import (
    "log"
    "github.com/silverswords/mast"
)

type Args struct { 
	A, B int
}

type Quotient struct {
	Quo, Rem int
}

func main(){
	m := &mast.Mast{BuilderOptions: defaultRPCBuildOptions()}
	args := &Args{7, 8}
	var reply int
    err := mast.BuildClient("RPC").(*rpc.Client).Call("Arith.Multiply", args, &reply)
	if err != nil {
		log.Fatal(err)
    }
}