post

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: MIT Imports: 6 Imported by: 1

README

post

Post resource for REST API that provides concurrency safe accessor and mutator functions using a SQLite3 DB for persistence.

Quick Start

See https://github.com/jecolon/restsrv for a sample REST API server that uses this package.

// Init must be called before using the rest of the package API.
if err := post.Init(); err != nil {
  log.Fatalf("post.Init() error: %v", err)
}
  
// A Post instance
p1 := post.Post{
  UserId: 1,
  Title: "The title",
  Body: "The body of the post.",
}

// Save the new post
post.New(p1)

// Get a post. id is an int. found is false if post not found.
p2, found := post.Get(id)

// List all posts. posts is a []Post.
posts := post.List()

// Update an existing post.
p1.Body = "A new body!"
post.Put(p1)

// Delete a post.
post.Del(p1.Id)

Documentation

Overview

Package post provides an API for accessing and manipulating content posts. The API functions are safe for concurrent access from multiple goroutines. Users of this package must call Init() to setup the data store properly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del

func Del(id int)

Del borra un post.

func Init added in v0.3.0

func Init() error

Init prepara el generador de números aleatorios, la DB y los "prepared statements". Si Init devuelve un error, el código cliente no debe usar este paquete.

func Put added in v0.1.6

func Put(p Post)

Put guarda un post existente.

Types

type Post

type Post struct {
	Id     int
	UserId int
	Title  string
	Body   string
}

Post es una entrada de contenido.

func Get

func Get(id int) (Post, bool)

Get busca un post por ID. El bool es falso si no lo encontramos.

func List

func List() []Post

List devuelve un slice de todos los posts.

func New added in v0.1.6

func New(p Post) []Post

New guarda un post nuevo.

Jump to

Keyboard shortcuts

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