posts

package
v0.0.0-...-7a1a3cb Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNewPost

func GetNewPost(c *gin.Context)

func GetPosts

func GetPosts(ps IPostStorage) func(c *gin.Context)

func PostNewPost

func PostNewPost(ps IPostStorage) func(c *gin.Context)

Types

type IPostStorage

type IPostStorage interface {
	GetPosts() []Post
	SavePost(p Post)
}

IPostStorage is a generic poster interface

type MongoStorage

type MongoStorage struct {
	Coll *mongo.Collection
}

func (MongoStorage) GetPosts

func (ps MongoStorage) GetPosts() []Post

func (MongoStorage) SavePost

func (ps MongoStorage) SavePost(p Post)

type Post

type Post struct {
	ID      string
	Created time.Time
	Name    string `form:"name" json:"name"`
	Message string `form:"message" json:"message"`
	Terms   string `form:"terms" json:"terms"`
}

Post is a representation of a Guestbook entry

func FromMap

func FromMap(m map[string]string) Post

FromMap creates a new Post instance from a map of strings. This is typically what is returned from external stores like Redis and is used by the PostStorage struct.

func NewPost

func NewPost() Post

NewPost is a constructor function which sets default values

func (Post) GetID

func (p Post) GetID() string

GetID returns the ID of the post

func (Post) GetTimeSince

func (p Post) GetTimeSince() string

func (Post) ToMap

func (p Post) ToMap() map[string]interface{}

ToMap converts the Post instance to a map of strings. This is usefull for persisting data to external stores lik Redis and is used by the PostStorage struct.

type RedisStorage

type RedisStorage struct {
	Rdb *redis.Client
}

func (RedisStorage) GetPosts

func (ps RedisStorage) GetPosts() []Post

func (RedisStorage) SavePost

func (ps RedisStorage) SavePost(p Post)

Jump to

Keyboard shortcuts

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