web

package
v0.7.56 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArticlePageDel          ArticlePageType = "del"
	ArticlePageReply                        = "reply"
	ArticlePageDetail                       = "detail"
	ArticlePageBlockRegions                 = "block_regions"
)
View Source
const (
	MessageStatusUnread MessageStatus = "unread"
	MessageStatusRead                 = "read"
	MessageStatusAll                  = "all"
)
View Source
const (
	AuthTypeGoogle    AuthType = "google"
	AuthTypeGithub             = "github"
	AuthTypeMicrosoft          = "microsoft"
)
View Source
const (
	DefaultPage     int = 1
	DefaultPageSize int = 50
)
View Source
const DefaultReplyPageSize = 50
View Source
const PGErrUniqueViolation = "23505"

https://www.postgresql.org/docs/current/errcodes-appendix.html

Variables

View Source
var (
	// ErrCodeVerifyExpired = errors.New("verification code is expired")
	ErrCodeVerifyIncorrect = errors.New("verification code is incorrect")
)
View Source
var TipStatusStr = map[TipStatus]string{
	TipStatusDeleteSuccess: "Successfully deleted.",
	TipStatusDeleteFailed:  "Failed to delete",
}

Functions

func CeilInt

func CeilInt(a, b int) int

func ClearSession

func ClearSession(cookStore *sessions.CookieStore, w http.ResponseWriter, r *http.Request)

func FileServer

func FileServer(r chi.Router, path string, root http.FileSystem) error

func GetLoginUserId

func GetLoginUserId(sessStore *sessions.CookieStore, w http.ResponseWriter, r *http.Request) (int, error)

func HttpError

func HttpError(msg string, err error, w http.ResponseWriter, code int)

func IsLogin

func IsLogin(sessStore *sessions.CookieStore, w http.ResponseWriter, r *http.Request) bool

func IsRegisterdPage

func IsRegisterdPage(url *url.URL, r *chi.Mux) bool

Types

type AppState

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

type ArticlePageType

type ArticlePageType string

type ArticleResource

type ArticleResource struct {
	*Renderer
	// contains filtered or unexported fields
}

func NewArticleResource

func NewArticleResource(renderer *Renderer) *ArticleResource

func (*ArticleResource) BlockRegions

func (ar *ArticleResource) BlockRegions(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) BlockRegionsPage

func (ar *ArticleResource) BlockRegionsPage(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) Delete

func (ar *ArticleResource) Delete(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) DeletePage

func (ar *ArticleResource) DeletePage(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) FormPage

func (ar *ArticleResource) FormPage(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) HistoryPage

func (ar *ArticleResource) HistoryPage(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) Item

func (*ArticleResource) List

func (*ArticleResource) React

func (ar *ArticleResource) React(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) Recover

func (ar *ArticleResource) Recover(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) ReplyPage

func (ar *ArticleResource) ReplyPage(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) Routes

func (ar *ArticleResource) Routes() http.Handler

func (*ArticleResource) Save

func (*ArticleResource) Share

func (ar *ArticleResource) Share(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) Submit

func (ar *ArticleResource) Submit(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) SubmitReply

func (ar *ArticleResource) SubmitReply(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) Subscribe

func (ar *ArticleResource) Subscribe(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) ToggleFadeOut

func (ar *ArticleResource) ToggleFadeOut(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) ToggleHideHistory

func (ar *ArticleResource) ToggleHideHistory(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) ToggleLock

func (ar *ArticleResource) ToggleLock(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) Update

func (ar *ArticleResource) Update(w http.ResponseWriter, r *http.Request)

func (*ArticleResource) Vote

type AuthType

type AuthType string

type GithubTokenResponse

type GithubTokenResponse struct {
	AccessToken string `json:"access_token"`
	Scope       string `json:"scope"`
	TokenType   string `json:"bearer"`
}

type GithubUserInfo

type GithubUserInfo struct {
	LoginId   string `json:"login"`
	AvatarUrl string `json:"avatar_url"`
	HtmlUrl   string `json:"html_url"`
	Name      string `json:"name"`
	Email     string `json:"email"`
}

type GoogleTokenResponse

