Documentation
¶
Overview ¶
Package std provides a standard HTTP implementation of the HTTP server abstraction.
Package std provides a standard HTTP implementation of the HTTP server abstraction.
Package std provides a standard HTTP implementation of the HTTP server abstraction.
Index ¶
- func NewErrorHandlerMiddleware() middleware.IErrorHandlerMiddleware
- func NewLoggingMiddleware() core.ILoggingMiddleware
- type Context
- func (c *Context) Abort()
- func (c *Context) Bind(obj interface{}) error
- func (c *Context) BindJSON(obj interface{}) error
- func (c *Context) DefaultQuery(key, defaultValue string) string
- func (c *Context) Error(err error) error
- func (c *Context) Errors() []error
- func (c *Context) File(filepath string)
- func (c *Context) Get(key string) (interface{}, bool)
- func (c *Context) GetHeader(key string) string
- func (c *Context) JSON(code int, obj interface{})
- func (c *Context) Next()
- func (c *Context) Param(key string) string
- func (c *Context) Query(key string) string
- func (c *Context) Redirect(code int, location string)
- func (c *Context) Request() *http.Request
- func (c *Context) Set(key string, value interface{})
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SetStatus(code int)
- func (c *Context) ShouldBindJSON(obj interface{}) error
- func (c *Context) String(code int, format string, values ...interface{})
- func (c *Context) Writer() http.ResponseWriter
- type ErrorHandlerMiddleware
- type LoggingMiddleware
- type ResponseWriterWrapper
- type RouterGroup
- func (g *RouterGroup) DELETE(path string, handlers ...core.HandlerFunc)
- func (g *RouterGroup) GET(path string, handlers ...core.HandlerFunc)
- func (g *RouterGroup) Group(path string) core.RouterGroup
- func (g *RouterGroup) PATCH(path string, handlers ...core.HandlerFunc)
- func (g *RouterGroup) POST(path string, handlers ...core.HandlerFunc)
- func (g *RouterGroup) PUT(path string, handlers ...core.HandlerFunc)
- func (g *RouterGroup) RegisterRouter(controllers ...core.Controller)
- func (g *RouterGroup) Use(middleware ...core.HandlerFunc)
- type Server
- func (s *Server) DELETE(path string, handlers ...core.HandlerFunc)
- func (s *Server) GET(path string, handlers ...core.HandlerFunc)
- func (s *Server) GetErrorHandlerMiddleware() core.IErrorHandlerMiddleware
- func (s *Server) GetLoggingMiddleware() core.ILoggingMiddleware
- func (s *Server) GetPort() string
- func (s *Server) Group(path string) core.RouterGroup
- func (s *Server) NoMethod(handlers ...core.HandlerFunc)
- func (s *Server) NoRoute(handlers ...core.HandlerFunc)
- func (s *Server) PATCH(path string, handlers ...core.HandlerFunc)
- func (s *Server) POST(path string, handlers ...core.HandlerFunc)
- func (s *Server) PUT(path string, handlers ...core.HandlerFunc)
- func (s *Server) RegisterRouter(controllers ...core.Controller)
- func (s *Server) Run() error
- func (s *Server) RunTLS(addr, certFile, keyFile string) error
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) StartLambda() error
- func (s *Server) Stop() error
- func (s *Server) Use(middleware ...core.HandlerFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewErrorHandlerMiddleware ¶
func NewErrorHandlerMiddleware() middleware.IErrorHandlerMiddleware
NewErrorHandlerMiddleware creates a new ErrorHandlerMiddleware.
func NewLoggingMiddleware ¶
func NewLoggingMiddleware() core.ILoggingMiddleware
NewLoggingMiddleware creates a new LoggingMiddleware.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is an implementation of core.Context using the standard net/http package.
func (*Context) Abort ¶ added in v0.0.6
func (c *Context) Abort()
Abort implements core.Context.Abort It prevents pending handlers in the chain from being called.
func (*Context) DefaultQuery ¶
DefaultQuery implements core.Context.DefaultQuery
func (*Context) Error ¶
Error implements core.Context.Error Since the standard HTTP package doesn't have a built-in error handling mechanism, this implementation stores the error in the context and returns it.
func (*Context) Errors ¶
Errors implements core.Context.Errors It returns all errors added to the context.
func (*Context) Get ¶
Get implements core.Context.Get It returns the value for the given key and a boolean indicating whether the key exists.
func (*Context) Next ¶
func (c *Context) Next()
Next implements core.Context.Next It calls the next handler in the chain.
func (*Context) Set ¶
Set implements core.Context.Set It stores a value in the context for the given key.
func (*Context) ShouldBindJSON ¶
ShouldBindJSON implements core.Context.ShouldBindJSON
func (*Context) Writer ¶
func (c *Context) Writer() http.ResponseWriter
Writer implements core.Context.Writer
type ErrorHandlerMiddleware ¶
type ErrorHandlerMiddleware struct{}
ErrorHandlerMiddleware is a standard HTTP implementation of middleware.IErrorHandlerMiddleware.
func (*ErrorHandlerMiddleware) Middleware ¶
func (m *ErrorHandlerMiddleware) Middleware(config *core.ErrorHandlerConfig) core.HandlerFunc
Middleware returns a middleware function that handles errors for standard HTTP.
type LoggingMiddleware ¶
type LoggingMiddleware struct {
middleware.BaseLoggingMiddleware
}
LoggingMiddleware is a standard HTTP implementation of core.ILoggingMiddleware.
func (*LoggingMiddleware) Middleware ¶
func (m *LoggingMiddleware) Middleware(config *core.LoggingConfig) core.HandlerFunc
Middleware returns a middleware function that logs API requests for standard HTTP. This implementation can capture the actual status code set by the handler.
type ResponseWriterWrapper ¶
type ResponseWriterWrapper struct { http.ResponseWriter // contains filtered or unexported fields }
ResponseWriterWrapper is a wrapper for http.ResponseWriter that captures the status code.
func (*ResponseWriterWrapper) Status ¶
func (w *ResponseWriterWrapper) Status() int
Status returns the captured status code.
func (*ResponseWriterWrapper) Write ¶
func (w *ResponseWriterWrapper) Write(b []byte) (int, error)
Write captures the status code (if not already set) and calls the underlying ResponseWriter's Write.
func (*ResponseWriterWrapper) WriteHeader ¶
func (w *ResponseWriterWrapper) WriteHeader(code int)
WriteHeader captures the status code and calls the underlying ResponseWriter's WriteHeader.
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup is an implementation of core.RouterGroup using the standard net/http package.
func (*RouterGroup) DELETE ¶
func (g *RouterGroup) DELETE(path string, handlers ...core.HandlerFunc)
DELETE implements core.RouterGroup.DELETE for RouterGroup
func (*RouterGroup) GET ¶
func (g *RouterGroup) GET(path string, handlers ...core.HandlerFunc)
GET implements core.RouterGroup.GET for RouterGroup
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(path string) core.RouterGroup
Group implements core.RouterGroup.Group for RouterGroup
func (*RouterGroup) PATCH ¶
func (g *RouterGroup) PATCH(path string, handlers ...core.HandlerFunc)
PATCH implements core.RouterGroup.PATCH for RouterGroup
func (*RouterGroup) POST ¶
func (g *RouterGroup) POST(path string, handlers ...core.HandlerFunc)
POST implements core.RouterGroup.POST for RouterGroup
func (*RouterGroup) PUT ¶
func (g *RouterGroup) PUT(path string, handlers ...core.HandlerFunc)
PUT implements core.RouterGroup.PUT for RouterGroup
func (*RouterGroup) RegisterRouter ¶
func (g *RouterGroup) RegisterRouter(controllers ...core.Controller)
RegisterRouter implements core.RouterGroup.RegisterRouter
func (*RouterGroup) Use ¶
func (g *RouterGroup) Use(middleware ...core.HandlerFunc)
Use implements core.RouterGroup.Use for RouterGroup
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an implementation of core.Server using the standard net/http package.
func NewServer ¶
NewServer creates a new Server instance using the standard HTTP package. If showLogs is true, logs about the framework, middleware, and routes will be printed to the console. If showLogs is false, these logs will be suppressed.
func (*Server) DELETE ¶
func (s *Server) DELETE(path string, handlers ...core.HandlerFunc)
DELETE implements core.Server.DELETE for Server
func (*Server) GET ¶
func (s *Server) GET(path string, handlers ...core.HandlerFunc)
GET implements core.Server.GET for Server
func (*Server) GetErrorHandlerMiddleware ¶
func (s *Server) GetErrorHandlerMiddleware() core.IErrorHandlerMiddleware
GetErrorHandlerMiddleware returns a standard HTTP-specific error handler middleware.
func (*Server) GetLoggingMiddleware ¶
func (s *Server) GetLoggingMiddleware() core.ILoggingMiddleware
GetLoggingMiddleware returns a standard HTTP-specific logging middleware.
func (*Server) Group ¶
func (s *Server) Group(path string) core.RouterGroup
Group implements core.Server.Group for Server
func (*Server) NoMethod ¶
func (s *Server) NoMethod(handlers ...core.HandlerFunc)
NoMethod implements core.Server.NoMethod
func (*Server) NoRoute ¶
func (s *Server) NoRoute(handlers ...core.HandlerFunc)
NoRoute implements core.Server.NoRoute
func (*Server) PATCH ¶
func (s *Server) PATCH(path string, handlers ...core.HandlerFunc)
PATCH implements core.Server.PATCH for Server
func (*Server) POST ¶
func (s *Server) POST(path string, handlers ...core.HandlerFunc)
POST implements core.Server.POST for Server
func (*Server) PUT ¶
func (s *Server) PUT(path string, handlers ...core.HandlerFunc)
PUT implements core.Server.PUT for Server
func (*Server) RegisterRouter ¶
func (s *Server) RegisterRouter(controllers ...core.Controller)
RegisterRouter implements core.Server.RegisterRouter
func (*Server) StartLambda ¶
StartLambda starts the server in AWS Lambda mode. This method should be called instead of Run or RunTLS when running in AWS Lambda. This method uses the httpadapter library to convert the standard HTTP handler to a Lambda handler.
Example usage:
import ( "github.com/mythofleader/go-http-server" ) func main() { s, _ := server.NewServer(server.FrameworkStdHTTP, "8080") // ... configure your server ... if err := s.StartLambda(); err != nil { // Handle error } }
func (*Server) Use ¶
func (s *Server) Use(middleware ...core.HandlerFunc)
Use implements core.Server.Use for Server