Documentation ¶
Index ¶
- func ActionById(w http.ResponseWriter, r *http.Request, ps httprouter.Params, user *User)
- func Actions(w http.ResponseWriter, r *http.Request, _ httprouter.Params, user *User)
- func AddRoutes(router *httprouter.Router)
- func AuthLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- func CallCommand(command string) error
- func CheckAuth(handle UserHandler) httprouter.Handle
- func CompareHashAndToken(hash string, token string) bool
- func CompareSaltAndPasswordToHash(salt, hashedPassword, password []byte) bool
- func CreateSaltAndHashedPassword(password []byte) ([]byte, []byte, error)
- func GenerateRandomBytes(n int) ([]byte, error)
- func GenerateRandomString(s int) (string, error)
- func HashToken(token string) string
- func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params, user *User)
- func LoginPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
- func LoginUser(username string, password string)
- func LoginUserJson(userJson []byte) (string, int, error)
- func OccurrenceById(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- func Occurrences(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- func PostAction(w http.ResponseWriter, r *http.Request, ps httprouter.Params, user *User)
- func PostArrayOfActionsJson(actionJson []byte) error
- func PostArrayOfOccurrencesJson(occurrenceJson []byte) error
- func PostArrayOfSetsJson(setJson []byte) error
- func PostOccurrence(w http.ResponseWriter, r *http.Request, ps httprouter.Params, user *User)
- func PostOccurrenceByActionIdJson(ActionId int, occurrenceJson []byte) error
- func PostUser(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- func PostUserJson(userJson []byte) error
- func Run()
- type Action
- type Configuration
- type DB
- func (db DB) CreateActionTable() error
- func (db DB) CreateOccurrenceTable() error
- func (db DB) CreateSessionTable() error
- func (db DB) CreateSetTable() error
- func (db DB) CreateUserTable() error
- func (db DB) DeleteActionById(actionId int) error
- func (db DB) DeleteOccurrenceById(occurrenceId int) error
- func (db DB) DeleteSessionByUserId(userId int) error
- func (db DB) DeleteSetById(setId int) error
- func (db DB) DropActionTable() error
- func (db DB) DropOccurrenceTable() error
- func (db DB) DropSessionTable() error
- func (db DB) DropSetTable() error
- func (db DB) DropUserTable() error
- func (db DB) GetActionById(id int) (*Action, error)
- func (db DB) GetActions() ([]Action, error)
- func (db DB) GetActionsByUserId(id int) ([]Action, error)
- func (db DB) GetOccurrenceById(id int) (*Occurrence, error)
- func (db DB) GetOccurrencesOfAction(id int) ([]Occurrence, error)
- func (db DB) GetSessionKeysByUserId(userId int) ([]string, error)
- func (db DB) GetSetById(id int) (*Set, error)
- func (db DB) GetSets() ([]Set, error)
- func (db DB) GetUserById(id int) (*User, error)
- func (db DB) GetUserByUserName(userName string) (*User, error)
- func (db DB) InsertAction(action *Action) error
- func (db DB) InsertOccurrence(occurrence *Occurrence) error
- func (db DB) InsertSession(userId int, hashedToken string) error
- func (db DB) InsertSet(set *Set) error
- func (db DB) InsertUser(user *User) error
- type Occurrence
- type Set
- type User
- type UserHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ActionById ¶
func ActionById(w http.ResponseWriter, r *http.Request, ps httprouter.Params, user *User)
func Actions ¶
func Actions(w http.ResponseWriter, r *http.Request, _ httprouter.Params, user *User)
func AddRoutes ¶
func AddRoutes(router *httprouter.Router)
Add routes to http router TODO: Add route description parameters and useage
func AuthLogin ¶
func AuthLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
func CallCommand ¶
func CompareHashAndToken ¶
func CompareSaltAndPasswordToHash ¶
CompareSaltAndPasswordToHash takes a salt, a hashedPassword, and a submitted password and returns true if the submitted password was the original password saved
func CreateSaltAndHashedPassword ¶
CreateSaltAndHashedPassword takes a password as a byte array and returns a hashed version of the password and a password salt that was generated and used in the hashing process
func GenerateRandomBytes ¶
GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func GenerateRandomString ¶
GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func Index ¶
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params, user *User)
func LoginPage ¶
func LoginPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
func LoginUserJson ¶
LoginuserJson takes json with a username and a password key unmarshals this json and then creates a session if the pass authentication information is valid
func OccurrenceById ¶
func OccurrenceById(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
func Occurrences ¶
func Occurrences(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
TODO: Add time as a query string parameter. Allow the user to specify how many they want also make a week the default amount
func PostAction ¶
func PostAction(w http.ResponseWriter, r *http.Request, ps httprouter.Params, user *User)
func PostArrayOfActionsJson ¶
func PostArrayOfSetsJson ¶
func PostOccurrence ¶
func PostOccurrence(w http.ResponseWriter, r *http.Request, ps httprouter.Params, user *User)
func PostUser ¶
func PostUser(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
func PostUserJson ¶
Creates a User in the database from json.
Types ¶
type Action ¶
type Action struct { Id int `json:"id"` ActionName string `json:"actionName"` SetId int `json:"setId"` UserId int `json:"userId"` }
TODO: Add metadata / extradata / data field. It can have any structure.
Action specifies the structure.
func (Action) CreateOccurrence ¶
func (a Action) CreateOccurrence(occurrence Occurrence) error
type Configuration ¶
type Configuration struct { DBName string DBUser string DBPassword string DBLocal bool DBHost string DBPort int DBSSL string AmbitionPort int }
func ReadConfiguration ¶
func ReadConfiguration(file string) Configuration
type DB ¶
Database type to extend with custom functions
func (DB) CreateActionTable ¶
func (DB) CreateOccurrenceTable ¶
func (DB) CreateSessionTable ¶
func (DB) CreateSetTable ¶
func (DB) CreateUserTable ¶
func (DB) DeleteActionById ¶
func (DB) DeleteOccurrenceById ¶
func (DB) DeleteSessionByUserId ¶
func (DB) DeleteSetById ¶
func (DB) DropActionTable ¶
func (DB) DropOccurrenceTable ¶
func (DB) DropSessionTable ¶
func (DB) DropSetTable ¶
func (DB) DropUserTable ¶
func (DB) GetActions ¶
func (DB) GetOccurrenceById ¶
func (db DB) GetOccurrenceById(id int) (*Occurrence, error)
func (DB) GetOccurrencesOfAction ¶
func (db DB) GetOccurrencesOfAction(id int) ([]Occurrence, error)
func (DB) GetSessionKeysByUserId ¶
func (DB) InsertAction ¶
func (DB) InsertOccurrence ¶
func (db DB) InsertOccurrence(occurrence *Occurrence) error
func (DB) InsertUser ¶
type Occurrence ¶
type Occurrence struct { Id int `json:"id"` ActionId int `json:"actionId"` Time time.Time `json:"time"` }
TODO: Add metadata / extradata / data field. It can have any structure.
Occurrence should follow the sturcture specified in Action.
type User ¶
type User struct { Id int `json:"id"` UserName string `json:"username"` Email string `json:"email"` HashedPassword []byte PasswordSalt []byte }
func (User) CreateAction ¶
func (User) GetActions ¶
type UserHandler ¶
type UserHandler func(http.ResponseWriter, *http.Request, httprouter.Params, *User)