type GoogleTokenResponse struct {
	AccessToken      string `json:"access_token"`
	ExpiresInSeconds int    `json:"expires_in"`
	Scope            string `json:"scope"`
	TokenType        string `json:"Bearer"`
	IdToken          string `json:"id_token"`
}

type GoogleUserInfo

type GoogleUserInfo struct {
	SubId         string `json:"sub"`
	Picture       string `json:"picture"`
	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
}

type MainResource

type MainResource struct {
	*Renderer
	// contains filtered or unexported fields
}

func NewMainResource

func NewMainResource(renderer *Renderer, ar *ArticleResource) *MainResource

func (*MainResource) About

func (mr *MainResource) About(w http.ResponseWriter, r *http.Request)

func (*MainResource) CategoryArticleList

func (mr *MainResource) CategoryArticleList(w http.ResponseWriter, r *http.Request)

func (*MainResource) CategoryList

func (mr *MainResource) CategoryList(w http.ResponseWriter, r *http.Request)

func (*MainResource) CategorySubscribe

func (mr *MainResource) CategorySubscribe(w http.ResponseWriter, r *http.Request)

func (*MainResource) Guide

func (mr *MainResource) Guide(w http.ResponseWriter, r *http.Request)

func (*MainResource) Login

func (mr *MainResource) Login(w http.ResponseWriter, r *http.Request)

func (*MainResource) LoginAuthCallback

func (mr *MainResource) LoginAuthCallback(w http.ResponseWriter, r *http.Request)

func (*MainResource) LoginAuthCallbackGithub

func (mr *MainResource) LoginAuthCallbackGithub(w http.ResponseWriter, r *http.Request)

func (*MainResource) LoginDebug

func (mr *MainResource) LoginDebug(w http.ResponseWriter, r *http.Request)

func (*MainResource) LoginPage

func (mr *MainResource) LoginPage(w http.ResponseWriter, r *http.Request)

func (*MainResource) LoginWithOAuth

func (mr *MainResource) LoginWithOAuth(w http.ResponseWriter, r *http.Request)

func (*MainResource) Logout

func (mr *MainResource) Logout(w http.ResponseWriter, r *http.Request)

func (*MainResource) MessageList

func (mr *MainResource) MessageList(w http.ResponseWriter, r *http.Request)

func (*MainResource) Register

func (mr *MainResource) Register(w http.ResponseWriter, r *http.Request)

func (*MainResource) RegisterPage

func (mr *MainResource) RegisterPage(w http.ResponseWriter, r *http.Request)

func (*MainResource) ResendVerifyEmail

func (mr *MainResource) ResendVerifyEmail(w http.ResponseWriter, r *http.Request)

func (*MainResource) ResetPassword

func (mr *MainResource) ResetPassword(w http.ResponseWriter, r *http.Request)

func (*MainResource) ResetPasswordPage

func (mr *MainResource) ResetPasswordPage(w http.ResponseWriter, r *http.Request)

func (*MainResource) RetrievePassword

func (mr *MainResource) RetrievePassword(w http.ResponseWriter, r *http.Request)

func (*MainResource) RetrievePasswordPage

func (mr *MainResource) RetrievePasswordPage(w http.ResponseWriter, r *http.Request)

func (*MainResource) Routes

func (mr *MainResource) Routes() http.Handler

func (*MainResource) SaveAccountSettings

func (mr *MainResource) SaveAccountSettings(w http.ResponseWriter, r *http.Request)

func (*MainResource) SaveUISettings

func (mr *MainResource) SaveUISettings(w http.ResponseWriter, r *http.Request)

func (*MainResource) SettingsAccountPage

func (mr *MainResource) SettingsAccountPage(w http.ResponseWriter, r *http.Request)

func (*MainResource) SettingsPage

func (mr *MainResource) SettingsPage(w http.ResponseWriter, r *http.Request)

func (*MainResource) SettingsUIPage

func (mr *MainResource) SettingsUIPage(w http.ResponseWriter, r *http.Request)

func (*MainResource) VerifyRegister

func (mr *MainResource) VerifyRegister(w http.ResponseWriter, r *http.Request)

func (*MainResource) VerifyRegisterPage

func (mr *MainResource) VerifyRegisterPage(w http.ResponseWriter, r *http.Request)

type ManageResource

