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{}
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)
}