todo

package
v0.0.0-...-60da083 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENOTFOUND     = "NOT_FOUND"
	EINVALID      = "INVALID"
	EUNAUTHORIZED = "UNAUTHORIZED"
	ECONFLICT     = "CONFLICT"
	EINTERNAL     = "INTERNAL"
)

Variables

View Source
var (
	Unauthorized   = &Error{EUNAUTHORIZED, "unauthorized"}
	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

View Source
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 BuildJSON

func BuildJSON() []byte

func Err

func Err(code string, tmpl string, args ...interface{}) error

Err is a utility method to create an Error with a Code.

func ErrCode

func ErrCode(err error) string

ErrCode extracts the ErrCode from an Error. If err is not an Error then EINTERNAL is returned.

func ErrMessage

func ErrMessage(err error) string

ErrMessage extracts the Message from an error. If err is not an Error then "internal error" is returned.

func NewContextWithUser

func NewContextWithUser(ctx context.Context, user *User) context.Context

NewContextWithUser returns a new context with the given user.

Types

type DefaultLogger

type DefaultLogger struct {
	*log.Logger
	// contains filtered or unexported fields
}

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) Output

func (l *DefaultLogger) Output(calldepth int, s string) error

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 Error struct {
	// Code is the application level error code
	Code string
	// Message is either a loggable and or human-readable message.
	Message string
}

func (*Error) Error

func (e *Error) Error() string

func (Error) Is

func (e Error) Is(target error) bool

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.

func (*Item) Validate

func (i *Item) Validate() error

type ItemFilter

type ItemFilter struct {
	// Filter fields
	ID        *int
	UserID    *int
	ListID    *int
	Name      *string
	Completed *bool

	// Range restrictions
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

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 ItemUpdate struct {
	Name      *string `json:"name,omitempty"`
	Completed *bool   `json:"completed,omitempty"`
}

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

func (*List) Validate

func (l *List) Validate() error

type ListFilter

type ListFilter struct {
	// Filter fields
	ID        *int
	UserID    *int
	Name      *string
	Completed *bool

	// Range restrictions
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

type ListUpdate

type ListUpdate struct {
	Name      *string `json:"name,omitempty"`
	Completed *bool   `json:"completed,omitempty"`
}

type LogLevel

type LogLevel int

LogLevel represents a log level

const (
	LogLevelDebug LogLevel = 0
	LogLevelInfo  LogLevel = 3
	LogLevelWarn  LogLevel = 5
	LogLevelError LogLevel = 7
)

func (LogLevel) String

func (l LogLevel) String() string

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

func UserFromContext(ctx context.Context) *User

UserFromContext returns the current logged-in user.

func ValidUserFromContext

func ValidUserFromContext(ctx context.Context) (*User, error)

ValidUserFromContext returns the current logged-in user if they pass basic validation, otherwise, an ErrUnauthorized is returned.

func (*User) Validate

func (u *User) Validate() error

type UserFilter

type UserFilter struct {
	// Filter fields
	ID     *int    `json:"id"`
	Name   *string `json:"name"`
	Email  *string `json:"email"`
	APIKey *string `json:"apiKey"`

	// Range restrictions
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

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

type UserUpdate struct {
	Name  *string `json:"name"`
	Email *string `json:"email"`
}

func (UserUpdate) Validate

func (upd UserUpdate) Validate() error

Jump to

Keyboard shortcuts

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