Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

boards source pure

Functions 16

func IsRepost

1func IsRepost(thread *Post) bool
source

IsRepost checks if a thread is a repost.

func IsThread

1func IsThread(p *Post) bool
source

IsThread checks if a post is a thread. When a post is not a thread it's considered a thread's reply/comment.

func SummaryOf

1func SummaryOf(text string, length int) string
source

SummaryOf returns a summary of a text.

func New

1func New(id ID) *Board
source

New creates a new basic non permissioned board.

func NewFlagStorage

1func NewFlagStorage() FlagStorage
source

NewFlagStorage creates a new storage for post flags. The new storage uses an AVL tree to store flagging info.

func NewIdentifierGenerator

1func NewIdentifierGenerator() IdentifierGenerator
source

NewIdentifierGenerator creates a new sequential unique identifier generator.

func NewPermissionSet

1func NewPermissionSet(perms ...Permission) PermissionSet
source

NewPermissionSet creates a new PermissionSet containing the given permissions.

func MustNewReply

1func MustNewReply(parent *Post, creator address, body string) *Post
source

MustNewReply creates a new reply or panics on error.

func MustNewRepost

1func MustNewRepost(thread *Post, dst *Board, creator address) *Post
source

MustNewRepost creates a new thread that is a repost of a thread from another board or panics on error.

func MustNewThread

1func MustNewThread(b *Board, creator address, title, body string) *Post
source

MustNewThread creates a new thread or panics on error.

func NewReply

1func NewReply(parent *Post, creator address, body string) (*Post, error)
source

NewReply creates a new reply to a thread or another reply.

func NewRepost

1func NewRepost(thread *Post, dst *Board, creator address) (*Post, error)
source

NewRepost creates a new thread that is a repost of a thread from another board.

func NewThread

1func NewThread(b *Board, creator address, title, body string) (*Post, error)
source

NewThread creates a new board thread.

func NewPostStorage

1func NewPostStorage() PostStorage
source

NewPostStorage creates a new storage for posts. The new storage uses an AVL tree to store posts.

func NewRepostStorage

1func NewRepostStorage() RepostStorage
source

NewRepostStorage creates a new storage for reposts. The new storage uses an AVL tree to store reposts.

func NewStorage

1func NewStorage() Storage
source

NewStorage creates a new boards storage.

Types 20

type Args

slice
1type Args []interface{}
source

Args is a list of generic arguments.

type Board

struct
 1type Board struct {
 2	// ID is the unique identifier of the board.
 3	ID ID
 4
 5	// Name is the current name of the board.
 6	Name string
 7
 8	// Aliases contains a list of alternative names for the board.
 9	Aliases []string
10
11	// Readonly indicates that the board is readonly.
12	Readonly bool
13
14	// Threads contains board threads.
15	Threads PostStorage
16
17	// ThreadsSequence generates sequential ID for new threads.
18	ThreadsSequence IdentifierGenerator
19
20	// Permissions enables support for permissioned boards.
21	// This type of boards allows managing members with roles and permissions.
22	// It also enables the implementation of permissioned execution of board related features.
23	Permissions Permissions
24
25	// Creator is the account address that created the board.
26	Creator address
27
28	// Meta allows storing board metadata.
29	Meta any
30
31	// CreatedAt is the board's creation time.
32	CreatedAt time.Time
33
34	// UpdatedAt is the board's update time.
35	UpdatedAt time.Time
36}
source

Board defines a type for boards.

Methods on Board

func SetAliases

method on Board
1func (board *Board) SetAliases(v []string)
source

SetAliases sets board name aliases.

func SetCreatedAt

method on Board
1func (board *Board) SetCreatedAt(v time.Time)
source

SetCreatedAt sets the time when board was created.

func SetCreator

method on Board
1func (board *Board) SetCreator(v address)
source

SetCreator sets the address of the account that created the board.

func SetID

method on Board
1func (board *Board) SetID(v ID)
source

SetID sets board ID value.

func SetMeta

method on Board
1func (board *Board) SetMeta(v any)
source

SetMeta sets board metadata.

func SetName

method on Board
1func (board *Board) SetName(v string)
source

SetName sets name value.

func SetPermissions

method on Board
1func (board *Board) SetPermissions(v Permissions)
source

SetPermissions sets permissions value.

func SetReadonly

method on Board
1func (board *Board) SetReadonly(v bool)
source

SetReadonly sets readonly value.

func SetThreadStorage

method on Board
1func (board *Board) SetThreadStorage(v PostStorage)
source

SetThreadStorage sets the storage where board threads are stored.

func SetThreadsSequence

method on Board
1func (board *Board) SetThreadsSequence(v IdentifierGenerator)
source

SetThreadsSequence sets the sequential thread ID generator.

func SetUpdatedAt

method on Board
1func (board *Board) SetUpdatedAt(v time.Time)
source

SetUpdatedAt sets the time when a board value was updated.

type BoardIterFn

func
1type BoardIterFn func(*Board) bool
source

BoardIterFn defines a function type to iterate boards.

