kommentator

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

README

kommentator

Open Source comment system for static websites

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCaptchaFailed = errors.New("incorrect captcha")
View Source
var ErrInternal = errors.New("internal error")
View Source
var ErrThreadClosed = errors.New("thread is closed")
View Source
var ErrThrottle = errors.New("too frequent requests")

Client is sending too many requests in short timeframe

Functions

func EncodePath

func EncodePath(path []IDType) string

Panics if length of string representation of any path element is more than 35 characters

func EncodePathComponent

func EncodePathComponent(id IDType) string

Types

type Comment

type Comment struct {
	ID         IDType     `json:"id" db:"id"`                   // unique id of the comment
	ThreadID   IDType     `json:"tid" db:"tid"`                 // unique id of the thread this comment belongs to
	Path       string     `json:"path" db:"path"`               // materialized path of this comment
	Body       string     `json:"body" db:"body"`               // body of the comment
	RemoteAddr string     `json:"remote_addr" db:"remote_addr"` // Remote address (IP) of author of this comment
	Likes      int64      `json:"likes" db:"likes"`             // Number of likes this comment received
	Dislikes   int64      `json:"dislikes" db:"dislikes"`       // number of dislikes this comment received
	Depth      int32      `json:"depth" db:"depth"`
	Created    *time.Time `json:"created" db:"created"`           // when this comment was created
	Modified   *time.Time `json:"modified" db:"modified"`         // when this comment was modified
	Author     *string    `json:"author,omitempty" db:"author"`   // name of author of this comment as left by author
	Email      *string    `json:"email,omitempty" db:"email"`     // email left by author of this comment
	Website    *string    `json:"website,omitempty" db:"website"` // url to website leaved by author if any
	Voters     []byte     `json:"-" db:"voters"`                  // binary representation of remote ip for the voters on the post
	Parent     *IDType    `json:"parent" db:"parent"`             // id of the parent comment
}

Comment in the thread

type Config

type Config struct {
	RequireEmail       bool   // Specifies if email is required for commenting
	MaxThreadDepth     uint8  // Configures maximum allowed thread depth
	ReCaptchaEnabled   bool   // If ReCaptcha is enabled
	ReCaptchaApiKey    string // Key for the ReCaptcha
	ReCaptchaApiSecret string // Secret for ReCaptcha
}

Config specifying different settings of running instance

type IDType

type IDType int64

type Storage

type Storage interface {
	// Adds new comment and returns new comment with all storage-related fields populated
	AddComment(thread *Thread, parent *Comment, comment *Comment) (*Comment, error)
	// Delete comment
	DeleteComment(*Comment) (bool, error)
	// Retrieve comment by id
	GetComment(IDType) (*Comment, error)
	// Retrieve thread by uri
	GetThread(string) (*Thread, error)

	// Creates thread
	CreateThread(uri, title string) (*Thread, error)

	// Retrieve comments for thread at specific URI
	GetThreadedComments(uri *string) (*ThreadedComments, error)

	LikeComment(idType IDType) error
	DislikeComment(idType IDType) error
}

Storage handles storing/retrieving of comments and does not do any access-related checks

func MustOpenSqliteStorage

func MustOpenSqliteStorage(path string) Storage

type Thread

type Thread struct {
	ID    IDType `json:"id" db:"id"`       // unique id of the comment
	URI   string `json:"uri" db:"uri"`     // uri for this comment thread
	Title string `json:"title" db:"title"` // title of the comment
}

Thread represents an ongoing discussion for specific url. Each comment belongs to thread

type ThreadedComments

type ThreadedComments struct {
	Count    int64     `json:"count"`
	Comments []Comment `json:"comments"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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