Documentation
¶
Overview ¶
Package web implements common functionality for web APIs using Gin and Gorm.
Modules ¶
Modules provide functionality for a web server. A module is a function executed before starting a server, accessing the Service and the Gin Engine. Each Service maintains a list of modules. When it runs, it executes all of its modules.
Index ¶
Constants ¶
const ( ContentTypeJSON = "application/json" ContentTypeJS = "application/javascript" ContentTypeXML = "text/xml" ContentTypeYAML = "text/yaml" ContentTypeHTML = "text/html" )
MIME type strings.
Variables ¶
var ( ErrAPIInvalidRequestFormat = errors.New("Invalid Request Format") ErrAPIInternalDatabase = errors.New("Internal Database Error") ErrAPINotFound = errors.New("Not found") )
Error strings used for HTTPError.Message.
Functions ¶
func JSONRequest ¶
JSONRequest issues a GET request to the specified URL and reads the returned JSON into value. See json.Unmarshal for the rules for converting JSON into a value.
func NewRequestWithFile ¶
NewRequestWithFile Create a Request with file as body
func Response ¶
Response sends an HTTP response.
statusCode is the respone's status.
If the request's Content-Type is JavaScript, JSON, YAML, or XML, it returns data serialized as JSONP, JSON, YAML, or XML, respectively. If the Content-Type is HTML, it returns the HTML template templateName rendered with data.
Types ¶
type HTTPError ¶
type HTTPError struct { Message string `json:"message" example:"invalid format"` Error string `json:"error,omitempty" example:"<internal error message>"` Data interface{} `json:"data,omitempty" swaggerignore:"true"` }
HTTPError is returned in HTTP error responses.
type ModuleRegisterFunc ¶
A ModuleRegisterFunc is a module.
type Service ¶
type Service struct { // config Listen string `config:"listen" toml:"listen"` AccessLog bool `config:"access_log" toml:"access_log"` WebrootIndexDisable bool `config:"webroot_index_disable" toml:"webroot_index_disable"` Webroot string `config:"webroot" toml:"webroot"` WebrootFS http.FileSystem `config:"-" toml:"-"` ACME struct { Enable bool `config:"enable" toml:"enable"` Domains []string `config:"domains" toml:"domains"` Cache string `config: "cache" toml:"cache"` } `config:"acme" toml:"acme"` Session struct { Name string `config:"name" toml:"name"` Secret string `config: "secret" toml:"secret"` } `config:"session" toml:"session"` // internal DB *gorm.DB `config:"-" toml:"-"` Mailer *mailer.Service `config:"-" toml:"-"` // contains filtered or unexported fields }
A Service stores configuration of a server.
func (*Service) LoadSession ¶
LoadSession starts session handling for s.
func (*Service) ModuleRegister ¶
func (ws *Service) ModuleRegister(f ModuleRegisterFunc)
ModuleRegister adds f to ws's list of modules.
Directories
¶
Path | Synopsis |
---|---|
api
|
|
status
Package status implements for web the module to publish the status with version and other extras
|
Package status implements for web the module to publish the status with version and other extras |
Package auth implements for web the module for authentification
|
Package auth implements for web the module for authentification |
Package file abstracts non-hierarchical file stores.
|
Package file abstracts non-hierarchical file stores. |
fs
Package fs implements a non-hierarchical file store using the underlying (disk) file system.
|
Package fs implements a non-hierarchical file store using the underlying (disk) file system. |
s3
Package s3 implements a non-hierarchical file store using Amazon s3.
|
Package s3 implements a non-hierarchical file store using Amazon s3. |
Package metrics implements for web the module to publish prometheus metrics
|
Package metrics implements for web the module to publish prometheus metrics |
Package webtest implements an easy way to write test for web modules
|
Package webtest implements an easy way to write test for web modules |