Back to godoc.org

Package core

v0.0.0-...-55c8b89
Latest Go to latest

The latest major version is .

Published: May 11, 2020 | License: BSD-3-Clause | Module: github.com/clevergo/demo

Index

Variables

var MiddlewareSet = wire.NewSet(
	NewCSRFMiddleware,
	NewI18NMiddleware,
	NewCORSMiddleware,
	NewGzipMiddleware,
	NewSessionMiddleware,
	NewMinify, NewMinifyMiddleware,
	NewLoggingMiddleware,
)

func LoggerWriter

func LoggerWriter(logger log.Logger) io.Writer

func NewAuthenticator

func NewAuthenticator(identityStore auth.IdentityStore) auth.Authenticator

func NewCORS

func NewCORS(cfg CORSConfig) *cors.Cors

func NewCaptchaManager

func NewCaptchaManager(cfg CaptchaConfig, store captchas.Store) *captchas.Manager

func NewCaptchaStore

func NewCaptchaStore(cfg RedisConfig) captchas.Store

func NewDB

func NewDB(cfg DBConfig) (*sqlex.DB, func(), error)

NewDB returns a sqlx.DB with the given config.

func NewEnforcer

func NewEnforcer(cfg DBConfig) (*casbin.Enforcer, error)

func NewFileStore

func NewFileStore(cfg I18NConfig) i18n.Store

NewFileStore returns a file store with the given directory and decoder.

func NewI18N

func NewI18N(cfg I18NConfig, store i18n.Store) (*i18n.Translators, error)

func NewI18NLanguageParsers

func NewI18NLanguageParsers(cfg I18NConfig) (parsers []i18n.LanguageParser)

func NewIdentityStore

func NewIdentityStore(db *sqlex.DB, manager *JWTManager) auth.IdentityStore

NewIdentityStore returns an identity store instance.

func NewLogger

func NewLogger(cfg LogConfig) (log.Logger, func(), error)

func NewMailer

func NewMailer(cfg MailerConfig) *mail.Dialer

NewMailer returns a mailer.

func NewMinify

func NewMinify() *minify.M

func NewRenderer

func NewRenderer(cfg ViewConfig) *jetrenderer.Renderer

func NewSessionManager

func NewSessionManager(cfg SessionConfig, store scs.Store) *scs.SessionManager

func NewSessionStore

func NewSessionStore(cfg RedisConfig) scs.Store

func NewUserManager

func NewUserManager(identityStore auth.IdentityStore, sessionManager *scs.SessionManager) *users.Manager

type Application

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

func New

func New(opts ...Option) *Application

func (*Application) AccessManager

func (app *Application) AccessManager() *access.Manager

func (*Application) AddFlash

func (app *Application) AddFlash(ctx *clevergo.Context, flash Flash)

func (*Application) Cache

func (app *Application) Cache() store.StoreInterface

func (*Application) DB

func (app *Application) DB() *sqlex.DB

func (*Application) Flashes

func (app *Application) Flashes(ctx *clevergo.Context) (flashes Flashes)

func (*Application) Logger

func (app *Application) Logger() log.Logger

func (*Application) Mailer

func (app *Application) Mailer() *mail.Dialer

func (*Application) Params

func (app *Application) Params() Params

func (*Application) SessionManager

func (app *Application) SessionManager() *scs.SessionManager

func (*Application) User

func (app *Application) User(ctx *clevergo.Context) (*users.User, error)

func (*Application) UserManager

func (app *Application) UserManager() *users.Manager

type BeforeRenderEvent

type BeforeRenderEvent struct {
	App     *Application
	Context *clevergo.Context
	View    string
	Vars    jet.VarMap
	Data    ViewData
}

type CORSConfig

type CORSConfig struct {
	AllowedOrigins     []string `koanf:"allowed_origins"`
	AllowedMethods     []string `koanf:"allowed_methods"`
	AllowedHeaders     []string `koanf:"allowed_headers"`
	MaxAge             int      `koanf:"max_age"`
	AllowedCredentials bool     `koanf:"allow_credentials"`
	Debug              bool     `koanf:"debug"`
}

type CORSMiddleware

type CORSMiddleware clevergo.MiddlewareFunc

func NewCORSMiddleware

