store

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeID

func EncodeID(id string) string

EncodeID hashes id to sha1. The function intentionally left outside of User struct because in some cases we need hashing for parts of id, in some others hashing for non-User values.

func HashValue

func HashValue(val string, secret string) string

HashValue makes hmac with secret

Types

type BlockedUser

type BlockedUser struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Timestamp time.Time `json:"time"`
}

BlockedUser holds id and ts for blocked user

type Comment

type Comment struct {
	ID        string          `json:"id"`
	ParentID  string          `json:"pid"`
	Text      string          `json:"text"`
	Orig      string          `json:"orig,omitempty"`
	User      User            `json:"user"`
	Locator   Locator         `json:"locator"`
	Score     int             `json:"score"`
	Votes     map[string]bool `json:"votes"`
	Timestamp time.Time       `json:"time"`
	Edit      *Edit           `json:"edit,omitempty"` // pointer to have empty default in json response
	Pin       bool            `json:"pin,omitempty"`
	Deleted   bool            `json:"delete,omitempty"`
}

Comment represents a single comment with optional reference to its parent

func (*Comment) PrepareUntrusted

func (c *Comment) PrepareUntrusted()

PrepareUntrusted pre-processes a comment received from untrusted source by clearing all autogen fields and reset everything users not supposed to provide

func (*Comment) Sanitize

func (c *Comment) Sanitize()

Sanitize clean dangerous html/js from the comment

func (*Comment) SetDeleted

func (c *Comment) SetDeleted(mode DeleteMode)

SetDeleted clears comment info, reset to deleted state. hard flag will clear all user info as well

type DeleteMode

type DeleteMode int

DeleteMode defines how much comment info will be erased

const (
	SoftDelete DeleteMode = 0
	HardDelete DeleteMode = 1
)

DeleteMode enum

type Edit

type Edit struct {
	Timestamp time.Time `json:"time"`
	Summary   string    `json:"summary"`
}

Edit indication

type Locator

type Locator struct {
	SiteID string `json:"site,omitempty"`
	URL    string `json:"url"`
}

Locator keeps site and url of the post

type PostInfo

type PostInfo struct {
	URL      string    `json:"url"`
	Count    int       `json:"count"`
	ReadOnly bool      `json:"read_only,omitempty"`
	FirstTS  time.Time `json:"first_time,omitempty"`
	LastTS   time.Time `json:"last_time,omitempty"`
}

PostInfo holds summary for given post url

type User

type User struct {
	Name     string `json:"name"`
	ID       string `json:"id"`
	Picture  string `json:"picture"`
	IP       string `json:"ip,omitempty"`
	Admin    bool   `json:"admin"`
	Blocked  bool   `json:"block,omitempty"`
	Verified bool   `json:"verified,omitempty"`
}

User holds user-related info

func (*User) HashIP

func (u *User) HashIP(secret string)

HashIP replace IP field with hashed hmac

Directories

Path Synopsis
Package engine defines interfaces each supported storage should implement.
Package engine defines interfaces each supported storage should implement.

Jump to

Keyboard shortcuts

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