todos

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package todos provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version v1.8.3 DO NOT EDIT.

Package todos provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version v1.8.3 DO NOT EDIT.

Index

Constants

View Source
const DefaultMaxId = 2

Variables

This section is empty.

Functions

func GetErrorF

func GetErrorF(errMsg string, err error) error

func IsDriverSupported

func IsDriverSupported(driver string) bool

func RegisterHandlers

func RegisterHandlers(router EchoRouter, si ServerInterface)

RegisterHandlers adds each server route to the EchoRouter.

func RegisterHandlersWithBaseURL

func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string)

Registers handlers, and prepends BaseURL to the paths, so that the paths can be served under a prefix.

Types

type CreateTodoJSONBody

type CreateTodoJSONBody NewTodo

CreateTodoJSONBody defines parameters for CreateTodo.

type CreateTodoJSONRequestBody

type CreateTodoJSONRequestBody CreateTodoJSONBody

CreateTodoJSONRequestBody defines body for CreateTodo for application/json ContentType.

type EchoRouter

type EchoRouter interface {
	CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}

This is a simple interface which specifies echo.Route addition functions which are present on both echo.Echo and echo.Group, since we want to allow using either of them for path registration

type Error

type Error struct {
	Code    int32  `json:"code"`
	Message string `json:"message"`
}

Error defines model for Error.

type ErrorService

type ErrorService struct {
	Err    error  `json:"err" `
	Status int    `json:"status" `
	Msg    string `json:"msg" `
}

func (*ErrorService) Error

func (e *ErrorService) Error() string

type GetTodosParams

type GetTodosParams struct {
	// maximum number of results to return
	Limit *int32 `json:"limit,omitempty"`
}

GetTodosParams defines parameters for GetTodos.

type NewTodo

type NewTodo struct {
	Task string `json:"task"`
}

NewTodo defines model for NewTodo.

type PGX

type PGX struct {
	Conn *pgxpool.Pool
	// contains filtered or unexported fields
}

func (*PGX) Close

func (db *PGX) Close()

func (*PGX) Count

func (db *PGX) Count() (int32, error)

Count returns the number of todos stored in DB

func (*PGX) Create

func (db *PGX) Create(todo NewTodo) (*Todo, error)

Create will store the new task in the store

func (*PGX) Delete

func (db *PGX) Delete(id int32) error

Delete the todos stored in DB with given id

func (*PGX) Exist

func (db *PGX) Exist(id int32) bool

Exist returns true only if a todos with the specified id exists in store.

func (*PGX) Get

func (db *PGX) Get(id int32) (*Todo, error)

func (*PGX) GetMaxId

func (db *PGX) GetMaxId() (int32, error)

GetMaxId returns the maximum value of todos id existing in store.

func (*PGX) List

func (db *PGX) List(offset, limit int) ([]*Todo, error)

func (*PGX) Update

func (db *PGX) Update(id int32, todo Todo) (*Todo, error)

Update the todos stored in DB with given id and other information in struct

type ServerInterface

type ServerInterface interface {
	// Returns all Todos
	// (GET /todos)
	GetTodos(ctx echo.Context, params GetTodosParams) error

	// (POST /todos)
	CreateTodo(ctx echo.Context) error

	// (DELETE /todos/{todoId})
	DeleteTodo(ctx echo.Context, todoId int32) error

	// (GET /todos/{todoId})
	GetTodo(ctx echo.Context, todoId int32) error

	// (PUT /todos/{todoId})
	UpdateTodo(ctx echo.Context, todoId int32) error
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler ServerInterface
}

ServerInterfaceWrapper converts echo contexts to parameters.

func (*ServerInterfaceWrapper) CreateTodo

func (w *ServerInterfaceWrapper) CreateTodo(ctx echo.Context) error

CreateTodo converts echo context to params.

func (*ServerInterfaceWrapper) DeleteTodo

func (w *ServerInterfaceWrapper) DeleteTodo(ctx echo.Context) error

DeleteTodo converts echo context to params.

func (*ServerInterfaceWrapper) GetTodo

