post

package module
v0.1.5 Latest Latest
Warning

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

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

README

post

Post resource for REST API that provides concurrency safe accessor and mutator functions via a monitor goroutine.

Quick Start

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

// A Post instance
p1 := post.Post{
  Id: post.NewId(), // post.NewID() generates unique post ID.
  UserId: 1,
  Title: "The title",
  Body: "The body of the post.",
}

// Get a post. id is an int.
p2 := post.Get(id)

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

// Save a new post.
post.Add(p1)

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

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

// Stop the monitor goroutine. Can be used with http.Server.RegisterOnShutdown().
post.Shutdown()

Documentation

Overview

Package post provides an API for accessing and manipulating content posts. The API functions are safe for concurrent access from multiple goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(p Post)

Add guarda un post nuevo.

func Del

func Del(id int)

Del borra un post.

func NewId

func NewId() int

NewId genera un ID único para un post.

func Set

func Set(p Post)

Set guarda un post existente.

func Shutdown added in v0.1.4

func Shutdown()

Shutdown detiene la monitor goroutine. Cualquier uso de las funciones de este paquete luego de llamar Shutdown resultarán en un panic.

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.

Jump to

Keyboard shortcuts

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