todos

package
v0.0.0-...-cf7041d Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TodoCtxKey = &todoCtxKey{}

Functions

func Handler

func Handler(svc Service) http.Handler

func TodoCtx

func TodoCtx(svc Service) func(http.Handler) http.Handler

Types

type ErrNotFound

type ErrNotFound struct {
	// contains filtered or unexported fields
}

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type Option

type Option func(*service)

func WithRepo

func WithRepo(r Repository) Option

type Repository

type Repository interface {
	FindByID(context.Context, string) (Todo, error)
	FindByTag(context.Context, string) ([]Todo, error)
	ListAll(context.Context) ([]Todo, error)
	Add(context.Context, Todo) error
	Delete(context.Context, string) error
	Update(context.Context, string, Todo) error
}

func NewDbRepository

func NewDbRepository(c *sql.DB) Repository

func NewInMemoryRepository

func NewInMemoryRepository() Repository

type Scanner

type Scanner interface {
	Scan(...any) error
}

Scanner is a constraint that matches sql.Row and sql.Rows

type Service

type Service interface {
	FindByID(context.Context, string) (Todo, error)
	FindByTags(context.Context, []string) ([]Todo, error)
	ListAll(context.Context) ([]Todo, error)
	Add(context.Context, Todo) (Todo, error)
	Delete(context.Context, string) error
	Update(context.Context, string, Todo) (Todo, error)
	MarkCompleted(context.Context, Todo) (Todo, error)
}

func NewService

func NewService(opts ...Option) Service

type Todo

type Todo struct {
	ID          string     `json:"id"`
	Title       string     `json:"title"`
	Tags        []string   `json:"tags"`
	CompletedAt *time.Time `json:"completed_at,omitempty"`
}

func (Todo) CleanTags

func (t Todo) CleanTags() string

CleanTags returns a comma separated list of deduplicated tags (small caps)

Jump to

Keyboard shortcuts

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