forge

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 23 Imported by: 0

README

forge

A toolkit for Go applications.

Documentation

Index

Constants

This section is empty.

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 Assert

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

func HTTPLoggerGetRequestID

func HTTPLoggerGetRequestID(r *http.Request) string

HTTPLoggerGetRequestID gets the request ID off of the request if there is one

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(
	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 Log

type Log struct {
	Timestamp time.Time              `json:"timestamp"`
	Severity  string                 `json:"severity"`
	Message   string                 `json:"message"`
	Context   map[string]interface{} `json:"context"`
}

type Logger

type Logger interface {
	Emergency(message string, context map[string]interface{})
	Alert(message string, context map[string]interface{})
	Critical(message string, context map[string]interface{})
	Error(message string, context map[string]interface{})
	Warning(message string, context map[string]interface{})
	Notice(message string, context map[string]interface{})
	Info(message string, context map[string]interface{})
	Debug(message string, context map[string]interface{})
	StandardLogger() *log.Logger
}

type LoggerJSON

type LoggerJSON struct {
	Encoder *json.Encoder
}

func (*LoggerJSON) Alert

func (logger *LoggerJSON) Alert(message string, context map[string]interface{})

func (*LoggerJSON) Critical

func (logger *LoggerJSON) Critical(message string, context map[string]interface{})

func (*LoggerJSON) Debug

func (logger *LoggerJSON) Debug(message string, context map[string]interface{})

func (*LoggerJSON) Emergency

func (logger *LoggerJSON) Emergency(message string, context map[string]interface{})

func (*LoggerJSON) Error

func (logger *LoggerJSON) Error(message string, context map[string]interface{})

func (*LoggerJSON) Info

func (logger *LoggerJSON) Info(message string, context map[string]interface{})

func (*LoggerJSON) Notice

func (logger *LoggerJSON) Notice(message string, context map[string]interface{})

func (*LoggerJSON) StandardLogger

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

func (*LoggerJSON) Warning

func (logger *LoggerJSON) Warning(message string, context map[string]interface{})

func (*LoggerJSON) Write

func (logger *LoggerJSON) 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 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