Documentation
¶
Index ¶
- Constants
- func BuildWebServer(db, migration string, daoType dao.DBType, statisticsDuration time.Duration) (*negroni.Negroni, error)
- func GetJSONContent(v interface{}, r *http.Request) error
- func NotFoundHandler() http.HandlerFunc
- func QueryParamAsString(name string, r *http.Request) string
- func SendJSONError(w http.ResponseWriter, error string, code int)
- func SendJSONNotFound(w http.ResponseWriter)
- func SendJSONOk(w http.ResponseWriter, d interface{})
- func SendJSONWithHTTPCode(w http.ResponseWriter, d interface{}, code int)
- func URLParamAsString(name string, r *http.Request) string
- type Route
- type Router
- type StatisticsMiddleware
- type TaskController
- func (sh *TaskController) Create(w http.ResponseWriter, r *http.Request)
- func (sh *TaskController) Delete(w http.ResponseWriter, r *http.Request)
- func (sh *TaskController) Get(w http.ResponseWriter, r *http.Request)
- func (sh *TaskController) GetAll(w http.ResponseWriter, r *http.Request)
- func (sh *TaskController) Update(w http.ResponseWriter, r *http.Request)
Constants ¶
const ( // ResponseHeaderContentTypeKey is the key used for response content type ResponseHeaderContentTypeKey = "Content-Type" // ResponseHeaderContentTypeJSONUTF8 is the key used for UTF8 JSON response ResponseHeaderContentTypeJSONUTF8 = "application/json; charset=UTF-8" )
Variables ¶
This section is empty.
Functions ¶
func BuildWebServer ¶
func BuildWebServer(db, migration string, daoType dao.DBType, statisticsDuration time.Duration) (*negroni.Negroni, error)
BuildWebServer constructs a new web server with the right DAO and tasks handler
func GetJSONContent ¶
GetJSONContent returns the JSON content of a request
func NotFoundHandler ¶
func NotFoundHandler() http.HandlerFunc
NotFoundHandler return a JSON implementation of the not found handler
func QueryParamAsString ¶
QueryParamAsString Param Return a url param as an int
func SendJSONError ¶
func SendJSONError(w http.ResponseWriter, error string, code int)
SendJSONError sends error with a custom message and error code
func SendJSONNotFound ¶
func SendJSONNotFound(w http.ResponseWriter)
SendJSONNotFound produces a http.StatusNotFound response with the following JSON, '{"Error":"Resource not found"}'
func SendJSONOk ¶
func SendJSONOk(w http.ResponseWriter, d interface{})
SendJSONOk outputs a JSON with http.StatusOK code
func SendJSONWithHTTPCode ¶
func SendJSONWithHTTPCode(w http.ResponseWriter, d interface{}, code int)
SendJSONWithHTTPCode outputs JSON with an HTTP code
Types ¶
type Route ¶
type Route struct { Name string Method string Pattern string HandlerFunc http.HandlerFunc }
Route is a structure of Route
type Router ¶
Router is the struct use for routing
func NewRouter ¶
func NewRouter(controller *TaskController) *Router
NewRouter creates a new router instance
type StatisticsMiddleware ¶
type StatisticsMiddleware struct {
Stat *statistics.Statistics
}
StatisticsMiddleware is the middleware to record request statistics
func NewStatisticsMiddleware ¶
func NewStatisticsMiddleware(duration time.Duration) *StatisticsMiddleware
NewStatisticsMiddleware creates a new statistics middleware
func (*StatisticsMiddleware) ServeHTTP ¶
func (sm *StatisticsMiddleware) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
type TaskController ¶
type TaskController struct { Routes []Route Prefix string // contains filtered or unexported fields }
TaskController is a controller for tasks resource
func NewTaskController ¶
func NewTaskController(taskDAO dao.TaskDAO) *TaskController
NewTaskController creates a new task controller to manage tasks
func (*TaskController) Create ¶
func (sh *TaskController) Create(w http.ResponseWriter, r *http.Request)
Create create an entity
func (*TaskController) Delete ¶
func (sh *TaskController) Delete(w http.ResponseWriter, r *http.Request)
Delete delete an entity by id
func (*TaskController) Get ¶
func (sh *TaskController) Get(w http.ResponseWriter, r *http.Request)
Get retrieve an entity by id
func (*TaskController) GetAll ¶
func (sh *TaskController) GetAll(w http.ResponseWriter, r *http.Request)
GetAll retrieve all entities with optional paging of items (start / end are item counts 50 to 100 for example)
func (*TaskController) Update ¶
func (sh *TaskController) Update(w http.ResponseWriter, r *http.Request)
Update update an entity by id