type ManageResource struct {
	*Renderer
	// contains filtered or unexported fields
}

func NewManageResource

func NewManageResource(renderer *Renderer, ur *UserResource) *ManageResource

func (*ManageResource) ActivityList

func (mr *ManageResource) ActivityList(w http.ResponseWriter, r *http.Request)

func (*ManageResource) PermissionCreatePage

func (mr *ManageResource) PermissionCreatePage(w http.ResponseWriter, r *http.Request)

func (*ManageResource) PermissionListPage

func (mr *ManageResource) PermissionListPage(w http.ResponseWriter, r *http.Request)

func (*ManageResource) PermissionSubmit

func (mr *ManageResource) PermissionSubmit(w http.ResponseWriter, r *http.Request)

func (*ManageResource) RoleCreatePage

func (mr *ManageResource) RoleCreatePage(w http.ResponseWriter, r *http.Request)

func (*ManageResource) RoleEditPage

func (mr *ManageResource) RoleEditPage(w http.ResponseWriter, r *http.Request)

func (*ManageResource) RoleEditSubmit

func (mr *ManageResource) RoleEditSubmit(w http.ResponseWriter, r *http.Request)

func (*ManageResource) RoleListPage

func (mr *ManageResource) RoleListPage(w http.ResponseWriter, r *http.Request)

func (*ManageResource) RoleSubmit

func (mr *ManageResource) RoleSubmit(w http.ResponseWriter, r *http.Request)

func (*ManageResource) Routes

func (mr *ManageResource) Routes() http.Handler

func (*ManageResource) TrashPage

func (mr *ManageResource) TrashPage(w http.ResponseWriter, r *http.Request)

type MessagePageData

type MessagePageData struct {
	List  []*model.Message
	Query *MessageQueryData
}

type MessageQueryData

type MessageQueryData struct {
	Tab string
	// contains filtered or unexported fields
}

type MessageStatus

type MessageStatus string

type PermissionPageType

type PermissionPageType string
const (
	PermissionPageList   PermissionPageType = "list"
	PermissionPageCreate                    = "create"
)

type RSSResource

type RSSResource struct {
	*Renderer
	// contains filtered or unexported fields
}

func NewRSSResource

func NewRSSResource(renderer *Renderer, ar *ArticleResource) *RSSResource

func (*RSSResource) Atom

func (rr *RSSResource) Atom(w http.ResponseWriter, r *http.Request)

func (*RSSResource) Routes

func (rr *RSSResource) Routes() http.Handler

type Region

type Region struct {
	Name, Value string
	Checked     bool
}

{{- $regions := list "mainland_china" "us" "in" -}} {{- $regionsMap := dict "mainland_china" (local "MainlandChina") "us" (local "UnitedStates") "in" (local "India") -}}

type Renderer

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

func NewRenderer

func NewRenderer(
	tmpl *template.Template,
	sessStore *sessions.CookieStore,
	router *chi.Mux,
	store *store.Store,
	sp *bluemonday.Policy,
	ic *i18nc.I18nCustom,
	srv *service.Service,
	rdb *redis.Client,
	dmp *diffmatchpatch.DiffMatchPatch,
) *Renderer

func (*Renderer) CheckPermit

func (rd *Renderer) CheckPermit(r *http.Request, module, action string) bool

func (*Renderer) Error

func (rd *Renderer) Error(msg string, err error, w http.ResponseWriter, r *http.Request, code int)

func (*Renderer) Forbidden

func (rd *Renderer) Forbidden(err error, w http.ResponseWriter, r *http.Request)

func (*Renderer) GetLoginedUserData

func (rd *Renderer) GetLoginedUserData(r *http.Request) *model.User

func (*Renderer) GetLoginedUserId

func (rd *Renderer) GetLoginedUserId(w http.ResponseWriter, r *http.Request) int

func (*Renderer) GetPaginationData

func (rd *Renderer) GetPaginationData(r *http.Request) (int, int)

func (*Renderer) Local

func (rd *Renderer) Local(id string, data ...any) string

func (*Renderer) NotFound

func (rd *Renderer) NotFound(w http.ResponseWriter, r *http.Request)

func (*Renderer) Render

func (rd *Renderer) Render(w http.ResponseWriter, r *http.Request, name string, data *model.PageData)

