forge

package
v0.0.44 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 24 Imported by: 4

Documentation

Index

Constants

View Source
const (
	HeaderContentType           = "Content-Type"
	HeaderCacheControl          = "Cache-Control"
	HeaderContentSecurityPolicy = "Content-Security-Policy"
)
View Source
const (
	LevelCritical = "CRITICAL"
	LevelError    = "ERROR"
	LevelWarning  = "WARNING"
	LevelInfo     = "INFO"
	LevelDebug    = "DEBUG"
)

Variables

View Source
var (
	ErrInvalidValue         = errors.New("value must be a non-nil pointer to a struct")
	ErrUnsupportedFieldType = errors.New("field is an unsupported type")
	ErrUnexportedField      = errors.New("field must be exported")
	ErrNotAuthenticated     = errors.New("not authenticated")
)
View Source
var ErrBodyCanNotBeBlank = errors.New("request body can not be blank")
View Source
var ErrHTTPClientShouldRetry = errors.New("")

Functions

func HTTPStaticDefaultHook added in v0.0.27

func HTTPStaticDefaultHook(w http.ResponseWriter, _ *http.Request, fileInfo fs.FileInfo)

func PanicReportTimeoutHandler added in v0.0.39

func PanicReportTimeoutHandler(h http.Handler, dt time.Duration, logger *Logger) http.Handler

Replace http.TimeoutHandler with PanicReportTimeoutHandler.

func ReadAllButRetain added in v0.0.32

func ReadAllButRetain(reader io.ReadCloser) []byte

Types

type App

type App interface {
	// The Logger to be used
	Logger() *Logger
	// How it responds to web requests
	Handler() http.Handler
	// What address the webserver should listen on
	ListenAddress() string
	// Tasks to run in the background (a Go routine)
	Background(ctx context.Context)
}

type Authenticator

type Authenticator interface {
	LoginHandler() http.Handler
	InitializeSession(next http.Handler) http.Handler
	RequireLogin(next http.Handler) http.Handler
	GetUser(r *http.Request) (User, error)
}

type CSP

type CSP struct {
	Default []string
	Script  []string
	Image   []string
	Connect []string
	Frame   []string
}

func (CSP) String

func (csp CSP) String() string

type HTTPBasicAuth added in v0.0.32

type HTTPBasicAuth struct {
	Username string
	Password string
}

func (HTTPBasicAuth) CheckResponse added in v0.0.32

func (httpBasicAuth HTTPBasicAuth) CheckResponse(r *http.Response) error

func (HTTPBasicAuth) ModifyRequest added in v0.0.32

func (httpBasicAuth HTTPBasicAuth) ModifyRequest(r *http.Request) error

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(
	httpClient *http.Client,
	middleware []HTTPClientMiddleware,
) *HTTPClient

func (*HTTPClient) Do

func (c *HTTPClient) Do(request *http.Request) (*http.Response, error)

func (*HTTPClient) JSONRequest added in v0.0.32

func (c *HTTPClient) JSONRequest(
	ctx context.Context,
	method string,
	url string,
	payload any,
	target any,
) error

type HTTPClientMiddleware added in v0.0.32

type HTTPClientMiddleware interface {
	ModifyRequest(r *http.Request) error
	CheckResponse(r *http.Response) error
}

type HTTPClientResponseMiddleware added in v0.0.32

type HTTPClientResponseMiddleware interface {
	ModifyResponse(r *http.Response) error
}

type HTTPHeaders added in v0.0.32

type HTTPHeaders map[string]string

func (HTTPHeaders) CheckResponse added in v0.0.32

func (httpHeaders HTTPHeaders) CheckResponse(r *http.Response) error

func (HTTPHeaders) ModifyRequest added in v0.0.32

func (httpHeaders HTTPHeaders) ModifyRequest(r *http.Request) error

type HTTPLogger

type HTTPLogger struct {
	Logger  *Logger
	Handler http.Handler
}

func (*HTTPLogger) ServeHTTP

func (httpLogger *HTTPLogger) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HTTPOAuth2 added in v0.0.32

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

func NewHTTPOAuth2 added in v0.0.32

func NewHTTPOAuth2(
	client *http.Client,
	grant HTTPOAuth2Grant,
	tokenURL string,
) *HTTPOAuth2

func (*HTTPOAuth2) CheckResponse added in v0.0.32

func (oauth2 *HTTPOAuth2) CheckResponse(r *http.Response) error

func (*HTTPOAuth2) ModifyRequest added in v0.0.32

func (oauth2 *HTTPOAuth2) ModifyRequest(r *http.Request) error

type HTTPOAuth2Grant added in v0.0.32

type HTTPOAuth2Grant interface {
	GenerateQuery() (url.Values, error)
}

type HTTPOAuth2GrantPassword added in v0.0.32

type HTTPOAuth2GrantPassword struct {
	ClientID     string
	ClientSecret string
	Username     string
	Password     string
	Scope        string
}

func (HTTPOAuth2GrantPassword) GenerateQuery added in v0.0.32

func (grant HTTPOAuth2GrantPassword) GenerateQuery() (url.Values, error)

type HTTPOAuth2Token added in v0.0.32

type HTTPOAuth2Token struct {
	AccessToken string `json:"access_token"`
}

type HTTPRouter

