todo

package module
v0.0.0-...-15fe6cf Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: MIT Imports: 4 Imported by: 0

README

todo-app

A sample todo app example written in go

Create .env file in the root of the project with DB_PASSWOD property:

DB_PASSWORD=qwert

Run postgres in docker container

docker run --name todo-db -e POSTGRES_PASSWORD=qwert -p 5432:5432 -d postgres

Database migration

Migrate is used for Database migrations.

Create migration files

migrate create -ext sql -dir db/migrations -seq init

Run DB migrations

Via Docker:

docker run -v /full-path-to/todo-app/db/migrations:/migrations --network host migrate/migrate -path=/migrations/ -database 'postgres://postgres:qwert@localhost:5432/postgres?sslmode=disable' up

or via binary file from the root of the project

migrate -path db/migrations -database 'postgres://postgres:qwert@localhost:5432/postgres?sslmode=disable' up

In case of error error: Dirty database version 1. Fix and force version. during migration run

migrate -path db/migrations -database 'postgres://postgres:qwert@localhost:5432/postgres?sslmode=disable' force 1

where 1 is a failed version of migration (see the name of sql file with migrations in db/migrations)

More details here: https://github.com/golang-migrate/migrate/issues/282#issuecomment-530743258

Swagger

Swagg is used for Swagger documentation.

Generate swagger

swag init -g cmd/main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListsItem

type ListsItem struct {
	Id     int
	ListId int
	ItemId int
}

type Server

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

func (*Server) Run

func (s *Server) Run(port string, handler http.Handler) error

func (Server) Shutdown

func (s Server) Shutdown(ctx context.Context) error

type TodoItem

type TodoItem struct {
	Id          int    `json:"id" db:"id"`
	Title       string `json:"title" db:"title" binding:"required"`
	Description string `json:"description" db:"description"`
	Done        bool   `json:"done" db:"done"`
}

type TodoList

type TodoList struct {
	Id          int    `json:"id" db:"id"`
	Title       string `json:"title" db:"title" binding:"required"`
	Description string `json:"description" db:"description"`
}

type UpdateItemInput

type UpdateItemInput struct {
	Title       *string `json:"title"`
	Description *string `json:"description"`
	Done        *bool   `json:"done"`
}

func (UpdateItemInput) Validate

func (i UpdateItemInput) Validate() error

type UpdateTodoListRequest

type UpdateTodoListRequest struct {
	Title       *string `json:"title"`
	Description *string `json:"description"`
}

func (UpdateTodoListRequest) ValidateNoUpdate

func (i UpdateTodoListRequest) ValidateNoUpdate() error

ValidateNoUpdate validates if UpdateTodoListRequest updates or not. Return error when there were no changes for UpdateTodoListRequest.

type User

type User struct {
	Id       int    `json:"-" db:"id"`
	Name     string `json:"name" binding:"required"`
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

type UsersList

type UsersList struct {
	Id     int
	UserId int
	ListId int
}

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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