func NewCORSMiddleware(cfg CORSConfig) CORSMiddleware

type CSRFConfig

type CSRFConfig struct {
	AuthKey        string   `koanf:"auth_key"`
	MaxAge         int      `koanf:"max_age"`
	Domain         string   `koanf:"domain"`
	Path           string   `koanf:"path"`
	Secure         bool     `koanf:"secure"`
	HTTPOnly       bool     `koanf:"http_only"`
	SameSite       int      `koanf:"same_site"`
	RequestHeader  string   `koanf:"request_header"`
	FieldName      string   `koanf:"field_name"`
	CookieName     string   `koanf:"cookie_name"`
	TrustedOrigins []string `koanf:"trusted_origins"`
}

type CSRFMiddleware

type CSRFMiddleware clevergo.MiddlewareFunc

func NewCSRFMiddleware

func NewCSRFMiddleware(cfg CSRFConfig) CSRFMiddleware

type CaptchaConfig

type CaptchaConfig struct {
	Driver string `koanf:"driver"`
	String struct {
		Height int `koanf:"height"`
		Width  int `koanf:"width"`
		Length int `koanf:"length"`
	} `koanf:"string"`
	Math struct {
		Height     int `koanf:"height"`
		Width      int `koanf:"width"`
		NoiseCount int `koanf:"noise_count"`
	} `koanf:"math"`
	Chinese struct {
		Height int `koanf:"height"`
		Width  int `koanf:"width"`
		Length int `koanf:"length"`
	} `koanf:"chinese"`
	Digit struct {
		Height int `koanf:"height"`
		Width  int `koanf:"width"`
		Length int `koanf:"length"`
	} `koanf:"digit"`
	Audio struct {
		Length int `koanf:"length"`
	} `koanf:"audio"`
}

type Config

type Config struct {
	HTTP      ServerConfig    `koanf:"http"`
	API       ServerConfig    `koanf:"api"`
	Params    Params          `koanf:"params"`
	DB        DBConfig        `koanf:"db"`
	View      ViewConfig      `koanf:"view"`
	Session   SessionConfig   `koanf:"session"`
	I18N      I18NConfig      `koanf:"i18n"`
	Mailer    MailerConfig    `koanf:"mailer"`
	Captcha   CaptchaConfig   `koanf:"captcha"`
	Migration MigrationConfig `koanf:"migration"`
	CORS      CORSConfig      `koanf:"cors"`
	CSRF      CSRFConfig      `koanf:"csrf"`
	JWT       JWTConfig       `koanf:"jwt"`
	Redis     RedisConfig     `koanf:"redis"`
	Log       LogConfig       `koanf:"log"`
}

type Controller

type Controller struct {
	*Application
}

func NewController

func NewController(app *Application) *Controller

type DBConfig

type DBConfig struct {
	Driver string `koanf:"driver"`
	DSN    string `koanf:"dsn"`
}

DBConfig is a database config.

type ErrorHandler

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

func NewErrorHandler

func NewErrorHandler(app *Application) *ErrorHandler

func (*ErrorHandler) Error

func (eh *ErrorHandler) Error(ctx *clevergo.Context) error

func (*ErrorHandler) Handle

func (eh *ErrorHandler) Handle(ctx *clevergo.Context, err error)

type FileStore

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

FileStore is a file store.

func (*FileStore) Get

func (s *FileStore) Get() (i18n.Translations, error)

Get implements Store.Get.

type Flash

type Flash interface {
	Message() string
}

type Flashes

type Flashes []Flash

type GzipMiddleware

type GzipMiddleware clevergo.MiddlewareFunc

func NewGzipMiddleware

func NewGzipMiddleware() GzipMiddleware

type I18NConfig

type I18NConfig struct {
	Path        string `koanf:"path"`
	Fallback    string `koanf:"fallback"`
	Param       string `koanf:"param"`
	CookieParam string `koanf:"cookie_param"`
}

type I18NMiddleware

type I18NMiddleware clevergo.MiddlewareFunc

func NewI18NMiddleware

func NewI18NMiddleware(translators *i18n.Translators, parsers []i18n.LanguageParser) I18NMiddleware

type IdentityStore

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

IdentityStore is an identity store.

func (*IdentityStore) GetIdentity

func (s *IdentityStore) GetIdentity(id string) (auth.Identity, error)

