Documentation ¶
Index ¶
- Constants
- Variables
- func GetPreferredResponseFormat(typ reflect.Type) spec.MediaTypeTitle
- func IsCorrectInWay(way InWay) bool
- func IsTypeOfWebContext(typ reflect.Type) bool
- func IsTypeOfWebController(typ reflect.Type) bool
- func IsTypeOfWebMiddleware(typ reflect.Type) bool
- func IsTypeOfWebServer(typ reflect.Type) bool
- func LaunchGin(webServerTypeOrInst any, others ...any) error
- func PrepareGin(webServerTypeOrInst any, others ...any) (*gin.Engine, dij.DependencyReferencePtr, error)
- type BaseParamField
- type HandlerSpec
- type HandlerWrapper
- type HandlerWrapperPurpose
- type InWay
- type OpenApiConfig
- func (o *OpenApiConfig) AppendApiKeyAuth(name string, paramIn InWay, paramName string) *OpenApiConfig
- func (o *OpenApiConfig) AppendBasicAuth(name string) *OpenApiConfig
- func (o *OpenApiConfig) AppendBearerAuth(name string) *OpenApiConfig
- func (o *OpenApiConfig) AppendSecurityScheme(name string, scheme spec.SecurityScheme) *OpenApiConfig
- func (o *OpenApiConfig) ApplyDefaultValues()
- func (o *OpenApiConfig) Enable() *OpenApiConfig
- func (o *OpenApiConfig) SetAddress(addr string) *OpenApiConfig
- func (o *OpenApiConfig) SetDescription(description string) *OpenApiConfig
- func (o *OpenApiConfig) SetDocPath(path string) *OpenApiConfig
- func (o *OpenApiConfig) SetEnabled(en bool) *OpenApiConfig
- func (o *OpenApiConfig) SetPort(port int) *OpenApiConfig
- func (o *OpenApiConfig) SetTitle(title string) *OpenApiConfig
- func (o *OpenApiConfig) SetVersion(version string) *OpenApiConfig
- func (o *OpenApiConfig) UseHttpAndHttps() *OpenApiConfig
- func (o *OpenApiConfig) UseHttpOnly() *OpenApiConfig
- func (o *OpenApiConfig) UseHttpsOnly() *OpenApiConfig
- type RuntimeEnv
- type WebConfig
- func (c *WebConfig) ApplyDefaultValues()
- func (c *WebConfig) SetAddress(addr string) *WebConfig
- func (c *WebConfig) SetBasePath(path string) *WebConfig
- func (c *WebConfig) SetDefaultWriter(writer io.Writer) *WebConfig
- func (c *WebConfig) SetDependentRef(key string, ref any) *WebConfig
- func (c *WebConfig) SetOpenApi(f func(o *OpenApiConfig)) *WebConfig
- func (c *WebConfig) SetPort(port int) *WebConfig
- func (c *WebConfig) SetRtMode(mode RuntimeEnv) *WebConfig
- type WebContext
- type WebContextSpec
- type WebController
- type WebControllerSpec
- type WebError
- type WebMiddleware
- type WebMiddlewareSpec
- type WebRouter
- type WebRoutes
- type WebServer
- type WebServerSpec
Constants ¶
View Source
const ( DefaultWebServerPort = 8000 DefaultValidatorTagName = "validate" )
View Source
const ( HttpTagName = "http" DescriptionTagName = "description" SecurityTagName = "security" RefKeyForWebConfig = "_.webserver.config" RefKeyForWebSpecRecord = "_.webserver.spec.record" RefKeyForWebValidator = "_.webserver.validator" RefKeyForWebDijRef = "_.webserver.dij.ref" )
Variables ¶
View Source
var TypeOfWebError reflect.Type
View Source
var WebCtxType reflect.Type
Functions ¶
func GetPreferredResponseFormat ¶ added in v0.0.3
func GetPreferredResponseFormat(typ reflect.Type) spec.MediaTypeTitle
func IsCorrectInWay ¶ added in v0.0.3
func IsTypeOfWebContext ¶
func IsTypeOfWebController ¶
func IsTypeOfWebMiddleware ¶
func IsTypeOfWebServer ¶
func LaunchGin ¶
LaunchGin launches a web server. The webServerTypeOrInst should be a struct type which is embedded WebServer or an instance (pointer) of a struct type which is embedded WebServer.
A new web server definition:
type WebSer struct { WebServer } func main() { webTyp = reflect.TypeOf(WebSer{}) LaunchGin(webTyp) // launch by type webInst = &WebSer{} LaunchGin(webInst) // launch by instance }
func PrepareGin ¶
Types ¶
type BaseParamField ¶ added in v0.0.3
type BaseParamField struct { Index int FieldSpec reflect.StructField ExistsTag bool // exists http tag Attrs StructTagAttrs // come from http tag PreferredName string Description string }
func (*BaseParamField) PreferredMediaTypeTitleForResponse ¶ added in v0.0.3
func (c *BaseParamField) PreferredMediaTypeTitleForResponse() spec.MediaTypeTitle
func (*BaseParamField) SupportedMediaTypesForRequest ¶ added in v0.0.3
func (c *BaseParamField) SupportedMediaTypesForRequest() []spec.MediaTypeSupport
type HandlerSpec ¶ added in v0.0.3
type HandlerSpec struct { Purpose HandlerWrapperPurpose MethodType reflect.Method BaseParamType reflect.Type Method string // lower case, ex: get, post, etc. Path string // lower cast path, does it need to support case-sensitive? InFields []BaseParamField MiddlewareNames []string OutFields []BaseParamField CtxAttrs StructTagAttrs // tag attr come from the base field in InFields Description string // description comes from the base field in InFields Security string // security comes from the tag of base field }
func (*HandlerSpec) UpperMethod ¶ added in v0.0.3
func (s *HandlerSpec) UpperMethod() string
type HandlerWrapper ¶
type HandlerWrapper struct { Spec HandlerSpec Handler gin.HandlerFunc }
func GenerateHandlerWrappers ¶
func GenerateHandlerWrappers(instPtr any, purpose HandlerWrapperPurpose, refPtr dij.DependencyReferencePtr) []HandlerWrapper
GenerateHandlerWrappers generates handler for the instance TODO: consider to cache result for same instance.
func (*HandlerWrapper) ConcatOpenapiPath ¶ added in v0.0.3
func (w *HandlerWrapper) ConcatOpenapiPath(basePath string) (fullPath string, params []string)
func (*HandlerWrapper) ReqMethod ¶ added in v0.0.3
func (w *HandlerWrapper) ReqMethod() string
func (*HandlerWrapper) ReqPath ¶ added in v0.0.3
func (w *HandlerWrapper) ReqPath() string
func (*HandlerWrapper) UpperReqMethod ¶ added in v0.0.3
func (w *HandlerWrapper) UpperReqMethod() string
type HandlerWrapperPurpose ¶
type HandlerWrapperPurpose int
const ( HandlerForReq HandlerWrapperPurpose = iota // for http request HandlerForMid // for middleware )
func (HandlerWrapperPurpose) BaseKey ¶ added in v0.0.3
func (h HandlerWrapperPurpose) BaseKey() string
func (HandlerWrapperPurpose) Regexp ¶ added in v0.0.3
func (h HandlerWrapperPurpose) Regexp() *regexp.Regexp
type InWay ¶ added in v0.0.3
type InWay = string
const ( InHeaderWay InWay = "header" // one kind of way for parameter InCookieWay InWay = "cookie" // one kind of way for parameter InQueryWay InWay = "query" // one kind of way for parameter InPathWay InWay = "path" // one kind of way for parameter InBodyWay InWay = "body" // one kind of way for request body )
type OpenApiConfig ¶ added in v0.0.3
type OpenApiConfig struct { Enabled bool // Default is false Title string Description string Version string Schemes []string // ex: "http", "https". Default is "https". Address string Port int DocPath string // Default is "doc" SecuritySchemes spec.SecuritySchemes }
func (*OpenApiConfig) AppendApiKeyAuth ¶ added in v0.1.0
func (o *OpenApiConfig) AppendApiKeyAuth(name string, paramIn InWay, paramName string) *OpenApiConfig
func (*OpenApiConfig) AppendBasicAuth ¶ added in v0.1.0
func (o *OpenApiConfig) AppendBasicAuth(name string) *OpenApiConfig
func (*OpenApiConfig) AppendBearerAuth ¶ added in v0.1.0
func (o *OpenApiConfig) AppendBearerAuth(name string) *OpenApiConfig
func (*OpenApiConfig) AppendSecurityScheme ¶ added in v0.1.0
func (o *OpenApiConfig) AppendSecurityScheme(name string, scheme spec.SecurityScheme) *OpenApiConfig
func (*OpenApiConfig) ApplyDefaultValues ¶ added in v0.0.3
func (o *OpenApiConfig) ApplyDefaultValues()
func (*OpenApiConfig) Enable ¶ added in v0.0.3
func (o *OpenApiConfig) Enable() *OpenApiConfig
func (*OpenApiConfig) SetAddress ¶ added in v0.0.8
func (o *OpenApiConfig) SetAddress(addr string) *OpenApiConfig
func (*OpenApiConfig) SetDescription ¶ added in v0.0.5
func (o *OpenApiConfig) SetDescription(description string) *OpenApiConfig
func (*OpenApiConfig) SetDocPath ¶ added in v0.0.3
func (o *OpenApiConfig) SetDocPath(path string) *OpenApiConfig
func (*OpenApiConfig) SetEnabled ¶ added in v0.0.3
func (o *OpenApiConfig) SetEnabled(en bool) *OpenApiConfig
func (*OpenApiConfig) SetPort ¶ added in v0.0.8
func (o *OpenApiConfig) SetPort(port int) *OpenApiConfig
func (*OpenApiConfig) SetTitle ¶ added in v0.0.5
func (o *OpenApiConfig) SetTitle(title string) *OpenApiConfig
func (*OpenApiConfig) SetVersion ¶ added in v0.0.5
func (o *OpenApiConfig) SetVersion(version string) *OpenApiConfig
func (*OpenApiConfig) UseHttpAndHttps ¶ added in v0.0.3
func (o *OpenApiConfig) UseHttpAndHttps() *OpenApiConfig
func (*OpenApiConfig) UseHttpOnly ¶ added in v0.0.3
func (o *OpenApiConfig) UseHttpOnly() *OpenApiConfig
func (*OpenApiConfig) UseHttpsOnly ¶ added in v0.0.3
func (o *OpenApiConfig) UseHttpsOnly() *OpenApiConfig
type RuntimeEnv ¶ added in v0.0.3
type RuntimeEnv string
const ( RtProd RuntimeEnv = "prod" RtDev RuntimeEnv = "dev" RtDebug RuntimeEnv = "debug" RtTest RuntimeEnv = "test" )
func (RuntimeEnv) IsInOnlyEnv ¶ added in v0.0.3
func (r RuntimeEnv) IsInOnlyEnv(onlyEnv string) bool
type WebConfig ¶ added in v0.0.3
type WebConfig struct { Address string // default is localhost Port int // if not setting, 8000 will be used. MaxConn int BasePath string // Default is empty ValidatorTagName string // Default is "validate", but go-gin preferred "binding". DependentRefs map[string]any RtEnv RuntimeEnv // Default is "dev" OpenApi OpenApiConfig DefaultWriter io.Writer }
func NewWebConfig ¶ added in v0.0.3
func NewWebConfig() *WebConfig
NewWebConfig returns an instance with default values.
func (*WebConfig) ApplyDefaultValues ¶ added in v0.0.3
func (c *WebConfig) ApplyDefaultValues()
ApplyDefaultValues if some properties are zero or empty, it will set the default values.
func (*WebConfig) SetAddress ¶ added in v0.0.3
func (*WebConfig) SetBasePath ¶ added in v0.0.3
func (*WebConfig) SetDefaultWriter ¶ added in v0.0.4
func (*WebConfig) SetDependentRef ¶ added in v0.0.4
func (*WebConfig) SetOpenApi ¶ added in v0.0.3
func (c *WebConfig) SetOpenApi(f func(o *OpenApiConfig)) *WebConfig
func (*WebConfig) SetRtMode ¶ added in v0.0.3
func (c *WebConfig) SetRtMode(mode RuntimeEnv) *WebConfig
type WebContext ¶
func (*WebContext) GetRequestHeader ¶ added in v0.0.4
func (c *WebContext) GetRequestHeader(key string) string
func (*WebContext) GetRequestValue ¶
func (c *WebContext) GetRequestValue(key string, instPtr any) (exists bool)
func (*WebContext) GetRequestValueForType ¶
type WebContextSpec ¶
type WebController ¶
type WebController struct {
// contains filtered or unexported fields
}
func (*WebController) GetRef ¶ added in v0.0.5
func (w *WebController) GetRef(keyOfRef string) (any, bool)
func (*WebController) SetupRouter ¶ added in v0.0.3
func (w *WebController) SetupRouter(_ WebRouter, _ ...any)
type WebControllerSpec ¶
type WebError ¶ added in v0.0.3
type WebError struct { Message string `json:"message"` Code string `json:"code"` // contains filtered or unexported fields }
func ToWebError ¶ added in v0.0.3
type WebMiddleware ¶
type WebMiddleware struct { }
type WebMiddlewareSpec ¶
type WebMiddlewareSpec interface {
// contains filtered or unexported methods
}
type WebServer ¶
type WebServer struct {
WebController
}
type WebServerSpec ¶
type WebServerSpec interface { WebControllerSpec // contains filtered or unexported methods }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.