app

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: Unlicense Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInconsistentIDs = errors.New("inconsistent IDs")
	ErrAlreadyExists   = errors.New("already exists")
	ErrNotFound        = errors.New("not found")
)
View Source
var (
	ErrBadRouting = errors.New("inconsistent mapping between route and handler (programmer error)")
	ErrNoInt      = errors.New("input parameter isn't integer")
)

Functions

func MakeAliveEndpoint

func MakeAliveEndpoint(_ Service) endpoint.Endpoint

func MakeDeleteTodoEndpoint

func MakeDeleteTodoEndpoint(s Service) endpoint.Endpoint

func MakeDeleteTodosEndpoint

func MakeDeleteTodosEndpoint(s Service) endpoint.Endpoint

func MakeGetTodoEndpoint

func MakeGetTodoEndpoint(s Service) endpoint.Endpoint

func MakeGetTodosEndpoint

func MakeGetTodosEndpoint(s Service) endpoint.Endpoint

func MakeHTTPHandler

func MakeHTTPHandler(s Service, logger log.Logger) http.Handler

func MakePatchTodoEndpoint

func MakePatchTodoEndpoint(s Service) endpoint.Endpoint

func MakePostTodoEndpoint

func MakePostTodoEndpoint(s Service) endpoint.Endpoint

func NewPostgresRepository

func NewPostgresRepository(c *Config) (*postgresRepository, error)

Types

type Config

type Config struct {
	ServerPort       string `envconfig:"port" default:"8080"`
	DatabaseHost     string `default:"localhost"`
	DatabasePort     string `default:"54321"`
	DatabaseUsername string `default:"todo"`
	DatabasePassword string `default:"todo"`
	DatabaseSchema   string `default:"todo"`
	Url              string `default:"http://localhost:8080"`
}

func CreateConfig

func CreateConfig() (*Config, error)

type Endpoints

type Endpoints struct {
	AliveEndpoint       endpoint.Endpoint
	GetTodosEndpoint    endpoint.Endpoint
	GetTodoEndpoint     endpoint.Endpoint
	PostTodoEndpoint    endpoint.Endpoint
	DeleteTodosEndpoint endpoint.Endpoint
	DeleteTodoEndpoint  endpoint.Endpoint
	PatchTodoEndpoint   endpoint.Endpoint
}

func MakeServerEndpoints

func MakeServerEndpoints(s Service) Endpoints

type Middleware

type Middleware func(Service) Service

func LoggingMiddleware

func LoggingMiddleware(logger log.Logger) Middleware

type Repository

type Repository interface {
	GetAll() ([]Todo, error)
	Get(id int) (Todo, error)
	Save(t Todo) (Todo, error)
	DeleteAll() error
	Delete(id int) error
	Update(id int, t Todo) (Todo, error)
	Drop() error
}

type Service

type Service interface {
	GetTodos(ctx context.Context) ([]Todo, error)
	GetTodo(ctx context.Context, id int) (Todo, error)
	InsertTodo(ctx context.Context, t Todo) (Todo, error)
	DeleteTodos(ctx context.Context) error
	DeleteTodo(ctx context.Context, id int) error
	UpdateTodo(ctx context.Context, id int, t Todo) (Todo, error)
	Clear() error
}

Service is a simple CRUD interface for user profiles.

func NewService

func NewService(repository Repository, cfg *Config) Service

type Todo

type Todo struct {
	Id        *int    `json:"id"`
	Title     *string `json:"title"`
	Completed *bool   `json:"completed"`
	Order     *int    `json:"order"`
	URL       string  `json:"url"`
}

Jump to

Keyboard shortcuts

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