package http import ( khttp "net/http" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" ) // RouterHandler hander type RouterHandler struct { Method string Router string Hander khttp.Handler } // EndpointRouter endpoint hander type EndpointRouter struct { Method string Router string Dec DecodeRequestFunc Enc EncodeResponseFunc Endpoint endpoint.Endpoint } // EndpointRouterHandler router to handler func EndpointRouterHandler(router EndpointRouter, logger log.Logger) RouterHandler { return RouterHandler{ Method: router.Method, Router: router.Router, Hander: NewTansportServer( router.Endpoint, router.Dec, router.Enc, logger)} } // GetEndpointRouter add GET endpoint func GetEndpointRouter(router string, dec DecodeRequestFunc, enc EncodeResponseFunc, endpoint endpoint.Endpoint) EndpointRouter { return EndpointRouter{ Method: `GET`, Router: router, Dec: dec, Enc: enc, Endpoint: endpoint} } // PostEndpointRouter add POST endpoint func PostEndpointRouter(router string, dec DecodeRequestFunc, enc EncodeResponseFunc, endpoint endpoint.Endpoint) EndpointRouter { return EndpointRouter{ Method: `POST`, Router: router, Dec: dec, Enc: enc, Endpoint: endpoint} } // PutEndpointRouter add PUT endpoint func PutEndpointRouter(router string, dec DecodeRequestFunc, enc EncodeResponseFunc, endpoint endpoint.Endpoint) EndpointRouter { return EndpointRouter{ Method: `PUT`, Router: router, Dec: dec, Enc: enc, Endpoint: endpoint} } // DeleteEndpointRouter add DELETE endpoint func DeleteEndpointRouter(router string, dec DecodeRequestFunc, enc EncodeResponseFunc, endpoint endpoint.Endpoint) EndpointRouter { return EndpointRouter{ Method: `DELETE`, Router: router, Dec: dec, Enc: enc, Endpoint: endpoint} } // HeadEndpointRouter add HEAD endpoint func HeadEndpointRouter(router string, dec DecodeRequestFunc, enc EncodeResponseFunc, endpoint endpoint.Endpoint) EndpointRouter { return EndpointRouter{ Method: `HEAD`, Router: router, Dec: dec, Enc: enc, Endpoint: endpoint} } // OptionsEndpointRouter add OPTIONS endpoint func OptionsEndpointRouter(router string, dec DecodeRequestFunc, enc EncodeResponseFunc, endpoint endpoint.Endpoint) EndpointRouter { return EndpointRouter{ Method: `OPTIONS`, Router: router, Dec: dec, Enc: enc, Endpoint: endpoint} } // PatchEndpointRouter add PATCH endpoint func PatchEndpointRouter(router string, dec DecodeRequestFunc, enc EncodeResponseFunc, endpoint endpoint.Endpoint) EndpointRouter { return EndpointRouter{ Method: `PATCH`, Router: router, Dec: dec, Enc: enc, Endpoint: endpoint} }