models

package
v0.0.0-...-e51c59f Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Users holds map of our users (ID->User). In real life, access should be protected!
	Users map[int64]*User
)

Functions

func AddOne

func AddOne(user User) int64

AddOne adds single user to the map

func GetAll

func GetAll() map[int64]*User

GetAll gets all users as map

func Init

func Init()

Init provides initial data for our application

func Update

func Update(user User) (err error)

Update updates single user in map (search is performed by ID)

Types

type RequestError

type RequestError struct {
	// ErrorCode is the code of your error; not exported to json. Added only for demonstration purposes.
	ErrorCode int `json:"-"`
	// Message is the description of error; exported to json
	Message string `json:"message"`
}

RequestError describes error that occurred in application

type User

type User struct {
	// ID defines the user ID. Should be unique per users set
	ID int64 `json:"id" example:"1" format:"int64"`
	// Name is the name of a user
	Name string `json:"name" example:"Dmytro" minLength:"1" maxLength:"30"`
	// Country is the country where user lives
	Country string `json:"country" example:"Ukraine"`
}

User defines user struct

func Delete

func Delete(id int64) (*User, error)

Delete deletes user form map, by ID

func GetOne

func GetOne(id int64) (object *User, err error)

GetOne gets single user by ID

Jump to

Keyboard shortcuts

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