rtfblog

package
v0.0.0-...-3585659 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: BSD-2-Clause Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxFileSize    = 50 * 1024 * 1024 // bytes
	PostsPerPage   = 5
	NumFeedItems   = 3
	NumRecentPosts = 10
)

Variables

Functions

func CheckCaptcha

func CheckCaptcha(task *CaptchaTask, input string) bool

func DetectLanguageWithTimeout

func DetectLanguageWithTimeout(text string, log *slog.Logger) string

func E

func E(err error) slog.Attr

E is a syntax sugar helper to append an error to a log statement.

func InitL10n

func InitL10n(assets *assets.Bin, userLocale string)

Loads translation files and inits L10n func that retrieves the translations. l10nDir is a name of a directory with translations. userLocale specifies a locale preferred by the user (a preference or accept header or language cookie).

func InsertOrUpdateAuthor

func InsertOrUpdateAuthor(db Data, newAuthor *Author) (id int64, err error)

func InsertOrUpdatePost

func InsertOrUpdatePost(db Data, post *EntryTable) (id int64, err error)

func Main

func Main()

func MkBasicData

func MkBasicData(ctx *Context, pageNo, offset int, conf Config) tmplMap

func MkFlashes

func MkFlashes(ctx *Context) template.HTML

func PublishComment

func PublishComment(db Data, postID, commenterID int64, body string) (string, error)

func PublishCommentAndCommenter

func PublishCommentAndCommenter(db Data, postID int64, commenter *Commenter, rawBody string) (string, error)

func RightCaptchaReply

func RightCaptchaReply(w http.ResponseWriter, redir string, log *slog.Logger) error

func WrongCaptchaReply

func WrongCaptchaReply(w http.ResponseWriter, req *http.Request, status string, task *CaptchaTask, log *slog.Logger) error

Types

type Author

type Author struct {
	ID       int64
	UserName string `gorm:"column:disp_name"`
	Passwd   string `gorm:"column:passwd"`
	FullName string `gorm:"column:full_name"`
	Email    string `gorm:"column:email"`
	Www      string `gorm:"column:www"`
}

type BcryptHelper

type BcryptHelper struct{}

func (BcryptHelper) Decrypt

func (h BcryptHelper) Decrypt(hash, passwd []byte) error

func (BcryptHelper) Encrypt

func (h BcryptHelper) Encrypt(passwd string) (hash string, err error)

type CaptchaTask

type CaptchaTask struct {
	Task   string
	ID     string
	Answer string
}

type Comment

type Comment struct {
	Commenter
	CommentTable
}

type CommentTable

type CommentTable struct {
	CommenterID int64         `gorm:"column:commenter_id"`
	PostID      int64         `gorm:"column:post_id"`
	Body        template.HTML `sql:"-"`
	RawBody     string        `gorm:"column:body"`
	Time        string        `sql:"-"`
	Timestamp   int64         `gorm:"column:timestamp"`
	CommentID   int64         `gorm:"column:id; primary_key:yes"`
}

func (CommentTable) TableName

func (t CommentTable) TableName() string

type CommentWithPostTitle

type CommentWithPostTitle struct {
	Comment
	EntryLink
}

type Commenter

type Commenter struct {
	Name      string
	Email     string
	EmailHash string `sql:"-"`
	Website   string `gorm:"column:www"`
	IP        string `gorm:"column:ip"`
}

type CommenterTable

type CommenterTable struct {
	ID int64
	Commenter
}

func (CommenterTable) TableName

func (t CommenterTable) TableName() string

type Config

type Config struct {
	Server
	Notifications
	Interface
}

type Context

type Context struct {
	Session    *sessions.Session
	AdminLogin bool
	Captcha    *Deck
	// contains filtered or unexported fields
}

func NewContext

func NewContext(req *http.Request, gctx *globalContext) (*Context, error)

type CryptoHelper

type CryptoHelper interface {
	Encrypt(passwd string) (hash string, err error)
	Decrypt(hash, passwd []byte) error
}

type Data

type Data interface {
	// contains filtered or unexported methods
}

type DbData

type DbData struct {
	// contains filtered or unexported fields
}

func InitDB

func InitDB(conf Config, root string, log *slog.Logger) *DbData

type Deck

type Deck struct {
	// contains filtered or unexported fields
}

func NewDeck

func NewDeck() *Deck

func (*Deck) GetTask

func (d *Deck) GetTask(id string) *CaptchaTask

func (*Deck) NextTask

func (d *Deck) NextTask() *CaptchaTask

func (*Deck) SetNextTask

func (d *Deck) SetNextTask(task int)

type Entry

type Entry struct {
	EntryTable
	Author   string     `gorm:"column:disp_name"`
	Tags     []*Tag     `sql:"-"`
	Comments []*Comment `sql:"-"`
}

func (Entry) HasComments

func (e Entry) HasComments() bool

func (Entry) HasTags

func (e Entry) HasTags() bool

func (Entry) NumCommentsStr

func (e Entry) NumCommentsStr() string

func (Entry) TagsList

func (e Entry) TagsList() string

func (Entry) TagsStr

func (e Entry) TagsStr() template.HTML
type EntryLink struct {
	Title  string `gorm:"column:title"`
	URL    string `gorm:"column:url"`
	Hidden bool   `gorm:"column:hidden"`
}

Note: URL mapping is required, gorm won't be able to map to all-caps URL without it. Others are only for consistency.

type EntryTable

type EntryTable struct {
	EntryLink
	ID       int64
	AuthorID int64         `gorm:"column:author_id"`
	Date     string        `sql:"-"`
	UnixDate int64         `gorm:"column:date"`
	Body     template.HTML `sql:"-"`
	RawBody  string        `gorm:"column:body"`
}

func (EntryTable) TableName

func (e EntryTable) TableName() string

type Interface

type Interface struct {
	BlogTitle string `yaml:"blog_title"`
	BlogDescr string `yaml:"blog_descr"`
	Language  string
}

type LangDetector

type LangDetector interface {
	Detect(text string, log *slog.Logger) string
}

type Notifications

type Notifications struct {
	SendEmail    bool   `yaml:"send_email"`
	SenderAcct   string `yaml:"sender_acct"`
	SenderPasswd string `yaml:"sender_passwd"`
	AdminEmail   string `yaml:"admin_email"`
}

type Server

type Server struct {
	DBConn       string `yaml:"db_conn"`
	StaticDir    string `yaml:"static_dir"`
	Favicon      string
	Port         string
	TLSPort      string `yaml:"tls_port"`
	TLSCert      string `yaml:"tls_cert"`
	TLSKey       string `yaml:"tls_key"`
	CookieSecret string `yaml:"cookie_secret"`
	Log          string
	LogSQL       bool   `yaml:"log_sql"`
	UploadsRoot  string `yaml:"uploads_root"`
}

type Tag

type Tag struct {
	ID   int64
	Name string `gorm:"column:tag"`
}

type TagMap

type TagMap struct {
	ID      int64
	TagID   int64 `gorm:"column:tag_id"`
	EntryID int64 `gorm:"column:post_id"`
}

func (TagMap) TableName

func (t TagMap) TableName() string

type XeroxLangDetector

type XeroxLangDetector struct{}

func (XeroxLangDetector) Detect

func (d XeroxLangDetector) Detect(text string, log *slog.Logger) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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