internal

package
v0.0.0-...-5bdb617 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateHandler

func CreateHandler() handler.Handler

CreateHandler : Create a user with given name. Return created user

func Delete

func Delete(id int) error

Delete deletes the user with the given ID, or returns an error if not found.

func DeleteHandler

func DeleteHandler() handler.Handler

DeleteHandler : Delete a user by ID

func GetOneHandler

func GetOneHandler() handler.Handler

GetOneHandler : Get a user by ID

func SearchHandler

func SearchHandler() handler.Handler

SearchHandler : Search users by name. If query param name is empty, all users are returned

func UpdateHandler

func UpdateHandler() handler.Handler

UpdateHandler : Update user by ID and return the updated user. If user doesn't exist a new entry is created.

Types

type User

type User struct {
	ID int `json:"id" description:"Immutable & unique user identifier"`
	UserBody
}

User model Tag description is used by openapi spec generation to add explanations about the field

func GetByID

func GetByID(id int) (User, error)

GetByID returns the user with the given ID, or an error if not found.

func Save

func Save(user User) (User, error)

Save saves the given user, assigning it a new ID if it is a new user.

func Search(name string) ([]User, error)

Search returns the users whose name contains the given string.

type UserBody

type UserBody struct {
	Name string `json:"name" description:"User name: can be updated" required:"true"`
}

UserBody model used as body by CreateHandler & UpdateHandler

- Tag description is used by openapi spec generation to add explanations about the field - Tag required is used by middleware.Body for body validation & openapi spec generation to flag the field as required

func (UserBody) Validate

func (u UserBody) Validate() error

Validate is an implementation of middleware.BodyValidation. If user UserBody is given to middleware.Body, this function was called automatically and error handled

Jump to

Keyboard shortcuts

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