Documentation ¶
Index ¶
- func AsRequestOut(ctx context.Context) context.Context
- func ContextWithHttpRequest(ctx context.Context, req *http.Request) context.Context
- func ContextWithOperatorFactory(ctx context.Context, factory *kit.OperatorFactory) context.Context
- func ContextWithRouteMetaID(ctx context.Context, id string) context.Context
- func ContextWithServiceMeta(ctx context.Context, meta ServiceMeta) context.Context
- func EnableQueryInBodyForGet(ctx context.Context) context.Context
- func HttpRequestFromContext(ctx context.Context) *http.Request
- func IsRequestOut(ctx context.Context) bool
- func OperationIDFromContext(ctx context.Context) string
- func OperatorFactoryFromContext(ctx context.Context) *kit.OperatorFactory
- func ShouldQueryInBodyForGet(ctx context.Context) bool
- type BadRequestError
- type BasePathDescriber
- type HttpMiddleware
- type HttpRouteMeta
- type HttpTransport
- type MetaOperator
- type MethodDescriber
- type OperatorFactoryWithRouteMeta
- type PathDescriber
- type PostValidator
- type RequestTsfm
- func (t *RequestTsfm) DecodeAndValidate(ctx context.Context, ri httpx.RequestInfo, v interface{}) error
- func (t *RequestTsfm) DecodeFromRequestInfo(ctx context.Context, ri httpx.RequestInfo, v interface{}) error
- func (t *RequestTsfm) NewReqWithContext(ctx context.Context, method, url string, v interface{}) (*http.Request, error)
- func (t *RequestTsfm) NewRequest(method, url string, v interface{}) (*http.Request, error)
- type RequestTsfmFactory
- func (f *RequestTsfmFactory) NewRequest(method, url string, v interface{}) (*http.Request, error)
- func (f *RequestTsfmFactory) NewRequestTsfm(ctx context.Context, typ reflect.Type) (*RequestTsfm, error)
- func (f *RequestTsfmFactory) NewRequestWithContext(ctx context.Context, method, url string, v interface{}) (*http.Request, error)
- func (f *RequestTsfmFactory) SetDefault()
- type ResponseWithError
- type RouteHandler
- type RouteMeta
- type ServerModifier
- type ServiceMeta
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithHttpRequest ¶
func ContextWithRouteMetaID ¶
func ContextWithServiceMeta ¶
func ContextWithServiceMeta(ctx context.Context, meta ServiceMeta) context.Context
func IsRequestOut ¶
func OperationIDFromContext ¶
func OperatorFactoryFromContext ¶
func OperatorFactoryFromContext(ctx context.Context) *kit.OperatorFactory
func ShouldQueryInBodyForGet ¶
Types ¶
type BadRequestError ¶
type BasePathDescriber ¶
type BasePathDescriber interface {
BasePath() string
}
type HttpMiddleware ¶
func MiddlewareChain ¶
func MiddlewareChain(mw ...HttpMiddleware) HttpMiddleware
type HttpRouteMeta ¶
type HttpRouteMeta struct { Route *kit.Route Metas []*OperatorFactoryWithRouteMeta }
Example ¶
os.Setenv(consts.EnvProjectName, "service-example") os.Setenv(consts.EnvProjectVersion, "1.0.0") color.NoColor = true routes := routes.RootRouter.Routes() sort.Slice(routes, func(i, j int) bool { return NewHttpRouteMeta(routes[i]).Key() < NewHttpRouteMeta(routes[j]).Key() }) for i := range routes { rm := NewHttpRouteMeta(routes[i]) fmt.Println(rm.String()) }
Output: GET /demo swagger.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/proxy routes.Proxy 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 GET /demo/v2/proxy routes.ProxyV2
func NewHttpRouteMeta ¶
func NewHttpRouteMeta(route *kit.Route) *HttpRouteMeta
func (*HttpRouteMeta) Key ¶
func (hr *HttpRouteMeta) Key() string
func (*HttpRouteMeta) Log ¶
func (hr *HttpRouteMeta) Log()
func (*HttpRouteMeta) Method ¶
func (hr *HttpRouteMeta) Method() string
func (*HttpRouteMeta) OperatorNames ¶
func (hr *HttpRouteMeta) OperatorNames() string
func (*HttpRouteMeta) Path ¶
func (hr *HttpRouteMeta) Path() string
func (*HttpRouteMeta) String ¶
func (hr *HttpRouteMeta) String() string
type HttpTransport ¶
type HttpTransport struct { ServiceMeta Port int Modifiers []ServerModifier // for modifying http.Server Middlewares []HttpMiddleware // Middlewares https://github.com/gorilla/handlers Vldt validator.Factory // Vldt validator factory Tsfm transformer.Factory // transformer mgr for parameter transforming CertFile string KeyFile string // contains filtered or unexported fields }
func NewHttpTransport ¶
func NewHttpTransport(modifiers ...ServerModifier) *HttpTransport
func (*HttpTransport) ServeContext ¶
func (*HttpTransport) ServeHTTP ¶
func (t *HttpTransport) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*HttpTransport) SetDefault ¶
func (t *HttpTransport) SetDefault()
type MetaOperator ¶
type MetaOperator struct { kit.EmptyOperator // contains filtered or unexported fields }
func BasePath ¶
func BasePath(basePath string) *MetaOperator
func Group ¶
func Group(path string) *MetaOperator
Example ¶
g := Group("/test") fmt.Println(g.Path())
Output: /test
func (*MetaOperator) BasePath ¶
func (g *MetaOperator) BasePath() string
func (*MetaOperator) Path ¶
func (g *MetaOperator) Path() string
type MethodDescriber ¶
type MethodDescriber interface {
Method() string
}
type OperatorFactoryWithRouteMeta ¶
type OperatorFactoryWithRouteMeta struct { *kit.OperatorFactory RouteMeta }
func NewOperatorFactoryWithRouteMeta ¶
func NewOperatorFactoryWithRouteMeta(op kit.Operator, last bool) *OperatorFactoryWithRouteMeta
type PathDescriber ¶
type PathDescriber interface {
Path() string
}
type PostValidator ¶
type PostValidator interface {
PostValidate(badReqErr BadRequestError)
}
type RequestTsfm ¶
type RequestTsfm struct { Type reflect.Type Params map[string][]transformer.ReqParam }
func (*RequestTsfm) DecodeAndValidate ¶
func (t *RequestTsfm) DecodeAndValidate(ctx context.Context, ri httpx.RequestInfo, v interface{}) error
func (*RequestTsfm) DecodeFromRequestInfo ¶
func (t *RequestTsfm) DecodeFromRequestInfo(ctx context.Context, ri httpx.RequestInfo, v interface{}) error
func (*RequestTsfm) NewReqWithContext ¶
func (*RequestTsfm) NewRequest ¶
func (t *RequestTsfm) NewRequest(method, url string, v interface{}) (*http.Request, error)
type RequestTsfmFactory ¶
type RequestTsfmFactory struct { Vldt validator.Factory Tsfm transformer.Factory // contains filtered or unexported fields }
func NewRequestTsfmFactory ¶
func NewRequestTsfmFactory(tsfm transformer.Factory, vldt validator.Factory) *RequestTsfmFactory
Example ¶
factory := NewRequestTsfmFactory(nil, nil) type PlainBody struct { A string `json:"a" validate:"@string[2,]"` Int int `json:"int,omitempty" default:"0" validate:"@int[0,]"` } type Req struct { Protocol types.Protocol `in:"query" name:"protocol,omitempty" default:"HTTP"` QString string `in:"query" name:"string,omitempty" default:"s"` PlainBody PlainBody `in:"body" mime:"plain" validate:"@struct<json>"` } req := &Req{} req.PlainBody.A = "1" rt, err := factory.NewRequestTsfm(bgctx, reflect.TypeOf(req)) if err != nil { panic(err) } statusErr := rt.Params["body"][0].Validator.Validate(req.PlainBody) statusErr.(*vldterr.ErrorSet).Each(func(fieldErr *vldterr.FieldError) { fmt.Println(fieldErr.Field, strconv.Quote(fieldErr.Error.Error())) })
Output: a "string length should be larger than 2, but got invalid value 1"
func (*RequestTsfmFactory) NewRequest ¶
func (f *RequestTsfmFactory) NewRequest(method, url string, v interface{}) (*http.Request, error)
func (*RequestTsfmFactory) NewRequestTsfm ¶
func (f *RequestTsfmFactory) NewRequestTsfm(ctx context.Context, typ reflect.Type) (*RequestTsfm, error)
func (*RequestTsfmFactory) NewRequestWithContext ¶
func (*RequestTsfmFactory) SetDefault ¶
func (f *RequestTsfmFactory) SetDefault()
type ResponseWithError ¶
type ResponseWithError interface {
WriteError(err error)
}
type RouteHandler ¶
type RouteHandler struct { *RequestTsfmFactory *HttpRouteMeta // contains filtered or unexported fields }
func NewRouteHandler ¶
func NewRouteHandler(sm *ServiceMeta, meta *HttpRouteMeta, rtf *RequestTsfmFactory) *RouteHandler
func (*RouteHandler) ServeHTTP ¶
func (hdl *RouteHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP impls http.Handler
type ServerModifier ¶
type ServiceMeta ¶
func ServiceMetaFromContext ¶
func ServiceMetaFromContext(ctx context.Context) ServiceMeta
func (*ServiceMeta) SetDefault ¶
func (s *ServiceMeta) SetDefault()
func (ServiceMeta) String ¶
func (s ServiceMeta) String() string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.