GetIdentity implements IdentityStore.GetIdentity.

func (*IdentityStore) GetIdentityByToken

func (s *IdentityStore) GetIdentityByToken(token, tokenType string) (auth.Identity, error)

GetIdentityByToken implements IdentityStore.GetIdentityByToken.

type JWTConfig

type JWTConfig struct {
	SecretKey string `koanf:"secret_key"`
	Duration  int    `konaf:"duration"`
}

type JWTManager

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

func NewJWTManager

func NewJWTManager(cfg JWTConfig) *JWTManager

func (*JWTManager) New

func (m *JWTManager) New(userID string) (string, error)

func (*JWTManager) Parse

func (m *JWTManager) Parse(s string) (*jwt.StandardClaims, error)

type LogConfig

type LogConfig struct {
}

type LoggingMiddleware

type LoggingMiddleware clevergo.MiddlewareFunc

func NewLoggingMiddleware

func NewLoggingMiddleware() LoggingMiddleware

type MailerConfig

type MailerConfig struct {
	Host     string `koanf:"host"`
	Port     int    `koanf:"port"`
	Username string `koanf:"username"`
	Password string `koanf:"password"`
}

MailerConfig mailer config.

type Map

type Map map[string]interface{}

type MigrationConfig

type MigrationConfig struct {
	DB     string `koanf:"db"`
	Driver string `koanf:"driver"`
	DSN    string `koanf:"dsn"`
	Path   string `koanf:"path"`
}

type MinifyMiddleware

type MinifyMiddleware clevergo.MiddlewareFunc

func NewMinifyMiddleware

func NewMinifyMiddleware(m *minify.M) MinifyMiddleware

type Option

type Option func(*Application)

func SetAccessManager

func SetAccessManager(manager *access.Manager) Option

func SetCache

func SetCache(cache store.StoreInterface) Option

func SetDB

func SetDB(db *sqlex.DB) Option

func SetLogger

func SetLogger(logger log.Logger) Option

func SetMailer

func SetMailer(mailer *mail.Dialer) Option

func SetParams

func SetParams(ps Params) Option

func SetSessionManager

func SetSessionManager(manager *scs.SessionManager) Option

func SetUserManager

func SetUserManager(m *users.Manager) Option

type Params

type Params map[string]interface{}

func (Params) Get

func (ps Params) Get(name string) (val interface{}, ok bool)

type RedisConfig

type RedisConfig struct {
	Host     string `koanf:"host"`
	Port     int    `koanf:"port"`
	Password string `koanf:"password"`
	Database int    `koanf:"database"`
}

type Server

type Server struct {
	*http.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(router *clevergo.Router, logger log.Logger) *Server

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error

func (*Server) ListenAndServeUnix

func (srv *Server) ListenAndServeUnix() error

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

func (*Server) Use

func (srv *Server) Use(middlewares ...func(http.Handler) http.Handler)

type ServerConfig

type ServerConfig struct {
	Addr string `koanf:"addr"`
	Root string `koanf:"root"`
}

type SessionConfig

type SessionConfig struct {
	Lifetime       int    `koanf:"lifetime"`
	IdleTimeout    int    `koanf:"idle_timeout"`
	CookieName     string `koanf:"cookie_name"`
	CookieDomain   string `koanf:"cookie_domain"`
	CookiePath     string `koanf:"cookie_path"`
	CookieHTTPOnly bool   `koanf:"cookie_http_only"`
	CookiePersist  bool   `koanf:"cookie_persist"`
	CookieSecure   bool   `koanf:"cookie_secure"`
	CookieSameSite int    `koanf:"cookie_same_site"`
}

type SessionMiddleware

type SessionMiddleware clevergo.MiddlewareFunc

func NewSessionMiddleware

func NewSessionMiddleware(manager *scs.SessionManager) SessionMiddleware

type Validatable

type Validatable interface {
	Validate() error
}

type ViewConfig

type ViewConfig struct {
	Path   string   `koanf:"path"`
	Suffix string   `koanf:"suffix"`
	Delims []string `koanf:"delims"`
	Debug  bool     `koanf:"debug"`
}

ViewConfig contains views manager's settings.

type ViewData

type ViewData map[string]interface{}

ViewData is an alias of map.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier