Documentation ¶
Overview ¶
Package http provides an ApiServer type - a server that uses api.PasteService and api.UserService to provide many useful endpoints. Check the New method documentation for the list of all endpoints.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIServer ¶
type APIServer struct { PasteService api.PasteService UserService api.UserService Router *gin.Engine Server *http.Server Options APIServerOptions }
APIServer type provides an HTTP server that calls PasteService methods in response to HTTP requests to certain routes.
Use the `New` function to create an instance of ApiServer with the default routes.
func New ¶
func New(pSvc api.PasteService, uSvc api.UserService, opts APIServerOptions) *APIServer
New function returns an instance of ApiServer using provided PasteService and all the HTTP routes for manipulating pastes.
The routes are:
GET /paste/{id} - get paste by ID POST /paste - create new paste DELETE /paste/{id} - delete paste by ID GET /paste/list/{id} - get a list of pastes by UserID POST /user/login - authenticate user POST /user/register - register new user POST /user/validate - validate user token
func (*APIServer) ListenAndServe ¶
ListenAndServe starts an HTTP server and binds it to the provided address.
TODO: Timeouts should be configurable.
type APIServerOptions ¶
type APIServerOptions struct { // Addr will be passed to http.Server to listen on, see http.Server // documentation for more information. Addr string // Maximum size of the POST request body, anything larger than this will // be rejected with an error. MaxBodySize int64 // When using a database as a storage this connection string will be passed // on to the corresponding service. DBConnectionString string //Read timeout: maximum duration for reading the entire request. ReadTimeout time.Duration // Write timeout: maximum duration before timing out writes of the response WriteTimeout time.Duration // Idle timeout: maximum amount of time to wait for the next request IdleTimeout time.Duration // Log file location LogFile string // Log mode 'debug' or 'production' LogMode string // DBAutoMigrate bool // TokenSecret string }
APIServerOptions defines various parameters needed to run the ApiServer