Documentation ¶
Index ¶
- Constants
- Variables
- func BuildDetails() string
- func BuildJSON() []byte
- func Err(code string, tmpl string, args ...interface{}) error
- func ErrCode(err error) string
- func ErrMessage(err error) string
- func NewContextWithUser(ctx context.Context, user *User) context.Context
- type DefaultLogger
- func (l *DefaultLogger) Debug(msg string)
- func (l *DefaultLogger) Debugf(format string, v ...interface{})
- func (l *DefaultLogger) E(err error)
- func (l *DefaultLogger) Error(msg string)
- func (l *DefaultLogger) Errorf(format string, v ...interface{})
- func (l *DefaultLogger) Fatal(v ...interface{})
- func (l *DefaultLogger) Fatalf(format string, v ...interface{})
- func (l *DefaultLogger) Fatalln(v ...interface{})
- func (l *DefaultLogger) Flags() int
- func (l *DefaultLogger) Info(msg string)
- func (l *DefaultLogger) Infof(format string, v ...interface{})
- func (l *DefaultLogger) Level() LogLevel
- func (l *DefaultLogger) Output(calldepth int, s string) error
- func (l *DefaultLogger) Panic(v ...interface{})
- func (l *DefaultLogger) Panicf(format string, v ...interface{})
- func (l *DefaultLogger) Panicln(v ...interface{})
- func (l *DefaultLogger) Prefix() string
- func (l *DefaultLogger) Print(v ...interface{})
- func (l *DefaultLogger) Printf(format string, v ...interface{})
- func (l *DefaultLogger) Println(v ...interface{})
- func (l *DefaultLogger) SetFlags(flag int)
- func (l *DefaultLogger) SetLevel(level string)
- func (l *DefaultLogger) SetOutput(w io.Writer)
- func (l *DefaultLogger) SetPrefix(prefix string)
- func (l *DefaultLogger) Warn(msg string)
- func (l *DefaultLogger) Warnf(format string, v ...interface{})
- func (l *DefaultLogger) Writer() io.Writer
- type Error
- type Item
- type ItemFilter
- type ItemListService
- type ItemUpdate
- type List
- type ListFilter
- type ListUpdate
- type LogLevel
- type Logger
- type User
- type UserFilter
- type UserService
- type UserUpdate
Constants ¶
const ( ENOTFOUND = "NOT_FOUND" EINVALID = "INVALID" EUNAUTHORIZED = "UNAUTHORIZED" ECONFLICT = "CONFLICT" EINTERNAL = "INTERNAL" )
Variables ¶
var ( Internal = &Error{EINTERNAL, "internal error"} NotFound = &Error{ENOTFOUND, "not found"} Invalid = &Error{EINVALID, "invalid"} Conflict = &Error{ECONFLICT, "conflict"} NotImplemented = &Error{EINTERNAL, "not implemented"} )
the following errors are intended to be used as sentinel values to determine error likeness using errors.Is
var Build = struct { Version string `json:"version"` Commit string `json:"commit"` Date string `json:"date"` }{ Version: "dev", Commit: "NA", Date: "NA", }
Functions ¶
func BuildDetails ¶
func BuildDetails() string
func ErrCode ¶
ErrCode extracts the ErrCode from an Error. If err is not an Error then EINTERNAL is returned.
func ErrMessage ¶
ErrMessage extracts the Message from an error. If err is not an Error then "internal error" is returned.
Types ¶
type DefaultLogger ¶
DefaultLogger wraps a log.Logger with a leveled implementation and satisfies the Logger interface.
func NewLogger ¶
func NewLogger() *DefaultLogger
NewLogger creates a new DefaultLogger at LogLevelInfo which writes to ioutil.Discard.
func (*DefaultLogger) Debug ¶
func (l *DefaultLogger) Debug(msg string)
func (*DefaultLogger) Debugf ¶
func (l *DefaultLogger) Debugf(format string, v ...interface{})
func (*DefaultLogger) E ¶
func (l *DefaultLogger) E(err error)
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(msg string)
func (*DefaultLogger) Errorf ¶
func (l *DefaultLogger) Errorf(format string, v ...interface{})
func (*DefaultLogger) Fatal ¶
func (l *DefaultLogger) Fatal(v ...interface{})
func (*DefaultLogger) Fatalf ¶
func (l *DefaultLogger) Fatalf(format string, v ...interface{})
func (*DefaultLogger) Fatalln ¶
func (l *DefaultLogger) Fatalln(v ...interface{})
func (*DefaultLogger) Flags ¶
func (l *DefaultLogger) Flags() int
func (*DefaultLogger) Info ¶
func (l *DefaultLogger) Info(msg string)
func (*DefaultLogger) Infof ¶
func (l *DefaultLogger) Infof(format string, v ...interface{})
func (*DefaultLogger) Level ¶
func (l *DefaultLogger) Level() LogLevel
func (*DefaultLogger) Panic ¶
func (l *DefaultLogger) Panic(v ...interface{})
func (*DefaultLogger) Panicf ¶
func (l *DefaultLogger) Panicf(format string, v ...interface{})
func (*DefaultLogger) Panicln ¶
func (l *DefaultLogger) Panicln(v ...interface{})
func (*DefaultLogger) Prefix ¶
func (l *DefaultLogger) Prefix() string
func (*DefaultLogger) Print ¶
func (l *DefaultLogger) Print(v ...interface{})
func (*DefaultLogger) Printf ¶
func (l *DefaultLogger) Printf(format string, v ...interface{})
func (*DefaultLogger) Println ¶
func (l *DefaultLogger) Println(v ...interface{})
func (*DefaultLogger) SetFlags ¶
func (l *DefaultLogger) SetFlags(flag int)
func (*DefaultLogger) SetLevel ¶
func (l *DefaultLogger) SetLevel(level string)
func (*DefaultLogger) SetOutput ¶
func (l *DefaultLogger) SetOutput(w io.Writer)
func (*DefaultLogger) SetPrefix ¶
func (l *DefaultLogger) SetPrefix(prefix string)
func (*DefaultLogger) Warn ¶
func (l *DefaultLogger) Warn(msg string)
func (*DefaultLogger) Warnf ¶
func (l *DefaultLogger) Warnf(format string, v ...interface{})
func (*DefaultLogger) Writer ¶
func (l *DefaultLogger) Writer() io.Writer
type Error ¶
type Item ¶
type Item struct { // ID represents a globally unique identifier and is set by the TodoService. ID int `json:"id"` // UserID represents the user who created the Item UserID int `json:"userId"` // ListID represents the list to which this Item belongs ListID int `json:"listId"` // Name is a used defined identifier for the Item. Name string `json:"name"` // Completed indicates whether this Item is completed or not. Completed bool `json:"completed"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
Item is an item contained within a List.
type ItemFilter ¶
type ItemListService ¶
type ItemListService interface { // CreateItem creates a Todo. The ID property of a Todo is ignored if specified. // Errors returned: // invalid: the todo specified failed to validate. CreateItem(ctx context.Context, i *Item) error // CreateList creates a List. The ID property of a List is ignored if specified. // Errors returned: // invalid: the todo specified failed to validate. CreateList(ctx context.Context, l *List) error // DeleteItem deletes a Item by ID. // Errors returned: // invalid: an invalid ID was specified // not_found: no matching Todo was found DeleteItem(ctx context.Context, id int) error // DeleteList deletes a List by ID. DeleteList(ctx context.Context, id int) error // FindItemByID returns a Todo with the matching ID. // Errors returned: // invalid: an invalid ID was specified // not_found: no matching Todo could be found FindItemByID(ctx context.Context, id int) (*Item, error) // FindItems finds the Items with the matching filters applied as a logical AND. // Errors returned: // invalid: an invalid filter was specified // not_found: no matching Items could be found. FindItems(ctx context.Context, f ItemFilter) ([]*Item, error) // FindListByID returns a List with the matching ID. // Errors returned: // invalid: an invalid ID was specified // not_found: no matching Todo could be found FindListByID(ctx context.Context, id int) (*List, error) // FindLists finds the Items with the matching filters applied as a logical AND. // Errors returned: // invalid: an invalid filter was specified // not_found: no matching Items could be found. FindLists(ctx context.Context, f ListFilter) ([]*List, error) // UpdateItem updates the Name and/or Completed state of a Todo. // Errors returned: // invalid: an invalid if no updates were specified. // not_found: no matching Item was found UpdateItem(ctx context.Context, id int, upd ItemUpdate) (*Item, error) // UpdateList updates the Title and/or Completed state of a Todo. // Errors returned: // invalid: an invalid if no updates were specified. // not_found: no matching Todo was found UpdateList(ctx context.Context, id int, upd ListUpdate) (*List, error) }
ItemListService provides functionality for manipulating Lists and Items.
type ItemUpdate ¶
type List ¶
type List struct { // ID represents the unique identifier for this List. ID int `json:"id"` // UserID represents the ID of the user who created this List. UserID int `json:"userId"` // Name represents a user assigned identifier for the List. Name string `json:"name"` // Completed indicates if all items are completed. Completed bool `json:"completed"` // Items represents all the items contained within this List. Items []*Item `json:"items"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
List represents a collection of Items
type ListFilter ¶
type ListUpdate ¶
type Logger ¶
type Logger interface { Debug(msg string) Debugf(format string, v ...interface{}) Info(msg string) Infof(format string, v ...interface{}) Warn(msg string) Warnf(format string, v ...interface{}) Error(msg string) Errorf(format string, v ...interface{}) E(err error) Level() LogLevel // Standard library logger methods below. SetOutput(w io.Writer) Output(calldepth int, s string) error Printf(format string, v ...interface{}) Print(v ...interface{}) Println(v ...interface{}) Flags() int SetFlags(flag int) Prefix() string SetPrefix(prefix string) Writer() io.Writer // Fatal, Fatalf, Fatalln, Panic, Panicf, and Panicln are not implemented. Fatal(v ...interface{}) Fatalf(format string, v ...interface{}) Fatalln(v ...interface{}) Panic(v ...interface{}) Panicf(format string, v ...interface{}) Panicln(v ...interface{}) }
Logger represents a leveled logger
type User ¶
type User struct { // ID is the unique identifier for this User. ID int `json:"id"` // Name represents the User's username Name string `json:"name"` // Email represents the email address associated with this User. Email *string `json:"email,omitempty"` // Password is the user's hashed password Password string `json:"password,omitempty"` // APIKey for bypassing normal auth flow access. APIKey string `json:"-"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
func UserFromContext ¶
UserFromContext returns the current logged-in user.
func ValidUserFromContext ¶
ValidUserFromContext returns the current logged-in user if they pass basic validation, otherwise, an ErrUnauthorized is returned.
type UserFilter ¶
type UserService ¶
type UserService interface { // LoginUser attempts to authenticate the user by username and password or API key. If the login attempt is // successful, all the properties on the User object will be filled out. LoginUser(ctx context.Context, user *User) error // CreateUser creates a User and an attached UserLogin with a random password. CreateUser(ctx context.Context, user *User) error // DeleteUser deletes a User, their UserCredentials and all associated Auths. DeleteUser(ctx context.Context, id int) error // UpdateUser updates a User. UpdateUser(ctx context.Context, id int, upd UserUpdate) (*User, error) // FindUserByID finds a User by their User ID. FindUserByID(ctx context.Context, id int) (*User, error) // FindUserByName finds a User by their Name. FindUserByName(ctx context.Context, name string) (*User, error) // FindUserByAPIKey finds a User by their API key. FindUserByAPIKey(ctx context.Context, apiKey string) (*User, error) // FindUsers finds one or more Users who match the UserFilter. FindUsers(ctx context.Context, f UserFilter) ([]*User, error) }
type UserUpdate ¶
func (UserUpdate) Validate ¶
func (upd UserUpdate) Validate() error