func (w *ServerInterfaceWrapper) GetTodo(ctx echo.Context) error

GetTodo converts echo context to params.

func (*ServerInterfaceWrapper) GetTodos

func (w *ServerInterfaceWrapper) GetTodos(ctx echo.Context) error

GetTodos converts echo context to params.

func (*ServerInterfaceWrapper) UpdateTodo

func (w *ServerInterfaceWrapper) UpdateTodo(ctx echo.Context) error

UpdateTodo converts echo context to params.

type Service

type Service struct {
	Log   *log.Logger
	Store Storage
}

func (Service) CreateTodo

func (s Service) CreateTodo(ctx echo.Context) error

CreateTodo will store the NewTodo task in the store to test it with curl you can try : curl -XPOST -H "Content-Type: application/json" -d '{"task":"learn Linux"}' 'http://localhost:8080/todos' curl -XPOST -H "Content-Type: application/json" -d '{"task":""}' 'http://localhost:8080/todos'

func (Service) DeleteTodo

func (s Service) DeleteTodo(ctx echo.Context, todoId int32) error

DeleteTodo will remove the given todoID entry from the store, and if not present will return 400 Bad Request curl -v -XDELETE -H "Content-Type: application/json" 'http://localhost:8080/todos/3' -> 204 No Content if present and delete it curl -v -XDELETE -H "Content-Type: application/json" 'http://localhost:8080/todos/93333' -> 400 Bad Request

func (Service) GetMaxId

func (s Service) GetMaxId(ctx echo.Context) error

GetMaxId returns the greatest todos id used by now curl -H "Content-Type: application/json" 'http://localhost:8080/todos/maxid'

func (Service) GetTodo

func (s Service) GetTodo(ctx echo.Context, todoId int32) error

func (Service) GetTodos

func (s Service) GetTodos(ctx echo.Context, params GetTodosParams) error

GetTodos will retrieve all Todos in the store and return then to test it with curl you can try : curl -H "Content-Type: application/json" 'http://localhost:8080/todos' |json_pp

func (Service) UpdateTodo

func (s Service) UpdateTodo(ctx echo.Context, todoId int32) error

UpdateTodo will store the modified information in the store for the given todoId curl -v -XPUT -H "Content-Type: application/json" -d '{"id": 3, "task":"learn Linux", "completed": true}' 'http://localhost:8080/todos/3' curl -v -XPUT -H "Content-Type: application/json" -d '{"id": 3, "task":"learn Linux", "completed": false}' 'http://localhost:8080/todos/3'

type Storage

type Storage interface {
	// List returns the list of existing todos with the given offset and limit.
	List(offset, limit int) ([]*Todo, error)
	// Get returns the todos with the specified todos ID.
	Get(id int32) (*Todo, error)
	// GetMaxId returns the maximum value of todos id existing in store.
	GetMaxId() (int32, error)
	// Exist returns true only if a todos with the specified id exists in store.
	Exist(id int32) bool
	// Count returns the total number of todos.
	Count() (int32, error)
	// Create saves a new todos in the storage.
	Create(todo NewTodo) (*Todo, error)
	// Update updates the todos with given ID in the storage.
	Update(id int32, todo Todo) (*Todo, error)
	// Delete removes the todos with given ID from the storage.
	Delete(id int32) error
	// Close terminates properly the connection to the backend
	Close()
}

Storage is an interface to different implementation of persistence for Todos

func GetStorageInstance

func GetStorageInstance(dbDriver, dbConnectionString string, log *log.Logger) (Storage, error)

func NewMemoryDB

func NewMemoryDB() (Storage, error)

func NewPgxDB

func NewPgxDB(dbConnectionString string, maxConnectionsInPool int, log *log.Logger) (Storage, error)

type Todo

type Todo struct {
	Completed   bool       `json:"completed"`
	CompletedAt *time.Time `json:"completed_at,omitempty"`
	CreatedAt   *time.Time `json:"created_at,omitempty"`
	Id          int32      `json:"id"`
	Task        string     `json:"task"`
}

Todo defines model for Todo.

Jump to

Keyboard shortcuts

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