snippet

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: Unlicense Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is used when a specific Snippet is requested but does not exist.
	ErrNotFound = errors.New("Snippet not found")

	// ErrInvalidID occurs when an ID is not in a valid form.
	ErrInvalidID = errors.New("ID is not in its proper form")
)

Functions

This section is empty.

Types

type Info

type Info struct {
	ID          string    `db:"snippet_id" json:"id"`
	Title       string    `db:"title" json:"title"`
	Content     string    `db:"content" json:"content"`
	DateExpires time.Time `db:"date_expires" json:"date_expires"`
	DateCreated time.Time `db:"date_created" json:"date_created"`
	DateUpdated time.Time `db:"date_updated" json:"date_updated"`
}

Info represents a textual extract of something

type NewSnippet

type NewSnippet struct {
	Title       string    `json:"title" validate:"required"`
	Content     string    `json:"content" validate:"required"`
	DateExpires time.Time `json:"date_expires" validate:"required"`
}

NewSnippet contains information needed to create a new Snippet.

type Snippet

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

Snippet manages the set of API's for snippet access. It wraps a sql.DB connection pool.

func New

func New(db *sqlx.DB) Snippet

New constructs a Snippet for api access.

func (Snippet) Create

func (s Snippet) Create(ctx context.Context, n NewSnippet, now time.Time) (*Info, error)

Create inserts a new snippet record into the database.

func (Snippet) Delete

func (s Snippet) Delete(ctx context.Context, id string) error

Delete removes a snippet record from the database.

func (Snippet) Latest

func (s Snippet) Latest(ctx context.Context) ([]Info, error)

Latest gets the latest snippets from the database.

func (Snippet) Retrieve

func (s Snippet) Retrieve(ctx context.Context, id string) (*Info, error)

Retrieve gets the specified snippet from the database.

func (Snippet) Update

func (s Snippet) Update(ctx context.Context, id string, upd UpdateSnippet, now time.Time) error

Update updates a snippet record in the database.

type UpdateSnippet

type UpdateSnippet struct {
	Title       *string    `json:"title"`
	Content     *string    `json:"content"`
	DateExpires *time.Time `json:"date_expires"`
}

UpdateSnippet defines what information may be provided to modify an existing Snippet. All fields are optional so clients can send just the fields they want changed. It uses pointer fields so we can differentiate between a field that was not provided and a field that was provided as explicitly blank.

Jump to

Keyboard shortcuts

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