Categorygithub.com/lambdaxs/go-server
modulepackage
0.0.15
Repository: https://github.com/lambdaxs/go-server.git
Documentation: pkg.go.dev

# README

特性

  • 服务注册发现
  • grpc负载均衡
  • 配置中心
  • 监控/日志/链路
  • 常用数据库驱动

配置管理

  • consul
  • admin
  • config version

日志管理

  • EFK
  • kafka
  • agent monitor

服务监控

  • prometheus
  • grafna
  • consul + confd

链路监控

  • jaeger + agent + collector

服务注册

  • consul
  • agent health
  • service health
  • cluster alert

机器和部署管理

  • CMDB
  • ansible + Makefile + image version

用户管理

  • user
  • group
  • auth grant

测试

  • sonar
  • unit

Example

  • config.toml
[httpServer]
    host = "127.0.0.1"
    port = 8000
    consulAddr = "127.0.0.1:8500"

[grpcServer]
    host = "127.0.0.1"
    port = 8001
    consulAddr = "127.0.0.1:8500"

[mysql]
    [mysql.db]
        dsn = "root:123456@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&readTimeout=3s"
        log = true

[redis]
    [redis.cache]
        dsn = "127.0.0.1:6379"
  • main.go
package main

import (    
    "github.com/lambdaxs/go-server"

    "github.com/labstack/echo"

    "context"   
    "fmt"
    "google.golang.org/grpc"
    hello "github.com/lambdaxs/go-server/example/discover/pb"
)

func main() {
    app := go_server.New("demo-server")
    
    //start http server
    httpSrv := app.HttpServer()
    httpSrv.GET("/hello", func(c echo.Context) error {
        return c.JSON(200,"Hello Go-Server!")
    })
    
    //start grpc server
    app.RegisterGRPCServer(func(srv *grpc.Server) {
        hello.RegisterHelloServerServer(srv, &SayHelloServer{})             
    })

    //server start
    app.Run()
    
}

type SayHelloServer struct {
}

func (s *SayHelloServer) SayHello(ctx context.Context, req *hello.SayHelloReq) (resp *hello.SayHelloResp, err error) {
    resp = &hello.SayHelloResp{
        Reply: "",
    }
    resp.Reply = fmt.Sprintf("%s:%s", req.GetName(), "hello")
    return
}

  • 启动程序
go run main.go --config config.toml

配置文件

  • http服务配置
[httpServer]
    host = "127.0.0.1"
    port = 8000
    consulAddr = "127.0.0.1:8500" #consulAddr为consul的链接地址,用户服务发现与注册。可选,留空即为单机服务
  • grpc服务配置
[grpcServer]
    host = "127.0.0.1"
    port = 8001
    consulAddr = "127.0.0.1:8500" #consulAddr为consul的链接地址,用户服务发现与注册。可选,留空即为单机服务
  • mysql配置
[mysql]
    [mysql.db]
        dsn = "root:123456@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&readTimeout=3s"
        log = true
//get mysql db object
db := go_server.Model("db")

  • redis配置
[redis]
    [redis.cache]
        dsn = "127.0.0.1:6379"
//get redis connect pool
pool := go_server.RedisPool("cache")
conn := pool.Get()
defer conn.close()

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author