type Flag

struct
1type Flag struct {
2	// User is the user that flagged the post.
3	User address
4
5	// Reason is the reason that describes why post is flagged.
6	Reason string
7}
source

Flag defines a type for post flags

type FlagIterFn

func
1type FlagIterFn func(Flag) bool
source

FlagIterFn defines a function type to iterate post flags.

type FlagStorage

interface
 1type FlagStorage interface {
 2	// Exists checks if a flag from a user exists
 3	Exists(address) bool
 4
 5	// Add adds a new flag from a user.
 6	Add(Flag) error
 7
 8	// Remove removes a user flag.
 9	Remove(address) (removed bool)
10
11	// Size returns the number of flags in the storage.
12	Size() int
13
14	// Iterate iterates post flags.
15	// To reverse iterate flags use a negative count.
16	// If the callback returns true, the iteration is stopped.
17	Iterate(start, count int, fn FlagIterFn) bool
18}
source

FlagStorage defines an interface for storing posts flagging information.

type ID

ident
1type ID uint64
source

ID defines a type for unique identifiers.

Methods on ID

func Key

method on ID
1func (id ID) Key() string
source

Key returns the ID as a string which can be used to index by ID.

func PaddedString

method on ID
1func (id ID) PaddedString() string
source

PaddedString returns the ID as a 10 character string padded with zeroes. This value can be used for indexing by ID.

func String

method on ID
1func (id ID) String() string
source

String returns the ID as a string.

type IdentifierGenerator

interface
1type IdentifierGenerator interface {
2	// Current returns the last generated ID.
3	Last() ID
4
5	// Next generates a new ID or panics if increasing ID overflows.
6	Next() ID
7}
source

IdentifierGenerator defines an interface for sequential unique identifier generators.

type Permission

ident
1type Permission uint16
source

Permission defines the type for permissions.

Methods on Permission

func String

method on Permission
1func (p Permission) String() string
source

String returns the string representation of a permission value.

type PermissionSet

slice
1type PermissionSet []uint64
source

PermissionSet defines a type to store any number of permissions.

Methods on PermissionSet

func Has

method on PermissionSet
1func (s PermissionSet) Has(p Permission) bool
source

Has checks if a permission is in the set.

func IsEmpty

method on PermissionSet
1func (s PermissionSet) IsEmpty() bool
source

IsEmpty reports whether the set contains no permissions.

type Permissions

interface
 1type Permissions interface {
 2	// HasRole checks if a user has a specific role assigned.
 3	HasRole(address, Role) bool
 4
 5	// HasPermission checks if a user has a specific permission.
 6	HasPermission(address, Permission) bool
 7
 8	// WithPermission calls a callback when a user has a specific permission.
 9	// It panics on error.
10	//
11	// An inline crossing function call can be used by the implementation if
12	// crossing is required to update its internal state, for example to create
13	// proposals that when approved execute the callback:
14	//
15	//  func(realm) {
16	//    // Update internal realm state
17	//    // ...
18	//  }(cross)
19	WithPermission(address, Permission, Args, func())
20
21	// SetUserRoles adds a new user when it doesn't exist and sets its roles.
22	// Method can also be called to change the roles of an existing user.
23	// It panics on error.
24	SetUserRoles(address, ...Role)
25
26	// RemoveUser removes a user from the permissioner.
27	// It panics on error.
28	RemoveUser(address) (removed bool)
29
30	// HasUser checks if a user exists.
31	HasUser(address) bool
32
33	// UsersCount returns the total number of users the permissioner contains.
34	UsersCount() int
35
36	// IterateUsers iterates permissions' users.
37	IterateUsers(start, count int, fn UsersIterFn) bool
38}
source

Permissions define an interface to for permissioned execution.

type Post

struct
 1type Post struct {
 2	// ID is the unique identifier of the post.
 3	ID ID
 4
 5	// ParentID is the ID of the parent post.
 6	ParentID ID
 7
 8	// ThreadID contains the post ID of the thread where current post is created.
 9	// If current post is a thread it contains post's ID.
10	// It should be used when current post is a thread or reply.
11	ThreadID ID
12
13	// OriginalBoardID contains the board ID of the original post when current post is a repost.
14	OriginalBoardID ID
15
16	// Board contains the board where post is created.
17	Board *Board
18
19	// Title contains the post's title.
20	Title string
21
22	// Body contains content of the post.
23	Body string
24
25	// Hidden indicates that the post is hidden.
26	Hidden bool
27
28	// Readonly indicates that the post is readonly.
29	Readonly bool
30
31	// Replies stores post replies.
32	Replies PostStorage
33
34	// Reposts stores reposts of the current post.
35	// It should be used when post is a thread.
36	Reposts RepostStorage
37
38	// Flags stores users flags for the current post.
39	Flags FlagStorage
40
41	// Creator is the account address that created the post.
42	Creator address
43
44	// Meta allows storing post metadata.
45	Meta any
46
47	// CreatedAt is the post's creation time.
48	CreatedAt time.Time
49
50	// UpdatedAt is the post's update time.
51	UpdatedAt time.Time
52}
source

