Documentation
¶
Index ¶
- Variables
- func Big5ToUtf8(input []byte) string
- func CstrToBytes(cstr Cstr) []byte
- func CstrToString(cstr Cstr) string
- func FilterStringANSI(src string) string
- func Register(drivername string, connector Connector)
- func Utf8ToBig5(input string) []byte
- type ArticleRecord
- type BadPostUserRecord
- type BoardRecord
- type BoardRecordInfo
- type BoardRecordSettings
- type Connector
- type Cstr
- type DB
- func (db *DB) AddArticleRecordFileRecord(boardID string, article ArticleRecord) error
- func (db *DB) AddBoardRecord(brd BoardRecord) error
- func (db *DB) AppendBoardArticleFile(boardID string, filename string, content []byte) error
- func (db *DB) CreateArticleRecord(boardID, owner, date, title string) (ArticleRecord, error)
- func (db *DB) DeleteUserDraft(userID, draftID string) error
- func (db *DB) GetBoardArticleCommentRecords(boardID string, ar ArticleRecord) (crs []UserCommentRecord, err error)
- func (db *DB) GetBoardUserCommentRecord(boardID, userID string) (recs []UserCommentRecord, err error)
- func (db *DB) GetUserArticleRecordFile(userID string) ([]UserArticleRecord, error)
- func (db *DB) GetUserCommentRecordFile(userID string) ([]UserCommentRecord, error)
- func (db *DB) GetUserDrafts(userID, draftID string) (UserDraft, error)
- func (db *DB) NewBoardRecord(args map[string]interface{}) (BoardRecord, error)
- func (db *DB) ReadBoardArticleFile(boardID string, filename string) ([]byte, error)
- func (db *DB) ReadBoardArticleRecordsFile(boardID string) ([]ArticleRecord, error)
- func (db *DB) ReadBoardRecord(index uint) (*BoardRecord, error)
- func (db *DB) ReadBoardRecords() ([]BoardRecord, error)
- func (db *DB) ReadBoardTreasureFile(boardID string, treasuresID []string, filename string) ([]byte, error)
- func (db *DB) ReadBoardTreasureRecordsFile(boardID string, treasureID []string) ([]ArticleRecord, error)
- func (db *DB) ReadUserFavoriteRecords(userID string) ([]FavoriteRecord, error)
- func (db *DB) ReadUserRecords() ([]UserRecord, error)
- func (db *DB) RemoveBoardRecord(index uint) error
- func (db *DB) UpdateBoardRecord(index uint, brd *BoardRecord) error
- func (db *DB) WriteBoardArticleFile(boardID, filename string, content []byte) error
- func (db *DB) WriteUserDraft(userID, draftID string, draftContent UserDraft) error
- type FavoriteRecord
- type FavoriteType
- type LastCountryUserRecord
- type MailboxUserRecord
- type UserArticleConnector
- type UserArticleRecord
- type UserCommentConnector
- type UserCommentRecord
- type UserDraft
- type UserDraftConnector
- type UserRecord
- type WriteArticleConnector
- type WriteBoardConnector
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Big5ToUtf8 ¶
func CstrToBytes ¶
CstrToBytes
Only the bytes until \0. See tests for more examples.
Params
cstr
Return
[]byte: bytes
func CstrToString ¶
CstrToString
Only the bytes until \0 when converting to string. See tests for more examples.
Params
cstr
Return
string: string
func FilterStringANSI ¶ added in v0.5.0
func Utf8ToBig5 ¶
Types ¶
type ArticleRecord ¶
type BadPostUserRecord ¶ added in v0.3.0
type BadPostUserRecord interface { // NumBadPosts return how many bad post this use have NumBadPosts() int }
BadPostUserRecord return UserRecord interface which support NumBadPosts
type BoardRecord ¶
type BoardRecordInfo ¶ added in v0.5.0
type BoardRecordSettings ¶ added in v0.5.0
type BoardRecordSettings interface { IsHide() bool IsPostMask() bool IsAnonymous() bool IsDefaultAnonymous() bool IsNoCredit() bool IsVoteBoard() bool IsWarnEL() bool IsTop() bool IsNoRecommend() bool IsAngelAnonymous() bool IsBMCount() bool IsNoBoo() bool IsRestrictedPost() bool IsGuestPost() bool IsCooldown() bool IsCPLog() bool IsNoFastRecommend() bool IsIPLogRecommend() bool IsOver18() bool IsNoReply() bool IsAlignedComment() bool IsNoSelfDeletePost() bool IsBMMaskContent() bool }
type Connector ¶
type Connector interface { // Open provides the driver parameter settings, such as BBSHome parameter and SHM parameters. Open(dataSourceName string) error // GetUserRecordsPath should return user records file path, eg: BBSHome/.PASSWDS GetUserRecordsPath() (string, error) // ReadUserRecordsFile should return UserRecord list in the file called name ReadUserRecordsFile(name string) ([]UserRecord, error) // GetUserFavoriteRecordsPath should return the user favorite records file path // for specific user, eg: BBSHOME/home/{{u}}/{{userID}}/.fav GetUserFavoriteRecordsPath(userID string) (string, error) // ReadUserFavoriteRecordsFile should return FavoriteRecord list in the file called name ReadUserFavoriteRecordsFile(name string) ([]FavoriteRecord, error) // GetBoardRecordsPath should return the board headers file path, eg: BBSHome/.BRD GetBoardRecordsPath() (string, error) // ReadBoardRecordsFile shoule return BoardRecord list in file, name is the file name ReadBoardRecordsFile(name string) ([]BoardRecord, error) // GetBoardArticleRecordsPath should return the article records file path, boardID is the board id, // eg: BBSHome/boards/{{b}}/{{boardID}}/.DIR GetBoardArticleRecordsPath(boardID string) (string, error) // GetBoardArticleRecordsPath should return the treasure records file path, boardID is the board id, // eg: BBSHome/man/boards/{{b}}/{{boardID}}/{{treasureID}}/.DIR GetBoardTreasureRecordsPath(boardID string, treasureID []string) (string, error) // ReadArticleRecordsFile returns ArticleRecord list in file, name is the file name ReadArticleRecordsFile(name string) ([]ArticleRecord, error) // GetBoardArticleFilePath return file path for specific boardID and filename GetBoardArticleFilePath(boardID string, filename string) (string, error) // GetBoardTreasureFilePath return file path for specific boardID, treasureID and filename GetBoardTreasureFilePath(boardID string, treasureID []string, name string) (string, error) // ReadBoardArticleFile should returns raw file of specific file name ReadBoardArticleFile(name string) ([]byte, error) }
Driver should implement Connector interface
type Cstr ¶
type Cstr []byte
Cstr
[]byte with C String property in that \0 is considered as the end of the bytes/string. It is used to convert from fixed-length bytes to string or []byte with no \0.
Naming Cstr instead of CString is to avoid confusion with C.CString (C.CString is from string, and should be compatible with string, not with []byte) (We also have str(len/cpy/cmp) functions in C)
See tests for more examples of how to use fixed-bytes with Cstr to get no-\0 string / []byte
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is whole bbs filesystem, including where file store, how to connect to local cache ( system V shared memory or etc.) how to parse or store it's data to bianry
func (*DB) AddArticleRecordFileRecord ¶ added in v0.5.0
func (db *DB) AddArticleRecordFileRecord(boardID string, article ArticleRecord) error
AddArticleRecordFileRecord append article ArticleRecord to boardID
func (*DB) AddBoardRecord ¶ added in v0.3.0
func (db *DB) AddBoardRecord(brd BoardRecord) error
func (*DB) AppendBoardArticleFile ¶ added in v0.8.1
func (*DB) CreateArticleRecord ¶ added in v0.8.1
func (db *DB) CreateArticleRecord(boardID, owner, date, title string) (ArticleRecord, error)
CreateArticleRecord returns new ArticleRecord with new filename in boardID and owner, date and title. This method will find a usable filename in board and occupy it.
func (*DB) DeleteUserDraft ¶ added in v0.5.0
func (*DB) GetBoardArticleCommentRecords ¶ added in v0.5.0
func (db *DB) GetBoardArticleCommentRecords(boardID string, ar ArticleRecord) (crs []UserCommentRecord, err error)
GetBoardArticleCommentRecords returns the comment records of the specific article.
func (*DB) GetBoardUserCommentRecord ¶ added in v0.5.0
func (db *DB) GetBoardUserCommentRecord(boardID, userID string) (recs []UserCommentRecord, err error)
GetBoardUserCommentRecord returns the comment records of the user from the specific board.
func (*DB) GetUserArticleRecordFile ¶ added in v0.4.0
func (db *DB) GetUserArticleRecordFile(userID string) ([]UserArticleRecord, error)
GetUserArticleRecordFile returns aritcle file which user posted.
func (*DB) GetUserCommentRecordFile ¶ added in v0.5.0
func (db *DB) GetUserCommentRecordFile(userID string) ([]UserCommentRecord, error)
GetUserCommentRecordFile returns the comment records of the specific user from all boards and all articles.
func (*DB) GetUserDrafts ¶ added in v0.6.0
func (*DB) NewBoardRecord ¶ added in v0.3.0
func (db *DB) NewBoardRecord(args map[string]interface{}) (BoardRecord, error)
func (*DB) ReadBoardArticleFile ¶
func (*DB) ReadBoardArticleRecordsFile ¶
func (db *DB) ReadBoardArticleRecordsFile(boardID string) ([]ArticleRecord, error)
func (*DB) ReadBoardRecord ¶ added in v0.3.0
func (db *DB) ReadBoardRecord(index uint) (*BoardRecord, error)
ReadBoardRecordFileRecord return boardRecord brd on index in record file.
func (*DB) ReadBoardRecords ¶
func (db *DB) ReadBoardRecords() ([]BoardRecord, error)
ReadBoardRecords returns the UserRecords
func (*DB) ReadBoardTreasureFile ¶
func (*DB) ReadBoardTreasureRecordsFile ¶
func (db *DB) ReadBoardTreasureRecordsFile(boardID string, treasureID []string) ([]ArticleRecord, error)
func (*DB) ReadUserFavoriteRecords ¶
func (db *DB) ReadUserFavoriteRecords(userID string) ([]FavoriteRecord, error)
ReadUserFavoriteRecords returns the FavoriteRecord for specific userID
func (*DB) ReadUserRecords ¶
func (db *DB) ReadUserRecords() ([]UserRecord, error)
ReadUserRecords returns the UserRecords
func (*DB) RemoveBoardRecord ¶ added in v0.3.0
RemoveBoardRecordFileRecord remove boardRecord brd on index in record file.
func (*DB) UpdateBoardRecord ¶ added in v0.3.0
func (db *DB) UpdateBoardRecord(index uint, brd *BoardRecord) error
UpdateBoardRecordFileRecord update boardRecord brd on index in record file, index is start with 0
func (*DB) WriteBoardArticleFile ¶ added in v0.8.1
WriteBoardArticleFile writes content into filename in boardID
type FavoriteRecord ¶
type FavoriteRecord interface { Title() string Type() FavoriteType BoardID() string // Records is FavoriteTypeFolder only. Records() []FavoriteRecord }
type FavoriteType ¶
type FavoriteType int
const ( FavoriteTypeBoard FavoriteType = iota // 0 FavoriteTypeFolder // 1 FavoriteTypeLine // 2 )
type LastCountryUserRecord ¶ added in v0.3.0
type LastCountryUserRecord interface { // LastLoginCountry will return the country with this user's last login IP LastLoginCountry() string }
LastCountryUserRecord return UserRecord interface which support LastCountry
type MailboxUserRecord ¶ added in v0.3.0
type MailboxUserRecord interface { // MailboxDescription will return the mailbox description with this user MailboxDescription() string }
MailboxUserRecord return UserRecord interface which support MailboxDescription
type UserArticleConnector ¶ added in v0.4.0
type UserArticleConnector interface { // GetUserArticleRecordsPath should return the file path which user article record stores. GetUserArticleRecordsPath(userID string) (string, error) // ReadUserArticleRecordFile should return the article record in file. ReadUserArticleRecordFile(name string) ([]UserArticleRecord, error) // WriteUserArticleRecordFile write user article records into file. WriteUserArticleRecordFile(name string, records []UserArticleRecord) error // AppendUserArticleRecordFile append user article records into file. AppendUserArticleRecordFile(name string, record UserArticleRecord) error }
UserArticleConnector is a connector for bbs who support cached user article records
type UserArticleRecord ¶ added in v0.4.0
type UserCommentConnector ¶ added in v0.5.0
type UserCommentConnector interface { // GetUserCommentRecordsPath should return the file path where storing the // user comment records. GetUserCommentRecordsPath(userID string) (string, error) // ReadUserCommentRecordFile should return the use comment records from the // file. ReadUserCommentRecordFile(name string) ([]UserCommentRecord, error) }
UserCommentConnector is a connector for bbs to access the cached user comment records.
type UserCommentRecord ¶ added in v0.5.0
type UserCommentRecord interface { CommentOrder() uint32 CommentTime() time.Time Owner() string IP() string Comment() string String() string BoardID() string Filename() string }
func NewUserCommentRecord ¶ added in v0.5.0
func NewUserCommentRecord(order uint32, data string, boardID string, ar ArticleRecord) (UserCommentRecord, error)
NewUserCommentRecord parses the data and returns the user comment record.
Return error when input data is not matched the user comment pattern.
type UserDraft ¶ added in v0.6.0
type UserDraft interface {
Raw() []byte
}
func NewUserDraft ¶ added in v0.6.0
type UserDraftConnector ¶ added in v0.5.0
type UserDraftConnector interface { // GetUserDraftPath should return the user's draft file path // eg: BBSHome/home/{{u}}/{{userID}}/buf.{{draftID}} GetUserDraftPath(userID, draftID string) (string, error) // ReadUserDraft return the user draft from the named file. ReadUserDraft(name string) ([]byte, error) // DeleteUserDraft should remove the named file. DeleteUserDraft(name string) error // WriteUserDraft should replace user draft from named file and user draft data WriteUserDraft(name string, draft []byte) error }
UserDraftConnector is a connector for bbs which supports modify user draft file.
type UserRecord ¶
type UserRecord interface { // UserID return user's identification string, and it is userid in // mostly bbs system UserID() string // HashedPassword return user hashed password, it only for debug, // If you want to check is user password correct, please use // VerifyPassword insteaded. HashedPassword() string // VerifyPassword will check user's password is OK. it will return null // when OK and error when there are something wrong VerifyPassword(password string) error // Nickname return a string for user's nickname, this string may change // depend on user's mood, return empty string if this bbs system do not support Nickname() string // RealName return a string for user's real name, this string may not be changed // return empty string if this bbs system do not support RealName() string // NumLoginDays return how many days this have been login since account created. NumLoginDays() int // NumPosts return how many posts this user has posted. NumPosts() int // Money return the money this user have. Money() int // LastLogin return last login time of user LastLogin() time.Time // LastHost return last login host of user, it is IPv4 address usually, but it // could be domain name or IPv6 address. LastHost() string // UserFlag return user setting. // uint32, see https://github.com/ptt/pttbbs/blob/master/include/uflags.h UserFlag() uint32 }
UserRecord mapping to `userec` in most system, it records uesr's basical data
type WriteArticleConnector ¶ added in v0.5.0
type WriteArticleConnector interface { // CreateBoardArticleFilename returns available filename for board with boardID CreateBoardArticleFilename(boardID string) (filename string, err error) // NewArticleRecord return ArticleRecord object in this driver with arguments NewArticleRecord(filename, owner, date, title string) (ArticleRecord, error) // AddArticleRecordFileRecord given record file name and new record, should append // file record in that file. AddArticleRecordFileRecord(name string, article ArticleRecord) error // UpdateArticleRecordFileRecord will write article in position index of name file // position is start with 0. UpdateArticleRecordFileRecord(name string, index uint, article ArticleRecord) error // WriteBoardArticleFile will turncate name file and write content into that file. WriteBoardArticleFile(name string, content []byte) error // AppendNewLine append content into file AppendBoardArticleFile(name string, content []byte) error }
WriteArticleConnector is a connector for writing a article
type WriteBoardConnector ¶
type WriteBoardConnector interface { // NewBoardRecord return BoardRecord object in this driver with arguments NewBoardRecord(args map[string]interface{}) (BoardRecord, error) // AddBoardRecordFileRecord given record file name and new record, should append // file record in that file. AddBoardRecordFileRecord(name string, brd BoardRecord) error // UpdateBoardRecordFileRecord update boardRecord brd on index in record file, // index is start with 0 UpdateBoardRecordFileRecord(name string, index uint, brd BoardRecord) error // ReadBoardRecordFileRecord return boardRecord brd on index in record file. ReadBoardRecordFileRecord(name string, index uint) (BoardRecord, error) // RemoveBoardRecordFileRecord remove boardRecord brd on index in record file. RemoveBoardRecordFileRecord(name string, index uint) error }
Driver which implement WriteBoardConnector supports modify board record file.