5.服务注册与发现Consul,简学API,手动注册和删除服务
2021-01-22 15:14
标签:定义 lse list pac status pack src and mic 5.服务注册与发现Consul,简学API,手动注册和删除服务 标签:定义 lse list pac status pack src and mic 原文地址:https://www.cnblogs.com/hualou/p/12079206.htmlpackage main
import (
httptransport "github.com/go-kit/kit/transport/http"
mymux "github.com/gorilla/mux"
"gomicro/Services"
"net/http"
)
func main() {
user := Services.UserService{}
endp := Services.GenUserEnPoint(user)
serverHandler := httptransport.NewServer(endp, Services.DecodeUserRequest, Services.EncodeUserResponse) //使用go kit创建server传入我们之前定义的两个解析函数
r := mymux.NewRouter()
//r.Handle(`/user/{uid:\d+}`, serverHandler) //这种写法支持多种请求方式
r.Methods("GET", "DELETE").Path(`/user/{uid:\d+}`).Handler(serverHandler) //这种写法仅支持Get,限定只能Get请求
r.Methods("GET").Path("/health").HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-type", "application/json")
writer.Write([]byte(`{"status":"ok"}`))
})
http.ListenAndServe(":8080", r)
}
文章标题:5.服务注册与发现Consul,简学API,手动注册和删除服务
文章链接:http://soscw.com/essay/45480.html