Post defines a generic type for posts. A post can be either a thread or a reply.

Methods on Post

func SetBoard

method on Post
1func (post *Post) SetBoard(v *Board)
source

SetBoard sets the board where post was created.

func SetBody

method on Post
1func (post *Post) SetBody(v string)
source

SetBody sets post's content.

func SetCreatedAt

method on Post
1func (post *Post) SetCreatedAt(v time.Time)
source

SetCreatedAt sets the time when post was created.

func SetCreator

method on Post
1func (post *Post) SetCreator(v address)
source

SetCreator sets the address of the account that created the post.

func SetFlagStorage

method on Post
1func (post *Post) SetFlagStorage(v FlagStorage)
source

SetFlagStorage sets the storage where post flags are stored.

func SetHidden

method on Post
1func (post *Post) SetHidden(v bool)
source

SetHidden sets hidden value.

func SetID

method on Post
1func (post *Post) SetID(v ID)
source

SetID sets post ID value.

func SetOriginalBoardID

method on Post
1func (post *Post) SetOriginalBoardID(v ID)
source

SetOriginalBoardID sets the board ID of the original post when current post is a repost.

func SetParentID

method on Post
1func (post *Post) SetParentID(v ID)
source

SetParentID sets post's parent ID value.

func SetReadonly

method on Post
1func (post *Post) SetReadonly(v bool)
source

SetReadonly sets readonly value.

func SetReplyStorage

method on Post
1func (post *Post) SetReplyStorage(v PostStorage)
source

SetReplyStorage sets the storage where post replies are stored.

func SetRepostStorage

method on Post
1func (post *Post) SetRepostStorage(v RepostStorage)
source

SetRepostStorage sets the storage where thread reposts are stored.

func SetThreadID

method on Post
1func (post *Post) SetThreadID(v ID)
source

SetThreadID sets thread ID value.

func SetTitle

method on Post
1func (post *Post) SetTitle(v string)
source

SetTitle sets title value.

func SetUpdatedAt

method on Post
1func (post *Post) SetUpdatedAt(v time.Time)
source

SetUpdatedAt sets the time when a post value was updated.

func Summary

method on Post
1func (post Post) Summary() string
source

Summary return a summary of the post's body. It returns the body making sure that the length is limited to 80 characters.

type PostIterFn

func
1type PostIterFn func(*Post) bool
source

PostIterFn defines a function type to iterate posts.

type PostStorage

interface
 1type PostStorage interface {
 2	// Get retruns a post that matches an ID.
 3	Get(ID) (_ *Post, found bool)
 4
 5	// Remove removes a post from the storage.
 6	Remove(ID) (_ *Post, removed bool)
 7
 8	// Add adds a post in the storage.
 9	Add(*Post) error
10
11	// Size returns the number of posts in the storage.
12	Size() int
13
14	// Iterate iterates posts.
15	// To reverse iterate posts use a negative count.
16	// If the callback returns true, the iteration is stopped.
17	Iterate(start, count int, fn PostIterFn) bool
18}
source

PostStorage defines an interface for posts storage.

type RepostIterFn

func
1type RepostIterFn func(board, repost ID) bool
source

RepostIterFn defines a function type to iterate reposts.

type RepostStorage

interface
 1type RepostStorage interface {
 2	// Get returns the repost ID for a board.
 3	Get(board ID) (repost ID, found bool)
 4
 5	// Add adds a new repost to the storage.
 6	Add(repost *Post) error
 7
 8	// Remove removes repost for a board.
 9	Remove(board ID) (removed bool)
10
11	// Size returns the number of reposts in the storage.
12	Size() int
13
14	// Iterate iterates reposts.
15	// To reverse iterate reposts use a negative count.
16	// If the callback returns true, the iteration is stopped.
17	Iterate(start, count int, fn RepostIterFn) bool
18}
source

RepostStorage defines an interface for storing reposts.

type Role

ident
1type Role string
source

Role defines the type for user roles.

type Storage

interface
 1type Storage interface {
 2	// Get retruns a boards that matches an ID.
 3	Get(ID) (_ *Board, found bool)
 4
 5	// GetByName retruns a boards that matches a name.
 6	GetByName(name string) (_ *Board, found bool)
 7
 8	// Remove removes a board from the storage.
 9	Remove(ID) (_ *Board, removed bool)
10
11	// Add adds a board to the storage.
12	Add(*Board) error
13
14	// Size returns the number of boards in the storage.
15	Size() int
16
17	// Iterate iterates boards.
18	// To reverse iterate boards use a negative count.
19	// If the callback returns true, the iteration is stopped.
20	Iterate(start, count int, fn BoardIterFn) bool
21}
source

Storage defines an interface for boards storage.

type User

struct
1type User struct {
2	Address address
3	Roles   []Role
4}
source

User contains user info.

type UsersIterFn

func
1type UsersIterFn func(User) bool
source

UsersIterFn defines a function type to iterate users.

Imports 7

Source Files 22