tp-micro

module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2018 License: Apache-2.0

README

Ants GitHub release report card Coverage Status github issues github closed issues view teleport view ant view Go网络编程群

Ants is a highly available microservice platform based on Ant and Teleport.

简体中文

1. Install

go version ≥ 1.9
go get -u -f -d github.com/xiaoenai/ants/...

2. Feature

  • Support auto service-discovery
  • Supports custom service linker
  • Support load balancing
  • Support NIO and connection pool
  • Support custom protocol
  • Support custom body codec
  • Support plug-in expansion
  • Support heartbeat mechanism
  • Detailed log information, support print input and output details
  • Support for setting slow operation alarm thresholds
  • Support for custom log
  • Support smooth shutdown and update
  • Support push handler
  • Support network list: tcp, tcp4, tcp6, unix, unixpacket and so on
  • Client support automatically redials after disconnection

3. Project Structure

(recommend)

├── README.md
├── main.go
├── api
│   ├── handlers.gen.go
│   ├── handlers.go
│   ├── router.gen.go
│   └── router.go
├── logic
│   └── xxx.go
├── sdk
│   ├── rpc.gen.go
│   ├── rpc.gen_test.go
│   ├── rpc.go
│   └── rpc_test.go
└── types
    ├── types.gen.go
    └── types.go

Desc:

  • add .gen suffix to the file name of the automatically generated file

4. Project Management

4.1 Install
cd $GOPATH/github.com/henrylee2cn/ant/cmd/ant
go install
4.2 Usage
  • generate project
NAME:
   ant gen - Generate an ant project

USAGE:
   ant gen [command options] [arguments...]

OPTIONS:
   --script value, -s value    The script for code generation(relative/absolute)
   --app_path value, -p value  The path(relative/absolute) of the project

example: ant gen -s ./test.ant -p ./myant

  • run project
NAME:
   ant run - Compile and run gracefully (monitor changes) an any existing go project

USAGE:
   ant run [options] [arguments...]
 or
   ant run [options except -app_path] [arguments...] {app_path}

OPTIONS:
   --watch_exts value, -x value  Specified to increase the listening file suffix (default: ".go", ".ini", ".yaml", ".toml", ".xml")
   --app_path value, -p value    The path(relative/absolute) of the project

example: ant run -x .yaml -p myant or ant run -x .yaml myant

More Ant Command

5. Demo of Ant

  • server
package main

import (
	"github.com/henrylee2cn/ant"
	tp "github.com/henrylee2cn/teleport"
)

// Args args
type Args struct {
	A int
	B int `param:"<range:1:>"`
}

// P handler
type P struct {
	tp.PullCtx
}

// Divide divide API
func (p *P) Divide(args *Args) (int, *tp.Rerror) {
	return args.A / args.B, nil
}

func main() {
	srv := ant.NewServer(ant.SrvConfig{
		ListenAddress: ":9090",
	})
	srv.RoutePull(new(P))
	srv.Listen()
}
  • client
package main

import (
	"github.com/henrylee2cn/ant"
)

func main() {
	cli := ant.NewClient(
		ant.CliConfig{},
		ant.NewStaticLinker(":9090"),
	)
	defer	cli.Close()

	type Args struct {
		A int
		B int
	}

	var reply int
	rerr := cli.Pull("/p/divide", &Args{
		A: 10,
		B: 2,
	}, &reply).Rerror()
	if rerr != nil {
		ant.Fatalf("%v", rerr)
	}
	ant.Infof("10/2=%d", reply)
	rerr = cli.Pull("/p/divide", &Args{
		A: 10,
		B: 0,
	}, &reply).Rerror()
	if rerr == nil {
		ant.Fatalf("%v", rerr)
	}
	ant.Infof("test binding error: ok: %v", rerr)
}

More

6. License

Ants is under Apache v2 License. See the LICENSE file for the full license text

Directories

Path Synopsis
cmd/antconfig command
Package gateway is the main program for TCP and HTTP services.
Package gateway is the main program for TCP and HTTP services.
samples/simple command
sdk
types
Package types is a generated protocol buffer package.
Package types is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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