This package provide a customize json-rpc mico-service framework
go get -u github.com/WeiWeiWesley/rpc_server
- ENV
- SERVICE (Service name)
For start service requires ENV & SERVICE variables
SERVICE=Echo ENV=local go run main.go
You can add your service in service folder
rpc_server
|-config
|-env
|-local
|-default.toml
|-echo.toml
|-core
|-scheme
|-service
|-echo.go
|-main.go
|-README.md
Here is a example that you have to do.
- Import "rpc_server/core/rpc"
- Use rpc.Register() when init()
- Implement your service
package service
// 1. Import "rpc_server/core/rpc"
import (
"rpc_server/core/rpc"
)
// 2. Use rpc.Register() when init()
func init() {
rpc.Register("Echo", "A Echo Service", &Echo{})
}
// 3. Implement your service
// Echo echo service
type Echo struct{}
//Ping Ping
func (d *Echo) Ping(args *string, result *string) (rpcErr error) {
*result = "Pong"
return
}
Simulation multi services in local envrionment. Use docker-compose.
docker-compose up
Add your services to docker-compose.yaml
version: '2'
services:
echo:
build: .
hostname: echo
environment:
- ENV=local
- SERVICE=Echo
- TZ=Asia/Taipei
math:
build: .
hostname: math
environment:
- ENV=local
- SERVICE=Math
- TZ=Asia/Taipei
We used to run one service at one pod or one mechine in production envrionment. But if you want to start all at once, here is it.
SERVICE=All ENV=local go run main.go