Documentation ¶
Overview ¶
Package apis consists of interfaces for managements endpoints httpgo
Index ¶
- Constants
- Variables
- func AddFieldToJSON(stream *jsoniter.Stream, field string, s string)
- func AddObjectToJSON(stream *jsoniter.Stream, field string, s any)
- func Bearer(name, desc string) string
- func FirstFieldToJSON(stream *jsoniter.Stream, field string, s string)
- func FirstObjectToJSON(stream *jsoniter.Stream, field string, s any)
- func GetGraphSVG(ctx *fasthttp.RequestCtx, buf *bytes.Buffer, opts *d2svg.RenderOpts) (any, error)
- func HandlerForPreflightedCORS(ctx *fasthttp.RequestCtx) (any, error)
- func Indirect(kind reflect.Kind, value reflect.Value) (reflect.Kind, reflect.Value)
- func NewSwaggerContent(schema map[string]any) map[string]any
- func NewqInParam(in string, dto any, multiPart bool, params ...InParam) *qInParam
- func Security(desc string) string
- func StreamBearer(qw422016 *qt422016.Writer, name, desc string)
- func StreamSecurity(qw422016 *qt422016.Writer, desc string)
- func WriteBearer(qq422016 qtio422016.Writer, name, desc string)
- func WriteCustomErrorResponse(ctx *fasthttp.RequestCtx, code int, err error, args map[string]string) (any, error)
- func WriteElemValue(ctx *fasthttp.RequestCtx, src []byte, col dbEngine.Column)
- func WriteMap(value reflect.Value, stream *jsoniter.Stream, title string) any
- func WriteRecordAsJSON(ctx *fasthttp.RequestCtx, rowComma *string) func(values [][]byte, columns []dbEngine.Column) error
- func WriteReflectKind(kind reflect.Kind, value reflect.Value, stream *jsoniter.Stream, ...) any
- func WriteSecurity(qq422016 qtio422016.Writer, desc string)
- func WriteSlice(value reflect.Value, stream *jsoniter.Stream, title string) any
- func WriteStruct(value reflect.Value, stream *jsoniter.Stream, title string) any
- type APIRouteParamsType
- type ApiRoute
- func NewAPIRoute(desc string, method tMethod, params []InParam, needAuth bool, ...) *ApiRoute
- func NewAPIRouteWithDBEngine(desc string, method tMethod, needAuth bool, params []InParam, sqlOrName string, ...) *ApiRoute
- func NewSimpleGETRoute(desc string, params []InParam, fnc ApiSimpleHandler, ...) *ApiRoute
- func NewSimplePOSTRoute(desc string, params []InParam, fnc ApiSimpleHandler, ...) *ApiRoute
- type ApiRouteFuncAuth
- type ApiRouteHandler
- type ApiRoutes
- type ApiSimpleHandler
- type Apis
- type ApisValues
- type BuildRouteOptions
- type CheckDTO
- type CompoundDTO
- type CtxApis
- type DefValueCalcFnc
- type DefValueHeader
- type Docs
- type ErrMethodNotAllowed
- type ErrorResp
- type FncVisit
- type HeaderInParam
- func (h *HeaderInParam) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream)
- func (h *HeaderInParam) Flag(c int) bool
- func (h *HeaderInParam) IsEmpty(ptr unsafe.Pointer) bool
- func (h *HeaderInParam) Precision() (prec int, ok bool)
- func (h *HeaderInParam) Width() (wid int, ok bool)
- func (h *HeaderInParam) Write(b []byte) (n int, err error)
- type InParam
- type MapRoutes
- type ReflectType
- func (r ReflectType) CheckType(ctx *fasthttp.RequestCtx, value string) bool
- func (r ReflectType) ConvertSlice(ctx *fasthttp.RequestCtx, values []string) (any, error)
- func (r ReflectType) ConvertValue(ctx *fasthttp.RequestCtx, value string) (any, error)
- func (r ReflectType) IsSlice() bool
- func (r *ReflectType) WriteMap(value reflect.Value, title string) any
- func (r *ReflectType) WriteReflectKind(kind reflect.Kind, value reflect.Value, sType, title string) any
- func (r *ReflectType) WriteSlice(value reflect.Value, title string) any
- func (r *ReflectType) WriteStruct(value reflect.Value, title string) any
- type RouteDTO
- type SwaggerParam
- type SwaggerUnit
- type TypeInParam
- func (t TypeInParam) CheckType(ctx *fasthttp.RequestCtx, value string) bool
- func (t TypeInParam) ConvertSlice(ctx *fasthttp.RequestCtx, values []string) (any, error)
- func (t TypeInParam) ConvertValue(ctx *fasthttp.RequestCtx, value string) (any, error)
- func (t TypeInParam) Format(s fmt.State, verb rune)
- func (t TypeInParam) IsSlice() bool
- func (t TypeInParam) ReadValue(s string, v any) (any, error)
- func (t TypeInParam) StreamFormat(w *quicktemplate.Writer)
- func (t TypeInParam) StreamRequestType(w *quicktemplate.Writer)
- func (t TypeInParam) StreamTypeString(w *quicktemplate.Writer)
- func (t TypeInParam) String() string
- func (t TypeInParam) TypeString(s fmt.State, verb rune) (int, error)
- type Visit
Constants ¶
const ( ContentTypeJSON = "application/json" ContentTypeMultiPart = "multipart/form-data" )
content types
const ( GET tMethod = iota POST HEAD PUT PATCH DELETE CONNECT OPTIONS TRACE UNKNOWN )
const of tMethod type values
const ( JSONParams = "JSONparams" MultiPartParams = "MultiPartParams" ChildRoutePath = "lastSegment" ApiVersion = "ACC_VERSION" IsWrapHandler = "HAS_HANDLER" ServerName = "name of server httpgo" ServerVersion = "version of server httpgo" Database = "DB" AppStore = "store" )
const of values ctx parameters names
const PARAM_REQUIRED = "is required parameter"
Variables ¶
var ( ErrUnAuthorized = errors.New("user is UnAuthorized") ErrRouteForbidden = errors.New("not allow permission") ErrPathAlreadyExists = errors.New("this path already exists") ErrWrongParamsList = errors.New("wrong params list: %+v") )
errors declaration
Functions ¶
func AddFieldToJSON ¶
func AddObjectToJSON ¶
func FirstFieldToJSON ¶
func FirstObjectToJSON ¶ added in v1.0.11512
func GetGraphSVG ¶ added in v1.2.33
func GetGraphSVG(ctx *fasthttp.RequestCtx, buf *bytes.Buffer, opts *d2svg.RenderOpts) (any, error)
func HandlerForPreflightedCORS ¶ added in v1.2.33
func HandlerForPreflightedCORS(ctx *fasthttp.RequestCtx) (any, error)
func NewSwaggerContent ¶ added in v1.1.10120
func NewqInParam ¶ added in v1.2.22
func StreamBearer ¶ added in v1.2.22
func StreamSecurity ¶ added in v1.2.22
func WriteBearer ¶ added in v1.2.22
func WriteBearer(qq422016 qtio422016.Writer, name, desc string)
func WriteCustomErrorResponse ¶ added in v1.2.67
func WriteElemValue ¶ added in v1.0.11512
func WriteElemValue(ctx *fasthttp.RequestCtx, src []byte, col dbEngine.Column)
func WriteRecordAsJSON ¶ added in v1.1.10119
func WriteReflectKind ¶ added in v1.1.10120
func WriteSecurity ¶ added in v1.2.22
func WriteSecurity(qq422016 qtio422016.Writer, desc string)
func WriteSlice ¶ added in v1.1.10120
Types ¶
type APIRouteParamsType ¶
type APIRouteParamsType interface { fmt.Stringer CheckType(ctx *fasthttp.RequestCtx, value string) bool ConvertValue(ctx *fasthttp.RequestCtx, value string) (any, error) ConvertSlice(ctx *fasthttp.RequestCtx, values []string) (any, error) IsSlice() bool }
APIRouteParamsType encapsulates types operation for apis parameters`
type ApiRoute ¶
type ApiRoute struct { Desc string `json:"descriptor"` DTO RouteDTO `json:"DTO"` Fnc ApiRouteHandler `json:"-"` FncAuth auth.FncAuth `json:"-"` FncIsForbidden func(ctx *fasthttp.RequestCtx) bool `json:"-"` TestFncAuth auth.FncAuth `json:"-"` Method tMethod `json:"method,string"` Multipart bool NeedAuth bool OnlyAdmin bool OnlyLocal bool WithCors bool IsAJAXRequest bool Params []InParam `json:"parameters,omitempty"` Resp any `json:"response,omitempty"` }
ApiRoute implement endpoint info & handler on request
func NewAPIRoute ¶
func NewAPIRoute(desc string, method tMethod, params []InParam, needAuth bool, fnc ApiRouteHandler, resp any, Options ...BuildRouteOptions) *ApiRoute
NewAPIRoute create customizing ApiRoute
func NewAPIRouteWithDBEngine ¶ added in v1.0.11512
func NewAPIRouteWithDBEngine(desc string, method tMethod, needAuth bool, params []InParam, sqlOrName string, Options ...BuildRouteOptions) *ApiRoute
NewAPIRouteWithDBEngine create customizing ApiRoute
func NewSimpleGETRoute ¶ added in v1.0.11512
func NewSimpleGETRoute(desc string, params []InParam, fnc ApiSimpleHandler, Options ...BuildRouteOptions) *ApiRoute
NewSimpleGETRoute create GET ApiRoute with minimal requirements
func NewSimplePOSTRoute ¶ added in v1.0.11512
func NewSimplePOSTRoute(desc string, params []InParam, fnc ApiSimpleHandler, Options ...BuildRouteOptions) *ApiRoute
NewSimplePOSTRoute create POST ApiRoute with minimal requirements
func (*ApiRoute) CheckAndRun ¶
func (route *ApiRoute) CheckAndRun(ctx *fasthttp.RequestCtx, fncAuth auth.FncAuth) (resp any, err error)
CheckAndRun check & run route handler
func (*ApiRoute) CheckParams ¶
CheckParams check param of request
type ApiRouteFuncAuth ¶
type ApiRouteFuncAuth func(ctx *fasthttp.RequestCtx) error
type ApiRouteHandler ¶
type ApiRouteHandler func(ctx *fasthttp.RequestCtx) (any, error)
type ApiSimpleHandler ¶ added in v1.0.11512
type Apis ¶
type Apis struct { *sync.RWMutex Ctx CtxApis Https bool StartTime time.Time // contains filtered or unexported fields }
Apis encapsulates REST API configuration and endpoints in calling it checks for the presence, validation of parameters and access privileges
func NewApis ¶
NewApis create new Apis from list of routes, environment values configuration & authentication method
func (*Apis) AddRoutes ¶
AddRoutes add routes to Apis for handling service return slice with name routes which not adding
func (*Apis) DefaultRoutes ¶ added in v1.2.1
func (*Apis) Handler ¶
func (a *Apis) Handler(ctx *fasthttp.RequestCtx)
Handler find route on request, check & run
type ApisValues ¶ added in v1.0.11512
type ApisValues string
type BuildRouteOptions ¶
type BuildRouteOptions func(route *ApiRoute)
BuildRouteOptions implement 'Functional Option' pattern for ApiRoute settings
func MultiPartForm ¶
func MultiPartForm() BuildRouteOptions
MultiPartForm set flag of multipart checking
func OnlyLocal ¶
func OnlyLocal() BuildRouteOptions
OnlyLocal set flag of only local response routing
func RouteAuth ¶
func RouteAuth(fncAuth auth.FncAuth) BuildRouteOptions
RouteAuth set custom auth method on ApiRoute
func RouteNeedAuth ¶ added in v1.0.11512
func RouteNeedAuth() BuildRouteOptions
RouteNeedAuth set auth on ApiRoute
func RouteOnlyAdmin ¶ added in v1.0.11512
func RouteOnlyAdmin() BuildRouteOptions
RouteOnlyAdmin set admin access for ApiRoute
type CheckDTO ¶ added in v1.0.11512
type CheckDTO interface {
CheckParams(ctx *fasthttp.RequestCtx, badParams map[string]string) bool
}
CheckDTO must implement checking parameters of route
type CompoundDTO ¶ added in v1.0.11512
type CompoundDTO interface {
ReadParams(ctx *fasthttp.RequestCtx)
}
CompoundDTO fills properties of DTO from ctx.UserValue
type CtxApis ¶
func NewCtxApis ¶
type DefValueCalcFnc ¶
type DefValueCalcFnc func(ctx *fasthttp.RequestCtx) any
func (DefValueCalcFnc) Expect ¶ added in v1.2.93
func (d DefValueCalcFnc) Expect() string
func (DefValueCalcFnc) FormatDoc ¶ added in v1.2.137
func (d DefValueCalcFnc) FormatDoc() string
func (DefValueCalcFnc) RequestType ¶ added in v1.2.93
func (d DefValueCalcFnc) RequestType() string
type DefValueHeader ¶ added in v1.2.93
type DefValueHeader struct {
// contains filtered or unexported fields
}
func NewDefValueHeader ¶ added in v1.2.93
func NewDefValueHeader(header, defValue string) DefValueHeader
func (DefValueHeader) ConvertValue ¶ added in v1.2.93
func (d DefValueHeader) ConvertValue(ctx *fasthttp.RequestCtx) string
func (DefValueHeader) Expect ¶ added in v1.2.93
func (d DefValueHeader) Expect() string
func (DefValueHeader) FormatDoc ¶ added in v1.2.137
func (d DefValueHeader) FormatDoc() string
func (DefValueHeader) RequestType ¶ added in v1.2.93
func (d DefValueHeader) RequestType() string
type ErrMethodNotAllowed ¶ added in v1.2.118
type ErrMethodNotAllowed struct {
// contains filtered or unexported fields
}
func (*ErrMethodNotAllowed) Error ¶ added in v1.2.118
func (e *ErrMethodNotAllowed) Error() string
type ErrorResp ¶ added in v1.0.11512
func NewErrorResp ¶ added in v1.0.11512
func NewErrorRespBadDTO ¶ added in v1.0.11512
func NewErrorRespBadDTO() *ErrorResp
type HeaderInParam ¶ added in v1.2.93
type HeaderInParam struct { TypeInParam // contains filtered or unexported fields }
func (*HeaderInParam) Encode ¶ added in v1.2.93
func (h *HeaderInParam) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream)
func (*HeaderInParam) Flag ¶ added in v1.2.137
func (h *HeaderInParam) Flag(c int) bool
func (*HeaderInParam) IsEmpty ¶ added in v1.2.93
func (h *HeaderInParam) IsEmpty(ptr unsafe.Pointer) bool
func (*HeaderInParam) Precision ¶ added in v1.2.137
func (h *HeaderInParam) Precision() (prec int, ok bool)
func (*HeaderInParam) Width ¶ added in v1.2.137
func (h *HeaderInParam) Width() (wid int, ok bool)
type InParam ¶
type InParam struct { Name string Desc string Req bool PartReq []string Type APIRouteParamsType DefValue any IncompatibleWiths []string TestValue string }
InParam implement params on request
func (*InParam) Check ¶ added in v1.1.10120
func (param *InParam) Check(ctx *fasthttp.RequestCtx, badParams map[string]string)
Check params of ctx
func (*InParam) WithNotRequired ¶ added in v1.2.2
type MapRoutes ¶ added in v1.0.310
type MapRoutes map[mapRoute]*ApiRoute
func NewMapRoutes ¶ added in v1.0.310
func NewMapRoutes() MapRoutes
NewMapRoutes create APIRotes instance
func NewMapRoutesWithAjaxWrap ¶ added in v1.2.93
func NewMapRoutesWithAjaxWrap(endpoints []ApiRoutes, wrapHandler ApiRouteHandler, chgRoute func(*ApiRoute)) MapRoutes
func (MapRoutes) GetRoute ¶ added in v1.0.310
func (r MapRoutes) GetRoute(ctx *fasthttp.RequestCtx) (*ApiRoute, error)
func (MapRoutes) GetTestRouteSuffix ¶ added in v1.0.310
type ReflectType ¶ added in v1.1.10120
func NewReflectType ¶ added in v1.1.10120
func NewReflectType(value any) *ReflectType
func (ReflectType) CheckType ¶ added in v1.1.10120
func (r ReflectType) CheckType(ctx *fasthttp.RequestCtx, value string) bool
func (ReflectType) ConvertSlice ¶ added in v1.1.10120
func (r ReflectType) ConvertSlice(ctx *fasthttp.RequestCtx, values []string) (any, error)
func (ReflectType) ConvertValue ¶ added in v1.1.10120
func (r ReflectType) ConvertValue(ctx *fasthttp.RequestCtx, value string) (any, error)
func (ReflectType) IsSlice ¶ added in v1.1.10120
func (r ReflectType) IsSlice() bool
func (*ReflectType) WriteMap ¶ added in v1.1.10120
func (r *ReflectType) WriteMap(value reflect.Value, title string) any
func (*ReflectType) WriteReflectKind ¶ added in v1.1.10120
func (*ReflectType) WriteSlice ¶ added in v1.1.10120
func (r *ReflectType) WriteSlice(value reflect.Value, title string) any
func (*ReflectType) WriteStruct ¶ added in v1.1.10120
func (r *ReflectType) WriteStruct(value reflect.Value, title string) any
type SwaggerParam ¶ added in v1.1.10120
func NewSwaggerArray ¶ added in v1.1.10120
func NewSwaggerArray(desc string, props ...any) SwaggerParam
func NewSwaggerArray1 ¶ added in v1.1.10120
func NewSwaggerArray1(props any, name string) SwaggerParam
func NewSwaggerObject ¶ added in v1.1.10120
func NewSwaggerObject(props any, name string) SwaggerParam
func NewSwaggerObjectRoot ¶ added in v1.1.10120
func NewSwaggerObjectRoot(props any) SwaggerParam
func NewSwaggerParam ¶ added in v1.1.10120
func NewSwaggerParam(name, in, typ, f string) SwaggerParam
type SwaggerUnit ¶ added in v1.1.10120
type SwaggerUnit struct { Properties []spec.SchemaProps `json:"properties,omitempty"` Items any `json:"items,omitempty"` Type string }
type TypeInParam ¶
TypeInParam has type definition of params ApiRoute
func NewSliceTypeInParam ¶
func NewSliceTypeInParam(bk types.BasicKind) TypeInParam
NewSliceTypeInParam create TypeInParam for slice
func NewStructInParam ¶ added in v1.0.11512
func NewStructInParam(dto RouteDTO) TypeInParam
NewStructInParam create TypeInParam for struct
func NewTypeInParam ¶
func NewTypeInParam(bk types.BasicKind) TypeInParam
NewTypeInParam create TypeInParam
func (TypeInParam) CheckType ¶
func (t TypeInParam) CheckType(ctx *fasthttp.RequestCtx, value string) bool
CheckType check of value computable with the TypeInParam
func (TypeInParam) ConvertSlice ¶
func (t TypeInParam) ConvertSlice(ctx *fasthttp.RequestCtx, values []string) (any, error)
func (TypeInParam) ConvertValue ¶
func (t TypeInParam) ConvertValue(ctx *fasthttp.RequestCtx, value string) (any, error)
ConvertValue convert value according to TypeInParam's type
func (TypeInParam) IsSlice ¶
func (t TypeInParam) IsSlice() bool
func (TypeInParam) ReadValue ¶ added in v1.0.11512
func (t TypeInParam) ReadValue(s string, v any) (any, error)
func (TypeInParam) StreamFormat ¶ added in v1.2.22
func (t TypeInParam) StreamFormat(w *quicktemplate.Writer)
func (TypeInParam) StreamRequestType ¶ added in v1.2.22
func (t TypeInParam) StreamRequestType(w *quicktemplate.Writer)
func (TypeInParam) StreamTypeString ¶ added in v1.2.22
func (t TypeInParam) StreamTypeString(w *quicktemplate.Writer)
func (TypeInParam) String ¶
func (t TypeInParam) String() string