snippet

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 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 Store added in v0.1.2

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

Store manages the set of API's for snippet access. It wraps a pgxpool.Pool connection pool.

func NewStore added in v0.1.4

func NewStore(db *pgxpool.Pool) Store

NewStore constructs a Store for api access.

func (Store) Create added in v0.1.2

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

Create inserts a new snippet record into the database.

func (Store) Delete added in v0.1.2

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

Delete removes a snippet record from the database.

func (Store) Latest added in v0.1.2

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

Latest gets the latest snippets from the database.

func (Store) Retrieve added in v0.1.2

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

Retrieve gets the specified snippet from the database.

func (Store) Update added in v0.1.2

func (s Store) 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