Documentation ¶
Index ¶
- Constants
- Variables
- func APIHandler(inner CustomHandlerFunc) http.Handler
- func ActiveServerMW(inner http.Handler) http.Handler
- func AddGlobalTemplateData(key string, data interface{})
- func AuthTokenFromB64(b64 string) (t *oauth2.Token, err error)
- func BaseTemplateDataMiddleware(inner http.Handler) http.Handler
- func CheckCSRFToken(client *redis.Client, token string) (bool, error)
- func CheckErr(t TemplateData, err error, errMsg string, logger func(...interface{})) bool
- func ControllerHandler(f ControllerHandlerFunc, templateName string) http.Handler
- func ControllerPostHandler(mainHandler ControllerHandlerFunc, extraHandler http.Handler, ...) http.Handler
- func CreateCSRFToken(client *redis.Client) (string, error)
- func CreateCookieSession(token *oauth2.Token, redisClient *redis.Client) (cookie *http.Cookie, err error)
- func CtxLogger(ctx context.Context) *log.Entry
- func DiscordSessionFromContext(ctx context.Context) *discordgo.Session
- func FormParserMW(inner http.Handler, dst interface{}) http.Handler
- func GenSessionCookie() *http.Cookie
- func HandleCPLogs(w http.ResponseWriter, r *http.Request) interface{}
- func HandleChanenlPermissions(w http.ResponseWriter, r *http.Request) interface{}
- func HandleConfirmLogin(w http.ResponseWriter, r *http.Request)
- func HandleLogin(w http.ResponseWriter, r *http.Request)
- func HandleLogout(w http.ResponseWriter, r *http.Request)
- func HandleSelectServer(w http.ResponseWriter, r *http.Request) interface{}
- func HasPermissionCTX(ctx context.Context, perms int) bool
- func InitOauth()
- func IsAcceptingRequests() bool
- func IsAdminCtx(ctx context.Context) bool
- func LoadAd()
- func LoadTemplates()
- func LogIgnoreErr(err error)
- func MiscMiddleware(inner http.Handler) http.Handler
- func NewPublicError(a ...interface{}) error
- func RandBase64(size int) string
- func RedisClientFromContext(ctx context.Context) *redis.Client
- func RedisMiddleware(inner http.Handler) http.Handler
- func RenderHandler(inner CustomHandlerFunc, tmpl string) http.Handler
- func RequestLogger(logger io.Writer) func(http.Handler) http.Handler
- func RequireActiveServer(inner http.Handler) http.Handler
- func RequireBotMemberMW(inner http.Handler) http.Handler
- func RequireFullGuildMW(inner http.Handler) http.Handler
- func RequireGuildChannelsMiddleware(inner http.Handler) http.Handler
- func RequirePermMW(perms ...int) func(http.Handler) http.Handler
- func RequireServerAdminMiddleware(inner http.Handler) http.Handler
- func RequireSessionMiddleware(inner http.Handler) http.Handler
- func Run()
- func SessionMiddleware(inner http.Handler) http.Handler
- func SetContextTemplateData(ctx context.Context, data map[string]interface{}) context.Context
- func SimpleConfigSaverHandler(t SimpleConfigSaver, extraHandler http.Handler) http.Handler
- func Stop()
- func UserInfoMiddleware(inner http.Handler) http.Handler
- func ValidateChannelField(s int64, channels []*discordgo.Channel, allowEmpty bool) error
- func ValidateFloatField(f float64, min, max float64) error
- func ValidateForm(guild *discordgo.Guild, tmpl TemplateData, form interface{}) bool
- func ValidateIntField(i int64, tags *ValidationTag, guild *discordgo.Guild) (keep bool, err error)
- func ValidateIntMinMaxField(i int64, min, max int64) error
- func ValidateIntSliceField(is []int64, tags *ValidationTag, guild *discordgo.Guild) (filtered []int64, err error)
- func ValidateNormalStringField(s string, min, max int) error
- func ValidateRegexField(s string, max int) error
- func ValidateRoleField(s int64, roles []*discordgo.Role, allowEmpty bool) error
- func ValidateStringField(s string, tags *ValidationTag, guild *discordgo.Guild) (str string, err error)
- func ValidateTemplateField(s string, max int) error
- func WriteErrorResponse(w http.ResponseWriter, r *http.Request, err string, statusCode int)
- type APIError
- type Advertisement
- type Alert
- type ControllerHandlerFunc
- type ControllerHandlerFuncJson
- type CustomHandlerFunc
- type Plugin
- type PublicError
- type SimpleConfigSaver
- type TemplateData
- func GetBaseCPContextData(ctx context.Context) (*redis.Client, *discordgo.Guild, TemplateData)
- func GetCreateTemplateData(ctx context.Context) (context.Context, TemplateData)
- func HandleLandingPage(w http.ResponseWriter, r *http.Request) (TemplateData, error)
- func HandleReconnectShard(w http.ResponseWriter, r *http.Request) (TemplateData, error)
- func HandleStatus(w http.ResponseWriter, r *http.Request) (TemplateData, error)
- type ValidationTag
Constants ¶
const ( AlertDanger = "danger" AlertSuccess = "success" AlertInfo = "info" AlertWarning = "warning" )
const (
SessionCookieName = "yagpdb-session"
)
Variables ¶
var ( ErrChannelNotFound = errors.New("Channel not found") ErrRoleNotFound = errors.New("Role not found") )
var ( // Core template files Templates *template.Template Debug = true // Turns on debug mode ListenAddressHTTP = ":5000" ListenAddressHTTPS = ":5001" // Muxers RootMux *goji.Mux CPMux *goji.Mux ServerPublicMux *goji.Mux ServerPubliAPIMux *goji.Mux StartedAt = time.Now() CurrentAd *Advertisement )
var ErrNotLoggedIn = errors.New("Not logged in")
var ErrTokenExpired = errors.New("OAUTH2 Token expired")
Functions ¶
func APIHandler ¶
func APIHandler(inner CustomHandlerFunc) http.Handler
A helper wrapper that json encodes the returned value
func ActiveServerMW ¶
Sets the active guild context and template data It will only attempt to fetch full guild if not logged in
func AddGlobalTemplateData ¶
func AddGlobalTemplateData(key string, data interface{})
func AuthTokenFromB64 ¶
AuthTokenFromB64 Retrives an oauth2 token from the base64 string Returns an error if expired
func BaseTemplateDataMiddleware ¶
Fills the template data in the context with basic data such as clientid and redirects
func CheckCSRFToken ¶
CheckCSRFToken returns true if it matched and false if not, an error if something bad happened
func CheckErr ¶
func CheckErr(t TemplateData, err error, errMsg string, logger func(...interface{})) bool
Checks and error and logs it aswell as adding it to the alerts returns true if an error occured
func ControllerHandler ¶
func ControllerHandler(f ControllerHandlerFunc, templateName string) http.Handler
Handlers can return templatedata and an erro. If error is not nil and publicerror it will be added as an alert, if error is not a publicerror it will render a error page
func ControllerPostHandler ¶
func ControllerPostHandler(mainHandler ControllerHandlerFunc, extraHandler http.Handler, formData interface{}, logMsg string) http.Handler
Uses the FormParserMW to parse and validate the form, then saves it
func CreateCSRFToken ¶
CreateCSRFToken creates a csrf token and adds it the list
func CreateCookieSession ¶
func CreateCookieSession(token *oauth2.Token, redisClient *redis.Client) (cookie *http.Cookie, err error)
CreateCookieSession creates a session cookie where the value is the access token itself, this way we don't have to store it on our end anywhere.
func CtxLogger ¶
CtxLogger Returns an always non nil entry either from the context or standard logger
func FormParserMW ¶
Parses a form
func GenSessionCookie ¶
func HandleCPLogs ¶
func HandleCPLogs(w http.ResponseWriter, r *http.Request) interface{}
func HandleChanenlPermissions ¶
func HandleChanenlPermissions(w http.ResponseWriter, r *http.Request) interface{}
func HandleConfirmLogin ¶
func HandleConfirmLogin(w http.ResponseWriter, r *http.Request)
func HandleLogin ¶
func HandleLogin(w http.ResponseWriter, r *http.Request)
func HandleLogout ¶
func HandleLogout(w http.ResponseWriter, r *http.Request)
func HandleSelectServer ¶
func HandleSelectServer(w http.ResponseWriter, r *http.Request) interface{}
func IsAcceptingRequests ¶
func IsAcceptingRequests() bool
func IsAdminCtx ¶
Checks the context if there is a logged in user and if so if he's and admin or not
func LoadTemplates ¶
func LoadTemplates()
func LogIgnoreErr ¶
func LogIgnoreErr(err error)
func MiscMiddleware ¶
Misc mw that adds some headers, (Strict-Transport-Security) And discards requests when shutting down And a logger
func NewPublicError ¶
func NewPublicError(a ...interface{}) error
func RandBase64 ¶
func RedisMiddleware ¶
Will put a redis client in the context if available
func RenderHandler ¶
func RenderHandler(inner CustomHandlerFunc, tmpl string) http.Handler
A helper wrapper that renders a template
func RequestLogger ¶
Writes the request log into logger, returns a new middleware
func RequireSessionMiddleware ¶
Will not serve pages unless a session is available Also validates the origin header if present
func SessionMiddleware ¶
Will put a session cookie in the response if not available and discord session in the context if available
func SetContextTemplateData ¶
func SimpleConfigSaverHandler ¶
func SimpleConfigSaverHandler(t SimpleConfigSaver, extraHandler http.Handler) http.Handler
Uses the FormParserMW to parse and validate the form, then saves it
func UserInfoMiddleware ¶
Fills the context with user and guilds if possible
func ValidateChannelField ¶
func ValidateFloatField ¶
func ValidateForm ¶
func ValidateForm(guild *discordgo.Guild, tmpl TemplateData, form interface{}) bool
Probably needs some cleaning up
func ValidateIntField ¶
func ValidateIntMinMaxField ¶
func ValidateIntSliceField ¶ added in v0.29.1
func ValidateRegexField ¶
func ValidateRoleField ¶
func ValidateStringField ¶
func ValidateTemplateField ¶
func WriteErrorResponse ¶
Types ¶
type Advertisement ¶ added in v0.29.1
type Alert ¶
func ErrorAlert ¶
func ErrorAlert(args ...interface{}) *Alert
func SucessAlert ¶
func SucessAlert(args ...interface{}) *Alert
func WarningAlert ¶
func WarningAlert(args ...interface{}) *Alert
type ControllerHandlerFunc ¶
type ControllerHandlerFunc func(w http.ResponseWriter, r *http.Request) (TemplateData, error)
type ControllerHandlerFuncJson ¶
type ControllerHandlerFuncJson func(w http.ResponseWriter, r *http.Request) (interface{}, error)
type CustomHandlerFunc ¶
type CustomHandlerFunc func(w http.ResponseWriter, r *http.Request) interface{}
type Plugin ¶
type Plugin interface { common.Plugin // Parse the templates and set up the http routes here // mainMuxer is the root and cpmuxer handles the /cp/ route // the cpmuxer requires a session and to be a admin of the server // being managed, otherwise it will redirect to the homepage InitWeb() }
Plugin represents a web plugin
type PublicError ¶
type PublicError struct {
// contains filtered or unexported fields
}
func (*PublicError) Error ¶
func (p *PublicError) Error() string
type SimpleConfigSaver ¶
type TemplateData ¶
type TemplateData map[string]interface{}
func GetBaseCPContextData ¶
Returns base context data for control panel plugins
func GetCreateTemplateData ¶
func GetCreateTemplateData(ctx context.Context) (context.Context, TemplateData)
func HandleLandingPage ¶
func HandleLandingPage(w http.ResponseWriter, r *http.Request) (TemplateData, error)
func HandleReconnectShard ¶
func HandleReconnectShard(w http.ResponseWriter, r *http.Request) (TemplateData, error)
func HandleStatus ¶
func HandleStatus(w http.ResponseWriter, r *http.Request) (TemplateData, error)
func (TemplateData) AddAlerts ¶
func (t TemplateData) AddAlerts(alerts ...*Alert) TemplateData
type ValidationTag ¶
type ValidationTag struct {
// contains filtered or unexported fields
}
func ParseValidationTag ¶
func ParseValidationTag(tag string) *ValidationTag
func (*ValidationTag) Len ¶
func (p *ValidationTag) Len() int