forge

package module
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: MIT Imports: 23 Imported by: 0

README

forge

A toolkit for Go applications.

Documentation

Index

Constants

View Source
const (
	LevelCritical = "CRITICAL"
	LevelError    = "ERROR"
	LevelWarning  = "WARNING"
	LevelInfo     = "INFO"
	LevelDebug    = "DEBUG"
)

Variables

View Source
var (
	// ErrInvalidValue returned when the value passed to Unmarshal is nil or not a pointer to a struct.
	ErrInvalidValue = errors.New("value must be a non-nil pointer to a struct")

	// ErrUnsupportedFieldType returned when a field with tag "env" is unsupported.
	ErrUnsupportedFieldType = errors.New("field is an unsupported type")

	// ErrUnexportedField returned when a field with tag "env" is not exported.
	ErrUnexportedField = errors.New("field must be exported")
)

Functions

func AddContextID added in v0.0.14

func AddContextID(ctx context.Context) context.Context

func Assert

func Assert(expected interface{}, actual interface{}) error

func DecodeRequestBody added in v0.0.10

func DecodeRequestBody(r *http.Request, target interface{}) error

func GetContextID added in v0.0.14

func GetContextID(ctx context.Context) string

func KeepRunning added in v0.0.13

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

func MockRoundTripperQueue added in v0.0.3

func MockRoundTripperQueue(t *testing.T, queue []MockRoundTripFunc) http.RoundTripper

func RespondHTML

func RespondHTML(w http.ResponseWriter, status int, s string)

func RespondJSON

func RespondJSON(w http.ResponseWriter, status int, v interface{})

func Run

func Run(ctx context.Context, app WebApp) error

func SetValueInEnvFile added in v0.0.4

func SetValueInEnvFile(filePath, key string, value string)

func UnreachableError

func UnreachableError(err error)

Types

type App

type App interface {
	// The Logger to be used
	Logger() *Logger
}

type AssertFailure

type AssertFailure struct {
	Expected interface{}
	Actual   interface{}
}

type CSP added in v0.0.9

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

func (CSP) String added in v0.0.9

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 added in v0.0.4

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

func NewHTTPClient added in v0.0.4

func NewHTTPClient(
	interceptor HTTPClientInterceptor,
	client *http.Client,
) *HTTPClient

func (*HTTPClient) Do added in v0.0.4

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

func (*HTTPClient) Request added in v0.0.4

func (httpClient *HTTPClient) Request(
	ctx context.Context,
	method string,
	url string,
	payload interface{},
	target interface{},
) error

type HTTPClientInterceptor added in v0.0.4

type HTTPClientInterceptor interface {
	ModRequest(request *http.Request) error
	ErrorCheck(response *http.Response) 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
}

func (*HTTPStatic) ServeHTTP

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

type LogEntry added in v0.0.14

type LogEntry 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 LogSupplementer added in v0.0.14

type LogSupplementer func(
	logEntry *LogEntry,
	ctx context.Context,
	r *http.Request,
)

type Logger

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

func NewLogger added in v0.0.14

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

func (*Logger) Copy added in v0.0.14

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 added in v0.0.14

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 added in v0.0.14

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

type MockRoundTripFunc added in v0.0.3

type MockRoundTripFunc func(t *testing.T, request *http.Request) (*http.Response, error)

type MockableRoundTripper

type MockableRoundTripper struct {
	RoundTripFunc func(*http.Request) (*http.Response, error)
}

func (MockableRoundTripper) RoundTrip

func (mockable MockableRoundTripper) RoundTrip(request *http.Request) (*http.Response, error)

type PreparedStatement added in v0.0.9

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

func NewPreparedStatement added in v0.0.9

func NewPreparedStatement(queryText string) *PreparedStatement

func (*PreparedStatement) GetParsedParameters added in v0.0.9

func (preparedStatement *PreparedStatement) GetParsedParameters() []interface{}

func (*PreparedStatement) GetParsedQuery added in v0.0.9

func (preparedStatement *PreparedStatement) GetParsedQuery() string

func (*PreparedStatement) SetValue added in v0.0.9

func (preparedStatement *PreparedStatement) SetValue(parameterName string, parameterValue interface{})

type Resources

type Resources struct {
	FileSystems []fs.FS
}

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) ReadInDefaultEnvironmentFiles

func (runtime Runtime) ReadInDefaultEnvironmentFiles() error

func (Runtime) ReadInEnvironmentFile

func (runtime Runtime) ReadInEnvironmentFile(fileName string) error

type Validator added in v0.0.10

type Validator interface {
	Validate() error
}

type ValidatorError added in v0.0.10

type ValidatorError struct {
	Message string
}

func (ValidatorError) Error added in v0.0.10

func (err ValidatorError) Error() string

type WebApp

type WebApp interface {
	App
	// 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)
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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