web

package module
v0.0.0-...-1176ba2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

README

web

Documentation

Index

Constants

View Source
const (
	StageDevelopment = "dev"
	StageTesting     = "test"
	StageProduction  = "prod"
)

Variables

This section is empty.

Functions

func Debug

func Debug(r *http.Request, v ...interface{})

func Debugf

func Debugf(r *http.Request, format string, v ...interface{})

func Error

func Error(r *http.Request, v ...interface{})

func Errorf

func Errorf(r *http.Request, format string, v ...interface{})

func Fatal

func Fatal(r *http.Request, v ...interface{})

func Fatalf

func Fatalf(r *http.Request, format string, v ...interface{})

func InDevelopmentStage

func InDevelopmentStage(r *http.Request) bool

func InProductionStage

func InProductionStage(r *http.Request) bool

func InTestingStage

func InTestingStage(r *http.Request) bool

func Info

func Info(r *http.Request, v ...interface{})

func Infof

func Infof(r *http.Request, format string, v ...interface{})

func ListenOSInterrupt

func ListenOSInterrupt(cancel context.CancelFunc)

func Parameters

func Parameters(r *http.Request) map[string]string

func Pg

func Pg(r *http.Request) orm.DB

func RenderGuestLayout

func RenderGuestLayout(w http.ResponseWriter, r *http.Request, templateName string, data interface{})

func RenderLayout

func RenderLayout(w http.ResponseWriter, r *http.Request, layoutName, templateName string, data interface{})

func RenderUserLayout

func RenderUserLayout(w http.ResponseWriter, r *http.Request, templateName string, data interface{})

func ResponseUnauthorized

func ResponseUnauthorized(w http.ResponseWriter, r *http.Request)

func ResponseWithError

func ResponseWithError(w http.ResponseWriter, r *http.Request, err error)

func Stage

func Stage(r *http.Request) string

func Warning

func Warning(r *http.Request, v ...interface{})

func Warningf

func Warningf(r *http.Request, format string, v ...interface{})

Types

type App

type App struct {
	Logger Logger
	Stage  string

	Template    TemplateConfig
	UseTemplate bool

	Authenticator    Authenticator
	UnauthorizedPath string

	ErrorPath string

	Address string
	// contains filtered or unexported fields
}

func NewApp

func NewApp() *App

func (*App) Handle

func (a *App) Handle(path, method string, handler http.Handler)

func (*App) InDevelopmentStage

func (a *App) InDevelopmentStage() bool

func (*App) InProductionStage

func (a *App) InProductionStage() bool

func (*App) InTestingStage

func (a *App) InTestingStage() bool

func (*App) Middleware

func (a *App) Middleware(m MiddlewareFunc)

func (*App) Serve

func (a *App) Serve() error

type Authenticator

type Authenticator interface {
	Authentic(r *http.Request) (bool, error)
}

type Logger

type Logger interface {
	Debugf(format string, v ...interface{})
	Debug(v ...interface{})
	Infof(format string, v ...interface{})
	Info(v ...interface{})
	Warningf(format string, v ...interface{})
	Warning(v ...interface{})
	Errorf(format string, v ...interface{})
	Error(v ...interface{})
	Fatalf(format string, v ...interface{})
	Fatal(v ...interface{})
}

type MiddlewareFunc

type MiddlewareFunc func(next http.Handler) http.Handler

func PostgreDBMiddleware

func PostgreDBMiddleware(db orm.DB) MiddlewareFunc

type Pagination

type Pagination struct {
	Page      int `json:"page"`
	PageSize  int `json:"page_size"`
	TotalData int `json:"total_data"`
	TotalPage int `json:"total_page"`
}

func CalculatePagination

func CalculatePagination(page, pageSize, totalData int) *Pagination

func (*Pagination) HasMultiplePages

func (p *Pagination) HasMultiplePages() bool

func (*Pagination) NextPage

func (p *Pagination) NextPage() int

func (*Pagination) Offset

func (p *Pagination) Offset() int

func (*Pagination) PageIsFirst

func (p *Pagination) PageIsFirst() bool

func (*Pagination) PageIsLast

func (p *Pagination) PageIsLast() bool

func (*Pagination) PrevPage

func (p *Pagination) PrevPage() int

type SessionValidator

type SessionValidator interface {
	IsValid(r *http.Request, id string) (bool, error)
}

type SimpleAuthenticator

type SimpleAuthenticator struct {
	GuestPaths       []string
	CookiePrefix     string
	SessionValidator SessionValidator
}

func (*SimpleAuthenticator) Authentic

func (sa *SimpleAuthenticator) Authentic(r *http.Request) (bool, error)

type TemplateConfig

type TemplateConfig struct {
	GuestLayoutName string
	UserLayoutName  string
	PathResolver    TemplatePathResolver
	Functions       template.FuncMap
}

type TemplatePathResolver

type TemplatePathResolver func(templateName string) []string

Jump to

Keyboard shortcuts

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