随笔分类 - Go kit
摘要:注册初始化代码 package utils import ( "fmt" "github.com/google/uuid" consulapi "github.com/hashicorp/consul/api" "log" "strconv" ) var ConsulClient *consulapi.Client var ServiceID st...
阅读全文
摘要:package main import ( "context" "fmt" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" "github.com/go-kit/kit/sd" "github.com/go-kit/kit/sd/consul" htt...
阅读全文
摘要:TransPoint代码 package Services import ( "context" "encoding/json" "errors" "net/http" "strconv" ) func GetUserInfo_Request(_ context.Context, request *http.Request, r inter...
阅读全文
摘要:注册和反注册代码 package utils import ( consulapi "github.com/hashicorp/consul/api" "log" ) var ConsulClient *consulapi.Client func init() { config := consulapi.DefaultConfig() config.Addr...
阅读全文
摘要:编写注册函数 package utils import ( consulapi "github.com/hashicorp/consul/api" "log" ) func RegService() { config := consulapi.DefaultConfig() config.Address = "192.168.3.14:8500" re...
阅读全文
摘要:package main import ( httptransport "github.com/go-kit/kit/transport/http" mymux "github.com/gorilla/mux" "gomicro/Services" "net/http" ) func main() { user := Services.UserService{} ...
阅读全文
摘要:package Services import ( "context" "fmt" "github.com/go-kit/kit/endpoint" ) type UserRequest struct { //封装User请求结构体,包含参数名和方法 Uid int `json:"uid"` Method string } type User...
阅读全文
摘要:package main import ( httptransport "github.com/go-kit/kit/transport/http" "github.com/gorilla/mux" "gomicro/Services" "net/http" ) func main() { user := Services.UserService...
阅读全文
摘要:package main import ( "github.com/go-kit/kit/transport/http" "gomicro/Services" ) func main() { user := Services.UserService{} endp := Services.GenUserEnPoint(user) http.NewServ...
阅读全文
摘要:第一步创建UserService package Services type IUserService interface { GetName(userid int) string } type UserService struct{} func (this UserService) GetName(userid int) string { if useri...
阅读全文