example

package
v0.0.0-...-e954c25 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Example model and data manager

It contains initialized Manager (`Man`) to get|set data:

`example.Man.Get(123)`

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExampleModel

type ExampleModel struct {
	ID        int       `db:"id"`
	Title     string    `db:"title" valid:"required"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

func (*ExampleModel) Validate

func (t *ExampleModel) Validate() error

type Manager

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

Use manager to get|set data

Instance of Manager

func NewExampleMan

func NewExampleMan(storage Storage) Manager

func (Manager) Create

func (m Manager) Create(item ExampleModel) (int, error)

func (Manager) Delete

func (m Manager) Delete(id int) error

func (Manager) Get

func (m Manager) Get(id int) (ExampleModel, error)

func (Manager) GetCached

func (m Manager) GetCached(id int) (ExampleModel, error)

func (Manager) Update

func (m Manager) Update(item ExampleModel) error

type Storage

type Storage interface {
	DBInit() error
	Create(item ExampleModel) (int, error)
	Get(id int) (ExampleModel, error)
	Update(item ExampleModel) error
	Delete(id int) error
}

Interface to store data in DB

func NewPostgresStorage

func NewPostgresStorage() Storage

Implementation of Storage interface

Jump to

Keyboard shortcuts

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