Help us shape the future of Go! Take the 2026 Go Developer Survey

forge

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 21 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")
)

Functions

This section is empty.

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
	Connect []string
	Frame   []string
}

func (CSP) String

func (csp CSP) String() string

type Environment

type Environment map[string]string

func NewEnvironment

func NewEnvironment() Environment

func (Environment) Decode

func (env Environment) Decode(target interface{}) error

func (Environment) ImportEnvFileContents

func (environment Environment) ImportEnvFileContents(fileContents string) error

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(
	client *http.Client,
	modRequest func(request *http.Request) error,
	errorCheck func(response *http.Response) error,
) *HTTPClient

func (*HTTPClient) Do

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

func (*HTTPClient) Request

func (httpClient *HTTPClient) Request(
	ctx context.Context,
	method string,
	url string,
	payload interface{},
	target interface{},
) 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 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
	NotFoundHandler http.Handler
	CacheControl    string
	Index           string
}

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() (deadline time.Time, ok 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
	Stdout      io.Writer
	Stderr      io.Writer
	Stdin       io.Reader
	FS          fs.FS
}

func NewRuntime

func NewRuntime() *Runtime

func (*Runtime) Execute

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

func (*Runtime) KeepRunning

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

func (*Runtime) ReadInDefaultEnvironmentFiles

func (runtime *Runtime) ReadInDefaultEnvironmentFiles() error

func (*Runtime) ReadInEnvironmentFile

func (runtime *Runtime) ReadInEnvironmentFile(fileName string) error

func (*Runtime) Serve

func (runtime *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

Jump to

Keyboard shortcuts

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