passport

package
v0.0.0-...-a480443 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMockDataSet

func CreateMockDataSet() (map[int]models.User, int)

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

func NewUserService(list map[int]models.User, count int) models.UserStorage

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 Routes

type Routes []Route

Routes are the main setup for our Router

type UserService

type UserService struct {
	UserList  map[int]models.User
	MaxUserID int
}

UserService will hold the connection and key db info

func (*UserService) AddUser

func (service *UserService) AddUser(u models.User) (models.User, error)

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

func (service *UserService) UpdateUser(u models.User) (models.User, error)

UpdateUser updates an existing user

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL