package
0.15.1
Repository: https://github.com/cisco-open/go-lanai.git
Documentation: pkg.go.dev

# README

Web

The web module enables the application to become a web application. When this module is used, a gin web server is started. The web module allows endpoints and middlewares to be added to the web server using dependency injection. The web module abstracts away the boilerplate code of running the web server, allowing application code to focus on writing the endpoints.

The web module achieves this by providing the following components:

NewEngine - this is a wrapped gin web server. Our wrapper allows the request to be pre-processed before being handled by gin web server. The only request pre-processor we currently provide is a CachedRequestPreProcessors. This is used during the auth process so that the auth server can replay the original request after the session is authenticated.

NewRegistrar - this registrar is used by other packages to register middlewares, endpoints, error translations etc. This registrar is provided so that any other feature that wants to add to the web server can do so via the registrar.

The web module also has a fx.Invoke. Because of it, when the web module is activated, it starts the web server and adds all the component in the registrar on it when the application starts.

Web Tests

Examples on how to write web tests can be found here.

FAQs:

  1. When running web-tests, if you ever encounter the following error:
pq: no database or schema specified

Follow the documentation here to configure local database for testing.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

BindServerProperties create and bind a ServerProperties using default prefix.
No description provided by the author
No description provided by the author
ContextPath returns the "server.context-path" from properties with leading "/".
No description provided by the author
DefaultErrorHandling implement error handling logics at last resort, in case errors are not properly handled downstream.
No description provided by the author
No description provided by the author
No description provided by the author
GinBindingRequestDecoder is a DecodeRequestFunc utilizing gin.Context's binding capabilities.
GinContext returns *gin.Context which either contained in the context or is the given context itself.
GinContextMerger is a Gin middleware that merge Request.Context() with gin.Context, allowing values in gin.Context also available via Request.Context().Value().
HttpRequest returns *http.Request associated with given context.
No description provided by the author
No description provided by the author
No description provided by the author
MustGinContext returns *gin.Context like GinContext but panic if not found.
MustHttpRequest returns *http.Request associated with given context, panic if not found.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewHttpGinHandlerFunc integrate http.HandlerFunc with GIN handler.
No description provided by the author
No description provided by the author
No description provided by the author
NewMiddlewareGinMapping create a MiddlewareGinMapping with gin.HandlerFunc It's recommended to use middleware.MappingBuilder instead of this function: e.g.
NewMiddlewareMapping create a MiddlewareMapping with http.HandlerFunc It's recommended to use middleware.MappingBuilder instead of this function: e.g.
NewMvcMapping create a MvcMapping It's recommended to use rest.MappingBuilder or template.MappingBuilder instead of this function: e.g.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewServerProperties create a ServerProperties with default values.
NewSimpleGinLogFormatter is a convenient function that returns a simple gin.LogFormatter without request filtering Normally, LoggingCustomizer configures more complicated gin logging schema automatically.
NewSimpleGinMapping create a SimpleGinMapping.
NewSimpleMapping create a SimpleMapping.
NormalizedPath removes path parameter name from path.
OrderedFS returns a fs.FS that also implements order.Ordered if the given fs.FS is already implement the order.Ordered, "defaultOrder" is ignored.
PropertiesAware is a Gin middleware mandatory for all mappings.
SetKV set a kv pair to given context if: - The context is a utils.MutableContext - The context has utils.MutableContext as parent/ancestors - The context contains *gin.Context The value then can be obtained via context.Context.Value(key) This function uses utils.FindMutableContext and GinContext() to find KV storage.
No description provided by the author
No description provided by the author
Validator returns the global validator for binding.

# Constants

goland:noinspection GoUnusedConst.
No description provided by the author
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
min int.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
max int.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
goland:noinspection GoUnusedConst.
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GinErrorHandlingCustomizer implements Customizer.
HttpError implements error, json.Marshaler, StatusCoder, Headerer Note: Do not use HttpError as a map key, because is is not hashable (it contains http.Header which is a map).
No description provided by the author
LazyHeaderWriter makes sure that status code and headers is overwritten at last second (when invoke Write([]byte) (int, error).
LoggingCustomizer implements Customizer and PostInitCustomizer.
LoggingLevelProperties is used to override logging level on particular set of paths the LoggingProperties.Pattern support wildcard and should not include "context-path" the LoggingProperties.Method is space separated values.
No description provided by the author
MergedFS implements fs.FS and fs.GlobFS.
PriorityGinContextCustomizer implements Customizer and order.PriorityOrdered.
RecoveryCustomizer implements Customizer.
No description provided by the author
No description provided by the author
Route contains information needed for registering handler func in gin.Engine.
No description provided by the author
Validate is a thin wrapper around validator/v10, which prevent modifying TagName.
No description provided by the author

# Interfaces

BodyContainer is an additional interface that a user response object or error could implement.
ConditionalMiddleware is an additional interface that a Middleware can implement to control when the middleware is applied.
Controller is usually implemented by user-domain types to provide a group of HTTP handling logics.
Customizer is invoked by Registrar at the beginning of initialization, customizers can register anything except for additional customizers If a customizer retains the given context in anyway, it should also implement PostInitCustomizer to release it.
ErrorTranslateMapping defines how errors should be handled before it's rendered into http.ResponseWriter.
ErrorTranslator can be registered via web.Registrar it will contribute our MvcMapping's error handling process.
Headerer is an additional interface that a user response object or error could implement.
Mapping is generic interface for all kind of HTTP mappings.
Middleware defines a http.HandlerFunc to be used by MiddlewareMapping and middleware.MappingBuilder.
MiddlewareGinMapping is a MiddlewareMapping that supported by gin.HandlerFunc See middleware.MappingBuilder.
MiddlewareMapping defines middlewares that applies to all or selected set (via Matcher and Condition) of requests.
MvcMapping defines HTTP handling that follows MVC pattern: 1.
PostInitCustomizer is invoked by Registrar after initialization, register anything in PostInitCustomizer.PostInit would cause error or takes no effect.
RequestMatcher is a typed ChainableMatcher that accept *http.Request or http.Request.
No description provided by the author
RequestRewriter handles request rewrite.
RoutedMapping defines dynamic HTTP handling with specific HTTP Route (path and method) and optionally a RequestMatcher as condition.
RouteMatcher is a typed ChainableMatcher that accept *Route or Route.
SimpleGinMapping is a SimpleMapping that supported by gin.HandlerFunc See mapping.MappingBuilder.
SimpleMapping endpoints that are directly implemented as HandlerFunc.
StaticMapping defines static assets handling.
StatusCoder is an additional interface that a user response object or error could implement.

# Type aliases

DecodeRequestFunc extracts a payload from a http.Request.
No description provided by the author
EncodeErrorFunc is responsible for encoding an error to the ResponseWriter.
No description provided by the author
EncodeResponseFunc encodes a user response object into http.ResponseWriter.
EndpointMapping defines REST API mapping.
No description provided by the author
ErrorTranslateFunc is similar to ErrorTranslator in function format.
MvcHandlerFunc is the generic function to be used for MvcMapping.
No description provided by the author
TemplateMapping defines templated MVC mapping.