随笔分类 -  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... 阅读全文
posted @ 2019-12-22 21:47 离地最远的星 阅读(645) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2019-12-22 20:52 离地最远的星 阅读(3218) 评论(0) 推荐(0) 编辑
摘要:TransPoint代码 package Services import ( "context" "encoding/json" "errors" "net/http" "strconv" ) func GetUserInfo_Request(_ context.Context, request *http.Request, r inter... 阅读全文
posted @ 2019-12-22 19:54 离地最远的星 阅读(649) 评论(0) 推荐(0) 编辑
摘要:注册和反注册代码 package utils import ( consulapi "github.com/hashicorp/consul/api" "log" ) var ConsulClient *consulapi.Client func init() { config := consulapi.DefaultConfig() config.Addr... 阅读全文
posted @ 2019-12-22 18:08 离地最远的星 阅读(752) 评论(0) 推荐(0) 编辑
摘要:编写注册函数 package utils import ( consulapi "github.com/hashicorp/consul/api" "log" ) func RegService() { config := consulapi.DefaultConfig() config.Address = "192.168.3.14:8500" re... 阅读全文
posted @ 2019-12-22 17:41 离地最远的星 阅读(1737) 评论(0) 推荐(0) 编辑
摘要: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{} ... 阅读全文
posted @ 2019-12-22 10:48 离地最远的星 阅读(1322) 评论(0) 推荐(0) 编辑
摘要:package Services import ( "context" "fmt" "github.com/go-kit/kit/endpoint" ) type UserRequest struct { //封装User请求结构体,包含参数名和方法 Uid int `json:"uid"` Method string } type User... 阅读全文
posted @ 2019-12-21 11:56 离地最远的星 阅读(664) 评论(0) 推荐(0) 编辑
摘要:package main import ( httptransport "github.com/go-kit/kit/transport/http" "github.com/gorilla/mux" "gomicro/Services" "net/http" ) func main() { user := Services.UserService... 阅读全文
posted @ 2019-12-21 11:29 离地最远的星 阅读(732) 评论(0) 推荐(0) 编辑
摘要:package main import ( "github.com/go-kit/kit/transport/http" "gomicro/Services" ) func main() { user := Services.UserService{} endp := Services.GenUserEnPoint(user) http.NewServ... 阅读全文
posted @ 2019-12-21 11:09 离地最远的星 阅读(917) 评论(0) 推荐(0) 编辑
摘要:第一步创建UserService package Services type IUserService interface { GetName(userid int) string } type UserService struct{} func (this UserService) GetName(userid int) string { if useri... 阅读全文
posted @ 2019-12-21 10:22 离地最远的星 阅读(1775) 评论(0) 推荐(0) 编辑