type HTTPRouter struct {
	Routes          map[string]http.Handler
	NotFoundHandler http.Handler
}

func (*HTTPRouter) ServeHTTP

func (httpRouter *HTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HTTPStatic

type HTTPStatic struct {
	FileSystem      http.FileSystem
	IndexFile       string
	NotFoundFile    string
	NotFoundCode    int
	NotFoundHandler func(w http.ResponseWriter, r *http.Request, httpStatic *HTTPStatic)
	Hook            func(w http.ResponseWriter, r *http.Request, fileInfo fs.FileInfo)
}

func (*HTTPStatic) ServeFile added in v0.0.28

func (httpStatic *HTTPStatic) ServeFile(w http.ResponseWriter, r *http.Request, file http.File, fileInfo fs.FileInfo, statusCode int)

func (*HTTPStatic) ServeHTTP

func (httpStatic *HTTPStatic) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandlerContext

type HandlerContext struct {
	Writer  http.ResponseWriter
	Request *http.Request
}

func NewHandlerContext

func NewHandlerContext(w http.ResponseWriter, r *http.Request) *HandlerContext

func (*HandlerContext) Deadline added in v0.0.25

func (handlerContext *HandlerContext) Deadline() (time.Time, bool)

func (*HandlerContext) DecodeRequest

func (handlerContext *HandlerContext) DecodeRequest(target any) error

func (*HandlerContext) Done added in v0.0.25

func (handlerContext *HandlerContext) Done() <-chan struct{}

func (*HandlerContext) Err added in v0.0.25

func (handlerContext *HandlerContext) Err() error

func (*HandlerContext) ExecuteTemplate added in v0.0.17

func (handlerContext *HandlerContext) ExecuteTemplate(tmpl *template.Template, data any)

func (*HandlerContext) ReadBody

func (handlerContext *HandlerContext) ReadBody() []byte

func (*HandlerContext) RespondHTML

func (handlerContext *HandlerContext) RespondHTML(status int, s string)

func (*HandlerContext) RespondJSON

func (handlerContext *HandlerContext) RespondJSON(status int, v any)

func (*HandlerContext) Value added in v0.0.25

func (handlerContext *HandlerContext) Value(key any) any

type Log

type Log struct {
	Timestamp time.Time      `json:"@timestamp"`
	Channel   string         `json:"channel"`
	Level     string         `json:"level"`
	Message   string         `json:"message"`
	Extras    map[string]any `json:"extras"`
	ContextID string         `json:"context_id"`
}

type LogSupplementerFunc

type LogSupplementerFunc func(
	logEntry *Log,
	ctx context.Context,
	r *http.Request,
)

type Logger

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

func NewLogger

func NewLogger(
	channel string,
	writer io.Writer,
	supplementer LogSupplementerFunc,
) *Logger

func (*Logger) Copy

func (logger *Logger) Copy(newChannel string) *Logger

func (*Logger) Critical

func (logger *Logger) Critical(
	cxt context.Context,
	message string,
	extras map[string]any,
)

func (*Logger) Debug

func (logger *Logger) Debug(
	cxt context.Context,
	message string,
	extras map[string]any,
)

func (*Logger) Error

func (logger *Logger) Error(
	cxt context.Context,
	message string,
	extras map[string]any,
)

func (*Logger) Info

func (logger *Logger) Info(
	cxt context.Context,
	message string,
	extras map[string]any,
)

func (*Logger) Log

func (logger *Logger) Log(
	ctx context.Context,
	level string,
	message string,
	extras map[string]any,
)

func (*Logger) StandardLogger

func (logger *Logger) StandardLogger() *log.Logger

func (*Logger) Warning

func (logger *Logger) Warning(
	cxt context.Context,
	message string,
	extras map[string]any,
)

func (*Logger) Write

func (logger *Logger) Write(b []byte) (int, error)

type LoggerErrorExtrasAdder added in v0.0.19

type LoggerErrorExtrasAdder interface {
	error
	AddExtras(map[string]any)
}

type Resources

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

func NewResources

func NewResources(fileSystems []fs.FS) *Resources

func (*Resources) MustOpenDirectory

func (resources *Resources) MustOpenDirectory(dir string) fs.FS

func (*Resources) MustOpenFile

func (resources *Resources) MustOpenFile(fileName string) fs.File

func (*Resources) MustOpenFileContents

func (resources *Resources) MustOpenFileContents(fileName string) string

func (*Resources) MustParseHTMLTemplate

func (resources *Resources) MustParseHTMLTemplate(fileName string) *template.Template

type Runtime

type Runtime struct {
	Environment *environment.Environment
	Stdout      io.Writer
	Stderr      io.Writer
	Stdin       io.Reader
	FS          fs.FS
}

func NewRuntime

func NewRuntime() *Runtime

func (*Runtime) Execute

func (r *Runtime) Execute(name string, args ...string) error

func (*Runtime) KeepRunning

func (r *Runtime) KeepRunning(ctx context.Context, app App, action func(ctx context.Context), coolDown time.Duration)

func (*Runtime) Serve

func (r *Runtime) Serve(ctx context.Context, app App) error

type User

type User interface {
	Username() string
	Roles() []string
}

type Validator

type Validator interface {
	Validate() error
}

type ValidatorError

type ValidatorError struct {
	Message string
}

func (ValidatorError) Error

func (err ValidatorError) Error() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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