web

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Port int `env:"SERVER_PORT" envDefault:"8080"`

	// CacheTemplates defines whether templates have to be loaded from disk every request.
	// It is useful during development. So, it is always false when Debug mode is on
	CacheTemplates bool `env:"SERVER_CACHE_TEMPLATES" envDefault:"true"`

	// SkipAuth disables auth. Works only in Debug mode!
	SkipAuth bool `env:"SERVER_SKIP_AUTH"`
	// Credentials is a list of pairs 'login:password' separated by comma.
	// Example: "login:password,user:qwerty"
	Credentials Credentials `env:"SERVER_CREDENTIALS"`
}

type Credentials

type Credentials map[string]string

func (*Credentials) UnmarshalText

func (c *Credentials) UnmarshalText(text []byte) error

type Database

type Database interface {
	// Month
	GetMonths(ctx context.Context, year int) ([]*db.Month, error)
	GetMonth(ctx context.Context, id uint) (*db.Month, error)
	GetMonthID(ctx context.Context, year, month int) (id uint, err error)

	// Day
	GetDay(ctx context.Context, id uint) (*db.Day, error)
	GetDayIDByDate(ctx context.Context, year, month, day int) (id uint, err error)

	// Income
	AddIncome(ctx context.Context, args db.AddIncomeArgs) (id uint, err error)
	EditIncome(ctx context.Context, args db.EditIncomeArgs) error
	RemoveIncome(ctx context.Context, id uint) error

	// Monthly Payment
	AddMonthlyPayment(ctx context.Context, args db.AddMonthlyPaymentArgs) (id uint, err error)
	EditMonthlyPayment(ctx context.Context, args db.EditMonthlyPaymentArgs) error
	RemoveMonthlyPayment(ctx context.Context, id uint) error

	// Spend
	AddSpend(ctx context.Context, args db.AddSpendArgs) (id uint, err error)
	EditSpend(ctx context.Context, args db.EditSpendArgs) error
	RemoveSpend(ctx context.Context, id uint) error

	// Spend Type
	GetSpendTypes(ctx context.Context) ([]db.SpendType, error)
	AddSpendType(ctx context.Context, name string) (id uint, err error)
	EditSpendType(ctx context.Context, id uint, newName string) error
	RemoveSpendType(ctx context.Context, id uint) error
}

type Server

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

func NewServer

func NewServer(cnf Config, db Database, log logrus.FieldLogger, debug bool) *Server

func (Server) AddIncome

func (s Server) AddIncome(w http.ResponseWriter, r *http.Request)

POST /api/incomes - add a new income

Request: models.AddIncomeReq Response: models.AddIncomeResp or models.Response

func (Server) AddMonthlyPayment

func (s Server) AddMonthlyPayment(w http.ResponseWriter, r *http.Request)

POST /api/monthly-payments

Request: models.AddMonthlyPaymentReq Response: models.AddMonthlyPaymentResp or models.Response

func (Server) AddSpend

func (s Server) AddSpend(w http.ResponseWriter, r *http.Request)

POST /api/spends

Request: models.AddSpendReq Response: models.AddSpendResp or models.Response

func (Server) AddSpendType

func (s Server) AddSpendType(w http.ResponseWriter, r *http.Request)

POST /api/spend-types

Request: models.AddSpendTypeReq Response: models.AddSpendTypeResp or models.Response

func (Server) EditIncome

func (s Server) EditIncome(w http.ResponseWriter, r *http.Request)

PUT /api/incomes - edit existing income

Request: models.EditIncomeReq Response: models.Response

func (Server) EditMonthlyPayment

func (s Server) EditMonthlyPayment(w http.ResponseWriter, r *http.Request)

PUT /api/monthly-payments

Request: models.EditMonthlyPaymentReq Response: models.Response

func (Server) EditSpend

func (s Server) EditSpend(w http.ResponseWriter, r *http.Request)

PUT /api/spends

Request: models.EditSpendReq Response: models.Response

func (Server) EditSpendType

func (s Server) EditSpendType(w http.ResponseWriter, r *http.Request)

PUT /api/spend-types

Request: models.EditSpendTypeReq Response: models.Response

func (Server) GetDay

func (s Server) GetDay(w http.ResponseWriter, r *http.Request)

GET /api/days

Request: models.GetDayReq or models.GetDayByDate Response: models.GetDayResp or models.Response

func (Server) GetMonth

func (s Server) GetMonth(w http.ResponseWriter, r *http.Request)

GET /api/months

Request: models.GetMonthReq or models.GetMonthByYearAndMonthReq Response: models.GetMonthResp or models.Response

func (Server) GetSpendTypes

func (s Server) GetSpendTypes(w http.ResponseWriter, r *http.Request)

GET /api/spend-types

Request: - Response: models.GetSpendTypesResp or models.Response

func (Server) ListenAndServer

func (s Server) ListenAndServer() error

func (*Server) Prepare

func (s *Server) Prepare()

func (Server) RemoveIncome

func (s Server) RemoveIncome(w http.ResponseWriter, r *http.Request)

DELETE /api/incomes - remove income

Request: models.RemoveIncomeReq Response: models.Response

func (Server) RemoveMonthlyPayment

func (s Server) RemoveMonthlyPayment(w http.ResponseWriter, r *http.Request)

DELETE /api/monthly-payments

Request: models.DeleteMonthlyPaymentReq Response: models.Response

func (Server) RemoveSpend

func (s Server) RemoveSpend(w http.ResponseWriter, r *http.Request)

DELETE /api/spends

Request: models.RemoveSpendReq Response: models.Response

func (Server) RemoveSpendType

func (s Server) RemoveSpendType(w http.ResponseWriter, r *http.Request)

DELETE /api/spend-types

Request: models.RemoveSpendTypeReq Response: models.Response

func (Server) Shutdown

func (s Server) Shutdown() error

type TemplateStore

type TemplateStore interface {
	Get(ctx context.Context, path string) *htmlTemplate.Template
	Execute(ctx context.Context, path string, w io.Writer, data interface{}) error
}

Directories

Path Synopsis
Package models contains models of requests and responses
Package models contains models of requests and responses
Package templates provides a store for templates which supports caching
Package templates provides a store for templates which supports caching

Jump to

Keyboard shortcuts

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