tagbbs

package module
v0.0.0-...-dde2e2b Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2014 License: MIT Imports: 13 Imported by: 0

README

TagBBS

TagBBS is a tag-based discussion system, based on discussions with @HenryHu.

Design

Aiming to be simple and extensible, the system works against a simple key-value store interface, and should have no internal states. The only requirement of the key-value store is to support a revision field for each key, and update the key only if the new revision is incremented by one.

This package is the core logic of the system and based on it various external interfaces can be built.

A list of interfaces:

  • apibbsd provides a CORS enabled web API endpoint. webui is an web app backed by this interface.
  • sshbbsd provides a simple SSH service.

Key Types

User Editable Keys:

  • post:id are the posts. Readable by
  • user:* are user profiles of each user.

System Keys:

  • bbs:* are the meta data for the BBS.
    • bbs:name is the name of the BBS.
    • bbs:nextid is the next available post id.
    • bbs:users is a list of all available users.
  • userpass:* are the user password hashes.

Index Keys:

  • tag:* are the post lists of every tags.

Post

User Editable Keys are mapped to Posts. A Post is a user editable file, usually consists of a YAML header and a Markdown body. A sample Post:

---
title: Hello World
tags: [test]
authors: [thinxer]
---

There goes the content of the post.

The content of the post should be encoded in UTF-8 and use Unix line-ending.

The YAML header is not limited to the predefined keys. It's okay to abuse it for extra information. However, those predefined keys have special meanings and will be respected by the system.

Here is a list of predefined keys:

  • title is the title of the the post.
  • tags is a list of tags that this post should be listed under.
  • authors is a list of users that this post can be edited with. It is not required to include yourself in this list. As a consequence, you cannot edit this post in the future.

Besides the Content, a Post also has a Rev field, which must be incremented by 1 on each edit (an empty post always has revision 0). Upon each edit, a Timestamp will be marked on the post.

Documentation

Overview

This is the core library for tagbbs, which will be used across different servers.

Index

Constants

View Source
const (
	SuperUser = "sysop"
)

Variables

View Source
var (
	ErrAccessDenied = errors.New("Access Denied")
)
View Source
var ErrSessionNotExist = errors.New("Session Not Exist")

Functions

This section is empty.

Types

type BBS

type BBS struct {
	Storage rkv.S
	Index
	Auth auth.AuthenticationList
	SessionManager
}

func NewBBSFromConfig

func NewBBSFromConfig(configFile string) *BBS

func (*BBS) Get

func (b *BBS) Get(key string, user string) (Post, error)

Get will return the post requested by the user, if the user is permitted.

func (*BBS) Init

func (b *BBS) Init()

func (*BBS) NewPostKey

func (b *BBS) NewPostKey() string

Atomically obtain the next available key for post.

func (*BBS) Put

func (b *BBS) Put(key string, post Post, user string) error

Put will update the post and the index, if the user is permitted.

func (*BBS) Version

func (b *BBS) Version() (string, string, error)

Version will return the name and build version of this installation. name is determined by the title of post:0, and build version is determined at compilation.

type Capability

type Capability int64
const (
	CapRead Capability = 1 << iota
	CapPost
	CapNotification
	CapChat
)

type FrontMatter

type FrontMatter struct {
	Title   string
	Tags    []string
	Authors []string
	Reply   string
	Thread  string
}

type Index

type Index struct {
	rkv.S
}

func (Index) Add

func (in Index) Add(key string, p Post)

func (Index) Query

func (in Index) Query(q string) (ss []string, p ParsedQuery, err error)

func (Index) Remove

func (in Index) Remove(key string, p Post)

func (Index) Replace

func (in Index) Replace(key string, oldpost, newpost Post)

type ParsedQuery

type ParsedQuery struct {
	Tags   []string `json:"tags"`
	Cursor string   `json:"cursor"`
	Before int      `json:"before"`
	After  int      `json:"after"`
}

type Post

type Post rkv.Value

func (*Post) FrontMatter

func (p *Post) FrontMatter() *FrontMatter

func (*Post) String

func (p *Post) String() string

func (*Post) UnmarshalTo

func (p *Post) UnmarshalTo(v interface{}) error

type Session

type Session struct {
	User       string `json:"user"`
	UserAgent  string `json:"user_agent"`
	Capability `json:"capability"`
	LoginTime  time.Time `json:"login_time"`
	RemoteAddr string    `json:"remote_addr"`
}

type SessionManager

type SessionManager struct {
	Store rkv.S
}

func (SessionManager) Get

func (s SessionManager) Get(sid string) (session Session, err error)

func (SessionManager) List

func (s SessionManager) List(user string) (ss map[string]Session, err error)

func (SessionManager) Request

func (s SessionManager) Request(ss Session) (sid string, err error)

func (SessionManager) Revoke

func (s SessionManager) Revoke(sid string) (err error)

func (SessionManager) SetCapability

func (s SessionManager) SetCapability(sid string, capability Capability) error

Directories

Path Synopsis
A unified authentication module.
A unified authentication module.
Key Value Storage with Revision
Key Value Storage with Revision

Jump to

Keyboard shortcuts

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