Documentation ¶
Index ¶
- Variables
- func ContextWithHttpRequest(ctx context.Context, req *http.Request) context.Context
- func ContextWithOperationID(ctx context.Context, operationID string) context.Context
- func ContextWithServiceMeta(ctx context.Context, meta ServiceMeta) context.Context
- func HttpRequestFromContext(ctx context.Context) *http.Request
- func OperationIDFromContext(ctx context.Context) string
- func ParamsFromMap(m map[string]string) httprouter.Params
- func TryCatch(fn func()) (err error)
- type BadRequest
- type GroupOperator
- type HttpMiddleware
- type HttpRouteHandler
- type HttpRouteMeta
- type HttpTransport
- type MethodDescriber
- type PathDescriber
- type PathnamePattern
- type PostValidator
- type RequestInfo
- func (info *RequestInfo) Body() io.Reader
- func (info *RequestInfo) CookieValues(name string) []string
- func (info *RequestInfo) HeaderValues(name string) []string
- func (info *RequestInfo) Param(name string) string
- func (info *RequestInfo) QueryValues(name string) []string
- func (info *RequestInfo) Value(in string, name string) string
- func (info *RequestInfo) Values(in string, name string) []string
- type RequestParameter
- type RequestTransformer
- type RequestTransformerMgr
- type ServerModifier
- type ServiceMeta
- type ServiceMetaHook
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var HttpRequestKey = reflect.TypeOf(http.Request{}).String()
View Source
var RxHttpRouterPath = regexp.MustCompile("/:([^/]+)")
View Source
var ServiceMetaKey = reflect.TypeOf(ServiceMeta{}).String()
Functions ¶
func ContextWithHttpRequest ¶
func ContextWithOperationID ¶ added in v1.3.0
func ContextWithServiceMeta ¶
func ContextWithServiceMeta(ctx context.Context, meta ServiceMeta) context.Context
func OperationIDFromContext ¶ added in v1.3.0
func ParamsFromMap ¶
func ParamsFromMap(m map[string]string) httprouter.Params
Types ¶
type BadRequest ¶
type BadRequest struct {
// contains filtered or unexported fields
}
func (*BadRequest) AddErr ¶
func (e *BadRequest) AddErr(err error, in string, nameOrIdx ...interface{})
func (*BadRequest) EnableErrTalk ¶
func (e *BadRequest) EnableErrTalk()
func (*BadRequest) Err ¶
func (e *BadRequest) Err() error
func (*BadRequest) SetMsg ¶
func (e *BadRequest) SetMsg(msg string)
type GroupOperator ¶
type GroupOperator struct { courier.EmptyOperator // contains filtered or unexported fields }
func Group ¶
func Group(path string) *GroupOperator
Example ¶
package main import ( "fmt" "github.com/go-courier/httptransport" ) func main() { g := httptransport.Group("/test") fmt.Println(g.Path()) }
Output: /test
func (*GroupOperator) Path ¶
func (g *GroupOperator) Path() string
type HttpMiddleware ¶
func MiddlewareChain ¶
func MiddlewareChain(mw ...HttpMiddleware) HttpMiddleware
type HttpRouteHandler ¶
type HttpRouteHandler struct { *RequestTransformerMgr *HttpRouteMeta // contains filtered or unexported fields }
func NewHttpRouteHandler ¶
func NewHttpRouteHandler(serviceMeta *ServiceMeta, httpRoute *HttpRouteMeta, requestTransformerMgr *RequestTransformerMgr) *HttpRouteHandler
func (*HttpRouteHandler) ServeHTTP ¶
func (handler *HttpRouteHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request)
type HttpRouteMeta ¶
Example ¶
package main import ( "fmt" "os" "sort" "github.com/fatih/color" "github.com/go-courier/httptransport/__examples__/routes" "github.com/go-courier/httptransport" ) func main() { os.Setenv("PROJECT_NAME", "service-example") os.Setenv("PROJECT_VERSION", "1.0.0") color.NoColor = true routeList := routes.RootRouter.Routes() sort.Slice(routeList, func(i, j int) bool { return httptransport.NewHttpRouteMeta(routeList[i]).Key() < httptransport.NewHttpRouteMeta(routeList[j]).Key() }) for i := range routeList { httpRouteMeta := httptransport.NewHttpRouteMeta(routeList[i]) fmt.Println(fmt.Sprintf(httpRouteMeta.String())) } }
Output: GET /demo openapi.OpenAPI GET /demo/binary/files routes.DownloadFile GET /demo/binary/images routes.ShowImage POS /demo/cookie routes.Cookie POS /demo/forms/multipart routes.FormMultipartWithFile POS /demo/forms/multipart-with-files routes.FormMultipartWithFiles POS /demo/forms/urlencoded routes.FormURLEncoded GET /demo/redirect routes.Redirect POS /demo/redirect routes.RedirectWhenError POS /demo/restful routes.Create HEA /demo/restful routes.HealthCheck GET /demo/restful/{id} routes.DataProvider routes.GetByID DEL /demo/restful/{id} routes.DataProvider routes.RemoveByID PUT /demo/restful/{id} routes.DataProvider routes.UpdateByID
func NewHttpRouteMeta ¶
func NewHttpRouteMeta(route *courier.Route) *HttpRouteMeta
func (*HttpRouteMeta) Key ¶
func (route *HttpRouteMeta) Key() string
func (*HttpRouteMeta) Method ¶
func (route *HttpRouteMeta) Method() string
func (*HttpRouteMeta) Path ¶
func (route *HttpRouteMeta) Path() string
func (*HttpRouteMeta) String ¶
func (route *HttpRouteMeta) String() string
type HttpTransport ¶
type HttpTransport struct { ServiceMeta Port int // for modifying http.Server ServerModifiers []ServerModifier // Middlewares // can use https://github.com/gorilla/handlers Middlewares []HttpMiddleware // validator mgr for parameter validating ValidatorMgr validator.ValidatorMgr // transformer mgr for parameter transforming TransformerMgr transformers.TransformerMgr // Logger Logger *logrus.Entry CertFile string KeyFile string // contains filtered or unexported fields }
func NewHttpTransport ¶
func NewHttpTransport(serverModifiers ...ServerModifier) *HttpTransport
func (*HttpTransport) ServeHTTP ¶
func (t *HttpTransport) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*HttpTransport) SetDefaults ¶
func (t *HttpTransport) SetDefaults()
type MethodDescriber ¶
type MethodDescriber interface {
Method() string
}
type PathDescriber ¶
type PathDescriber interface {
Path() string
}
type PathnamePattern ¶
type PathnamePattern struct {
// contains filtered or unexported fields
}
func NewPathnamePattern ¶
func NewPathnamePattern(p string) *PathnamePattern
func (*PathnamePattern) Parse ¶
func (pattern *PathnamePattern) Parse(pathname string) (params httprouter.Params, err error)
func (*PathnamePattern) String ¶
func (pattern *PathnamePattern) String() string
func (*PathnamePattern) Stringify ¶
func (pattern *PathnamePattern) Stringify(params httprouter.Params) string
type PostValidator ¶
type PostValidator interface {
PostValidate(badRequest *BadRequest)
}
type RequestInfo ¶
func NewRequestInfo ¶
func NewRequestInfo(r *http.Request) *RequestInfo
func (*RequestInfo) Body ¶
func (info *RequestInfo) Body() io.Reader
func (*RequestInfo) CookieValues ¶
func (info *RequestInfo) CookieValues(name string) []string
func (*RequestInfo) HeaderValues ¶
func (info *RequestInfo) HeaderValues(name string) []string
func (*RequestInfo) Param ¶
func (info *RequestInfo) Param(name string) string
func (*RequestInfo) QueryValues ¶
func (info *RequestInfo) QueryValues(name string) []string
type RequestParameter ¶
type RequestParameter struct { Name string In string transformers.CommonTransformOption Transformer transformers.Transformer Validator validator.Validator }
func NewRequestParameter ¶
func NewRequestParameter(name string, in string) *RequestParameter
type RequestTransformer ¶
type RequestTransformer struct { Type reflect.Type Parameters map[string]*RequestParameter }
func (*RequestTransformer) DecodeFromRequestInfo ¶
func (t *RequestTransformer) DecodeFromRequestInfo(info *RequestInfo, v interface{}) error
func (*RequestTransformer) NewRequest ¶
type RequestTransformerMgr ¶
type RequestTransformerMgr struct { validator.ValidatorMgr transformers.TransformerMgr // contains filtered or unexported fields }
func NewRequestTransformerMgr ¶
func NewRequestTransformerMgr( transformerMgr transformers.TransformerMgr, validatorMgr validator.ValidatorMgr, ) *RequestTransformerMgr
func (*RequestTransformerMgr) NewRequest ¶
func (*RequestTransformerMgr) NewRequestTransformer ¶
func (mgr *RequestTransformerMgr) NewRequestTransformer(ctx context.Context, typ reflect.Type) (*RequestTransformer, error)
func (*RequestTransformerMgr) SetDefaults ¶
func (mgr *RequestTransformerMgr) SetDefaults()
type ServerModifier ¶
type ServiceMeta ¶
func ServerMetaFromContext ¶
func ServerMetaFromContext(ctx context.Context) ServiceMeta
func (*ServiceMeta) SetDefaults ¶
func (s *ServiceMeta) SetDefaults()
func (ServiceMeta) String ¶
func (s ServiceMeta) String() string
type ServiceMetaHook ¶
type ServiceMetaHook struct {
ServiceMeta
}
func (ServiceMetaHook) Levels ¶
func (ServiceMetaHook) Levels() []logrus.Level
Source Files ¶
Click to show internal directories.
Click to hide internal directories.