Documentation ¶
Index ¶
- func CreateMockDataSet() (map[int]models.User, int)
- func CreateUserHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
- func DeleteUserHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
- func GetUserHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
- func HealthcheckHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
- func ListUsersHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
- func MakeHandler(appEnv AppEnv, fn func(http.ResponseWriter, *http.Request, AppEnv)) http.HandlerFunc
- func NewUserService(list map[int]models.User, count int) models.UserStorage
- func PassportsHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
- func StartServer(appEnv AppEnv)
- func UpdateUserHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
- type AppEnv
- type HandlerFunc
- type Route
- type Routes
- type UserService
- func (service *UserService) AddUser(u models.User) (models.User, error)
- func (service *UserService) DeleteUser(i int) error
- func (service *UserService) GetUser(i int) (models.User, error)
- func (service *UserService) ListUsers() ([]models.User, error)
- func (service *UserService) UpdateUser(u models.User) (models.User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateMockDataSet ¶
CreateMockDataSet initialises a database for test purposes. It returns a list of User objects as well as the new max object count
func CreateUserHandler ¶
func CreateUserHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
CreateUserHandler adds a new user
func DeleteUserHandler ¶
func DeleteUserHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
DeleteUserHandler deletes a user
func GetUserHandler ¶
func GetUserHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
GetUserHandler returns a user object
func HealthcheckHandler ¶
func HealthcheckHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
HealthcheckHandler returns useful info about the app
func ListUsersHandler ¶
func ListUsersHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
ListUsersHandler returns a list of users
func MakeHandler ¶
func MakeHandler(appEnv AppEnv, fn func(http.ResponseWriter, *http.Request, AppEnv)) http.HandlerFunc
MakeHandler allows us to pass an environment struct to our handlers, without resorting to global variables. It accepts an environment (Env) struct and our own handler function. It returns a function of the type http.HandlerFunc so can be passed on to the HandlerFunc in main.go.
func NewUserService ¶
NewUserService creates a new Carer Service with the system's database connection
func PassportsHandler ¶
func PassportsHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
PassportsHandler not implemented yet
func StartServer ¶
func StartServer(appEnv AppEnv)
StartServer Wraps the mux Router and uses the Negroni Middleware
func UpdateUserHandler ¶
func UpdateUserHandler(w http.ResponseWriter, req *http.Request, appEnv AppEnv)
UpdateUserHandler updates a user object
Types ¶
type AppEnv ¶
type AppEnv struct { Render *render.Render Version string Env string Port string UserStore models.UserStorage }
AppEnv holds application configuration data
func CreateContextForTestSetup ¶
func CreateContextForTestSetup() AppEnv
CreateContextForTestSetup initialises an application context struct for testing purposes
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request, AppEnv)
HandlerFunc is a custom implementation of the http.HandlerFunc
type Route ¶
type Route struct { Name string Method string Pattern string HandlerFunc HandlerFunc }
Route is the model for the router setup
type UserService ¶
UserService will hold the connection and key db info
func (*UserService) AddUser ¶
AddUser adds a User JSON document, returns the JSON document with the generated id
func (*UserService) DeleteUser ¶
func (service *UserService) DeleteUser(i int) error
DeleteUser deletes a user
func (*UserService) GetUser ¶
func (service *UserService) GetUser(i int) (models.User, error)
GetUser returns a single JSON document
func (*UserService) ListUsers ¶
func (service *UserService) ListUsers() ([]models.User, error)
ListUsers returns a list of JSON documents
func (*UserService) UpdateUser ¶
UpdateUser updates an existing user