Documentation ¶
Index ¶
- Variables
- type Context
- func (c *Context) GetBody() (io.Reader, error)
- func (c *Context) GetHeader(name string) string
- func (c *Context) GetMethod() string
- func (c *Context) GetParam(name string, typ Paramtype) (string, error)
- func (c *Context) GetRequest() *http.Request
- func (c *Context) GetURL() string
- func (c *Context) HttpResWriter() http.ResponseWriter
- func (c *Context) InHeaders() http.Header
- func (c *Context) Read(obj interface{}) error
- func (c *Context) SetContentType(contentType string)
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetHeader(name, value string)
- func (c *Context) SetStatusCode(statusCode int)
- func (c *Context) Write(data interface{}, contentType string) error
- func (c *Context) WriteData(data []byte) (int, error)
- func (c *Context) WriteFrom(data io.Reader)
- func (c *Context) WriteString(data string)
- type DataTypProvider
- type HandlerFunc
- type Options
- func (o *Options) GetCertPath() string
- func (o *Options) GetEnableTLS() bool
- func (o *Options) GetListenHost() string
- func (o *Options) GetListenPort() int16
- func (o *Options) GetPrivateKeyPath() string
- func (o *Options) SetCertPath(certPath string) *Options
- func (o *Options) SetEnableTLS(enableTLS bool) *Options
- func (o *Options) SetListenHost(host string) *Options
- func (o *Options) SetListenPort(port int16) *Options
- func (o *Options) SetPrivateKeyPath(privateKeyPath string) *Options
- func (o *Options) Validate() error
- type Paramtype
- type Server
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCertPath = errors.New("empty cert path")
var ErrInvalidConfig = errors.New("empty config path")
var ErrInvalidID = errors.New("empty id")
var ErrInvalidListenHost = errors.New("empty listen host")
var ErrInvalidListenPort = errors.New("empty listen port")
var ErrInvalidParamType = errors.New("invalid param type provided")
var ErrInvalidPrivateKeyPath = errors.New("empty private key path")
var ErrNilOptions = errors.New("nil options")
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is the struct that holds the request and response of the server.
func (*Context) GetRequest ¶
GetRequest returns the request. for most Rest Use cases this would not be required
func (*Context) HttpResWriter ¶
func (c *Context) HttpResWriter() http.ResponseWriter
HttpResWriter returns the http.ResponseWriter
func (*Context) SetContentType ¶
SetContentType sets the content type of the response.
func (*Context) SetStatusCode ¶
SetStatusCode sets the status code of the response.
func (*Context) Write ¶
Write writes the object to the response with the given content type and status code.
func (*Context) WriteString ¶
WriteString writes the string to the response.
type DataTypProvider ¶
type DataTypProvider func() any
type HandlerFunc ¶
type HandlerFunc func(context Context)
type Options ¶
type Options struct { Id string `json:"id" yaml:"id" bson:"id" mapstructure:"id"` PathPrefix string `json:"path_prefix,omitempty" yaml:"path_prefix,omitempty" bson:"path_prefix,omitempty" mapstructure:"path_prefix,omitempty"` ListenHost string `json:"listen_host" yaml:"listen_host" bson:"listen_host" mapstructure:"listen_host"` ListenPort int16 `json:"listen_port" yaml:"listen_port" bson:"listen_port" mapstructure:"listen_port"` ReadTimeout int64 `` /* 127-byte string literal not displayed */ WriteTimeout int64 `` /* 131-byte string literal not displayed */ EnableTLS bool `json:"enable_tls" yaml:"enable_tls" bson:"enable_tls" mapstructure:"enable_tls"` PrivateKeyPath string `` /* 138-byte string literal not displayed */ CertPath string `json:"cert_path,omitempty" yaml:"cert_path,omitempty" bson:"cert_path,omitempty" mapstructure:"cert,omitempty"` Cors *filters.CorsOptions `json:"cors,omitempty" yaml:"cors,omitempty" bson:"cors,omitempty" mapstructure:"cors,omitempty"` }
Options is the configuration for the server
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns the default options for the server The default options are:
- PathPrefix: "/"
- Id: "default-http-server"
- ListenHost: "localhost"
- ListenPort: 8080
- ReadTimeout: 20000
- WriteTimeout: 20000
- Cors: &filters.CorsOptions{ MaxAge: 0, AllowedOrigins: []string{"*"}, AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"}, ResponseStatus: http.StatusNoContent, }
func NewOptionsWithDefaults ¶
func NewOptionsWithDefaults() *Options
NewOptionsWithDefaults returns a new server options with default values
func (*Options) GetCertPath ¶
GetCertPath returns the cert path
func (*Options) GetEnableTLS ¶
GetEnableTLS returns the enable TLS value
func (*Options) GetListenHost ¶
GetListenHost returns the listen host
func (*Options) GetListenPort ¶
GetListenPort returns the listen port
func (*Options) GetPrivateKeyPath ¶
GetPrivateKeyPath returns the private key path
func (*Options) SetCertPath ¶
SetCertPath sets the cert path
func (*Options) SetEnableTLS ¶
SetEnableTLS sets the enable TLS value
func (*Options) SetListenHost ¶
SetListenHost sets the listen host
func (*Options) SetListenPort ¶
SetListenPort sets the listen port
func (*Options) SetPrivateKeyPath ¶
SetPrivateKeyPath sets the private key path
type Server ¶
type Server interface { // Server is a lifecytcle component lifecycle.Component // Opts returns the options of the server Opts() *Options // AddRoute adds a route to the server AddRoute(path string, handler HandlerFunc, method ...string) (err error) // AddRoute adds a route to the server Post(path string, handler HandlerFunc) (err error) // AddRoute adds a route to the server Get(path string, handler HandlerFunc) (err error) // AddRoute adds a route to the server Put(path string, handler HandlerFunc) (err error) // AddRoute adds a route to the server Delete(path string, handler HandlerFunc) (err error) // Unhandled adds a handler for unhandled routes Unhandled(handler HandlerFunc) (err error) // Unsupported adds a handler for unsupported methods Unsupported(handler HandlerFunc) (err error) }
Server is the interface that wraps the ServeHTTP method.