├── README.md
├── common 公共包
│ ├── common.go 实现一些基础方法,如配置文件读取,获取redis句柄等
│ └── register.go 服务注册封装
├── conf 配置文件目录
│ ├── config.conf 项目配置文件,如consul地址等
│ ├── db.conf 数据库配置文件
│ └── env.conf 运行环境
├── constant 常量包
│ └── status_code.go 定义所有返回码
├── consul consul api封装
│ ├── register.go
│ ├── resolver.go
│ └── watcher.go
└── service 服务模块集合
├── cache 缓存服务
│ ├── README.md
│ ├── logics 业务逻辑包
│ │ └── redis.go 具体业务
│ ├── main.go 服务入口
│ ├── proto proto文件
│ │ ├── cache.pb.go 执行protoc.sh生成的文件
│ │ ├── cache.proto 定义服务
│ │ └── protoc.sh 编译proto文件
│ └── test 测试包
│ └── client.go 用于测试本服务的客户端
├── web 服务面板
│ ├── README.md
│ ├── logics 业务逻辑包
│ │ ├── base.go 具体业务
│ │ └── db.go 具体业务
│ ├── main.go 面板主程序入口
│ ├── db 文件数据库
│ │ └── 2018_11_02 数据写入日期目录
│ └── models 数据模型
·
·
·
syntax = "proto3";
//service name is kibana
service Kibana {
//service method is write
rpc Write(WriteRequest) returns (WriteResponse) {}
}
//writer request struct
message WriteRequest {
string tag = 1;
string info = 2;
string level = 3;
}
//writer response struct
message WriteResponse {
int32 code = 1;
string message = 2;
map<string, string> data = 3;
}
protoc --proto_path=.:. --micro_out=. --go_out=. kibana.proto
package main
import (
proto "micro-srv/service/kibana/proto"
"micro-srv/service/kibana/logics"
"fmt"
"micro-srv/common"
"golang.org/x/net/context"
)
type Kibana struct{}
const (
SRV_PORT = 50061
SRV_NAME = "kibana"
)
func (k *Kibana) Write(ctx context.Context, req *proto.WriteRequest) (rsp *proto.WriteResponse, err error) {
rsp.Code = 0
rsp.Message = "success"
rsp.Data = map[string]string{"tag":req.Tag,"info":req.Info,"level":req.Level}
err = logics.WriteLog(req.Tag, req.Info, req.Level)
return rsp, err
}
func main() {
server, listener, err := common.Register(SRV_NAME, SRV_PORT)
if err != nil {
fmt.Println(err.Error())
}
proto.RegisterKibanaServer(server, &Kibana{})
err = server.Serve(listener)
if err != nil {
fmt.Println(err.Error())
}
}
consul agent -dev &
cd kibana && go run main.go &
详细见各服务根目录中 [README.md]
详细见各服务根目录中 [test/client.go]