Documentation
¶
Index ¶
- func MultiErrorsSlice(err error) []string
- func NewDirFS(rootDir string, fsys fs.FS) *dirFS
- func NewPostgresConnection(param *ConnectionParams) *sql.DB
- func UseSchema(schema string) iris.Handler
- type App
- type AppOptions
- type ConnectionParams
- type MultiErrorResponse
- type MultiErrors
- type WebApp
- type WebAppOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MultiErrorsSlice ¶
MultiErrorsSlice returns a representation of the stacked errors as a slice of string. It is made to generate a slice of string from an error either it is a basic error or a MultiErrors.
MultiErrorsSlice is usefull when returning a list of error in the API response without relying on the MultiErrorResponse response format. Typically, it can be used to generate a list of validation error in a Problem response (rfc 7807 : https://datatracker.ietf.org/doc/html/rfc7807)
func NewPostgresConnection ¶
func NewPostgresConnection(param *ConnectionParams) *sql.DB
NewPostgresConnection creates a new sql.DB compatible Postgres connection After having opened the connection, NewPostgresConnection tries to ping the database and wait for a timeout.
NewPostgresConnection uses *ConnectionParams to open the connection.
func UseSchema ¶
func UseSchema(schema string) iris.Handler
UseSchema is a per-route middleware that validates the input payload following the provided Json Schema The aim of this middleware is to avoid data basic validation in your own middleware.
example :
app.Post("/entity", lever.UseSchema(`{"type": "object"}`), postEntityHandler) ... func postEntityHandler(ctx iris.Context) { ctx.Application().Logger().Info("payload is valid") //put your business logic here }
Types ¶
type App ¶
type App struct { *iris.Application // contains filtered or unexported fields }
func NewDefaultApp ¶
func NewDefaultApp() *App
NewDefaultApp creates a new App with the following default parameters * CORS are disabled
func (*App) Run ¶
func (app *App) Run()
Run runs the app with TLS (https). Serving http request through https is the default mode. When the app is ran locally or on a remote server that doesn't have a public domain name, a certificate is generated automatically
type AppOptions ¶
type AppOptions struct {
Cors bool
}
AppOptions handles the App configuration. AppOptions should be used when creating a new App with custom parameters like * Cors enabled/disabled
type ConnectionParams ¶
type ConnectionParams struct { Host string Port string User string Password string DBName string TimeOut time.Duration }
ConnectionParams represents the database connection parameters The following parameters are needed : Host, Port, User, Password, DBName
type MultiErrorResponse ¶
type MultiErrorResponse struct {
Err []string `json:"errors,omitempty"`
}
MultiErrorResponse represents a typical api response in case of error. In this case, the response looks like :
{ "errors": [ "first error", "second error" ] }
and should be associated with the right status code (ex : 400, bad request)
func MultiErrorsJSON ¶
func MultiErrorsJSON(err error) MultiErrorResponse
MultiErrorsJSON generates a MultiErrorResponse ready to be marshalled as JSON It should typically be used when an API returns a error code (ex : 400 bad request) to list all the errors in the server response.
MultiErrorsJSON supports both error and MultiErrors type. Thus, it can be used right before returning the HTTP response without any consideration of either there are multiple errors to return or not. Example : err := Validate(myVar) ctx.StopWithJSON(400, lever.MultiErrorsJSON(err))
type MultiErrors ¶
type MultiErrors struct {
// contains filtered or unexported fields
}
MultiErrors helps handling multiple errors. It aims to be used especially when validating some input that may contains multiple errors One may choose to return an error (bad request) when the first validation error occurs. But Multierrors helps stacking the validation errors and return them all at once.
func (*MultiErrors) Append ¶
func (merr *MultiErrors) Append(errs ...error) *MultiErrors
Append append a new error to the error stack already contained in the Multierror. A typical use of the Append function may look likes this : errs := lever.NewMultiErrors().Append(errors.New("an error"))
func (*MultiErrors) Error ¶
func (merr *MultiErrors) Error() string
Error return a concatenation of the error stack as a string.
func (*MultiErrors) ListAsString ¶
func (merr *MultiErrors) ListAsString() []string
ListAsString returns the list of stacked error as a slice of strings.
type WebApp ¶
type WebApp struct { *App // contains filtered or unexported fields }
func NewDefaultWebApp ¶
func NewDefaultWebApp(assetsFS *dirFS, templatesFS *dirFS) *WebApp
NewDefaultWebApp creates a new WebApp with the following default parameters * CORS are disabled * Assets are served on the default /assets path
func NewWebApp ¶
func NewWebApp(assetsFS *dirFS, templatesFS *dirFS, options *WebAppOptions) *WebApp
NewWebApp creates a new WebApp with the given options
type WebAppOptions ¶
type WebAppOptions struct { AppOptions // contains filtered or unexported fields }
WebAppOptions handles the WebApp configuration. WebAppOptions should be used when creating a new WebApp with custom parameters.