blog

package
v0.0.0-...-209e33c Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ByAuthor = 1
	ByPostId = 2
)
View Source
const (
	SessionAuthorized    = 0
	SessionUnauthorized  = 1
	SessionInternalError = 2
)
View Source
const (
	PermNone   = 0
	PermView   = 1 << iota
	PermEdit   = 1 << iota
	PermDelete = 1 << iota
)
View Source
const Key_SQL_GetPostInfo = `SELECT post.*, ` +
	`IFNULL(poststatistics.star1,0), ` +
	`IFNULL(poststatistics.star2,0), ` +
	`IFNULL(poststatistics.star3,0), ` +
	`IFNULL(poststatistics.star4,0), ` +
	`IFNULL(poststatistics.star5,0)  ` +
	`FROM post ` +
	`LEFT JOIN poststatistics ` +
	`ON post.id = poststatistics.postid ` +
	`WHERE post.id = `
View Source
const Key_SQL_loadPost = `select * from post where id = `

Variables

View Source
var ErrCacheTokenUnmatch = errors.New("Cache token unmatch")
View Source
var ErrCredentialFailed = errors.New("fail to validate credential")
View Source
var ErrHttpUnAuthorized = errors.New("StatusUnauthorized")

Functions

func AnalyzeByAuthor

func AnalyzeByAuthor(name string) int32

func AnalyzePost

func AnalyzePost(text string) (string, error)

func DBGetCache

func DBGetCache(key string, data interface{}) error

func DBRemoveCache

func DBRemoveCache(key string) error

func DBUpdateCache

func DBUpdateCache(key string, data interface{}) error

func Debug

func Debug(s string)

func DeletePost

func DeletePost(id int64) error

func GetCache

func GetCache(key string, data interface{}) error

func HttpLogger

func HttpLogger(writer io.Writer) http.Handler

func Info

func Info(s string)

func IsAdmin

func IsAdmin(username string) bool

func NewRespErr

func NewRespErr(err error, code int, msg ...string) error

func RemoveCache

func RemoveCache(key string) error

func RespondAlert

func RespondAlert(w http.ResponseWriter, err error)

func RespondError

func RespondError(w http.ResponseWriter, err error)

func Run

func Run(addr string)

func UpdateCache

func UpdateCache(key string, data interface{}) error

func UpdateCacheWithLimit

func UpdateCacheWithLimit(key string, data interface{}) error

func ValidateSession

func ValidateSession(w http.ResponseWriter, r *http.Request) (string, error)

func Warn

func Warn(s string)

Types

type AnalyzeHow

type AnalyzeHow int64

type AnalyzeReq

type AnalyzeReq struct {
	How    AnalyzeHow `json:"how"`
	Author string     `json:"author"`
	PostId int64      `json:"id"`
}

type Credentials

type Credentials struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

func (*Credentials) Validate

func (creds *Credentials) Validate() (bool, error)

remaining:

add contraint: validate pwd regexp

type Handler

type Handler interface {
	ServeHTTP(http.ResponseWriter, *http.Request)
	Use(http.Handler) Handler
}

func NewHandler

func NewHandler() Handler

type PageInfo

type PageInfo struct {
	Username string
	Id       int64 `json:"id"`
}

type Post

type Post struct {
	Id       int64     `json:"id"`
	Title    string    `json:"title"`
	Author   string    `json:"author"`
	Date     time.Time `json:"date"`
	Modified time.Time `json:"modified"`
	Body     string    `json:"body"`
}

func (*Post) Validate

func (p *Post) Validate() error

type PostInfo

type PostInfo struct {
	Post
	Star [5]int64 `json:"star"`
}

type PostStatistics

type PostStatistics struct {
	PostId int64    `json:"postid"`
	Star   [5]int64 `json:"star"`
}

type SessionStatus

type SessionStatus uint

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	Rank     string `json:"rank"`
}

type VoteStar

type VoteStar struct {
	Id   int `json:"id"`
	Star int `json:"star"`
}

Jump to

Keyboard shortcuts

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