func (*Renderer) SavePrevPage

func (rd *Renderer) SavePrevPage(w http.ResponseWriter, r *http.Request)

func (*Renderer) ServerError

func (rd *Renderer) ServerError(w http.ResponseWriter, r *http.Request)

func (*Renderer) ServerErrorp

func (rd *Renderer) ServerErrorp(msg string, err error, w http.ResponseWriter, r *http.Request)

func (*Renderer) Session

func (rd *Renderer) Session(name string, w http.ResponseWriter, r *http.Request) *Session

func (*Renderer) ToLogin

func (rd *Renderer) ToLogin(w http.ResponseWriter, r *http.Request)

func (*Renderer) ToPrevPage

func (rd *Renderer) ToPrevPage(w http.ResponseWriter, r *http.Request)

func (*Renderer) ToRefererUrl

func (rd *Renderer) ToRefererUrl(w http.ResponseWriter, r *http.Request)

func (*Renderer) ToTargetUrl

func (rd *Renderer) ToTargetUrl(w http.ResponseWriter, r *http.Request)

type RoleFormPageData

type RoleFormPageData struct {
	Role                 *model.Role
	RolePermissionIdList []int
	PermissionList       []*model.PermissionListItem
	PageType             RoleFormPageType
}

type RoleFormPageType

type RoleFormPageType string
const (
	RoleFormPageAdd  RoleFormPageType = "add"
	RoleFormPageEdit                  = "edit"
)

type Session

type Session struct {
	Raw *sessions.Session
	// contains filtered or unexported fields
}

func (*Session) Flash

func (ss *Session) Flash(data any, vars ...string)

func (*Session) GetStringValue

func (ss *Session) GetStringValue(key string) string

func (*Session) GetValue

func (ss *Session) GetValue(key string) any

Get value from *sessions.Session.Values

func (*Session) SetValue

func (ss *Session) SetValue(key string, val any)

Set data to *sessons.Session.Values and auto save, handle save error

type SettingsPageData

type SettingsPageData struct {
	PageKey            SettingsPageKey
	AccountData        *model.User
	LanguageOptions    []*model.OptionItem
	ArticleSortTabList []model.ArticleSortType
	ReplySortTabList   []model.ArticleSortType
	SortTabNames       map[model.ArticleSortType]string
}

type SettingsPageKey

type SettingsPageKey string
const (
	SettingsPageKeyUI      SettingsPageKey = "ui"
	SettingsPageKeyAccount                 = "account"
)

type TipStatus

type TipStatus int
const (
	TipStatusDeleteSuccess TipStatus = iota
	TipStatusDeleteFailed
)

type TurnstileVerifyResult

type TurnstileVerifyResult struct {
	Success bool `json:"success"`
}

type UserResource

type UserResource struct {
	*Renderer
	// contains filtered or unexported fields
}

func NewUserResource

func NewUserResource(renderer *Renderer) *UserResource

func (*UserResource) Ban

func (ur *UserResource) Ban(w http.ResponseWriter, r *http.Request)

func (*UserResource) BanPage

func (ur *UserResource) BanPage(w http.ResponseWriter, r *http.Request)

func (*UserResource) EditUserProfilePage

func (ur *UserResource) EditUserProfilePage(w http.ResponseWriter, r *http.Request)

func (*UserResource) ItemPage

func (ur *UserResource) ItemPage(w http.ResponseWriter, r *http.Request)

func (*UserResource) List

func (ur *UserResource) List(w http.ResponseWriter, r *http.Request)

func (*UserResource) Routes

func (ur *UserResource) Routes() http.Handler

func (*UserResource) SetRole

func (ur *UserResource) SetRole(w http.ResponseWriter, r *http.Request)

func (*UserResource) SetRolePage

func (ur *UserResource) SetRolePage(w http.ResponseWriter, r *http.Request)

func (*UserResource) Unban

func (ur *UserResource) Unban(w http.ResponseWriter, r *http.Request)

func (*UserResource) UnbanPage

func (ur *UserResource) UnbanPage(w http.ResponseWriter, r *http.Request)

func (*UserResource) UpdateUserProfile

func (ur *UserResource) UpdateUserProfile(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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