123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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}
- }
|