goat

package module
v0.2.3-alpha-20 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 39 Imported by: 0

README

GOAT

Goat is a toolkit for creating JSON-speaking RESTful APIs in Go.

Goat aims to streamline development by offering a tightly focused feature set, convention-over-configuration philosophies, and out-of-the-box devops tooling.

Goat is not made for building traditional webapps with a front-end. Instead, it focuses on helping developers create headless webservices that can be used as the backend for server-side rendered static sites or mobile-apps.

Roadmap

Planned features include:

  • A global CLI tool for for scaffolding projects (including out-of-the-box Docker support and Makefiles)
  • Full migration suite
  • Generator scripts for Cobra commands, repositories, models, handlers, migrations, etc.
  • Out-of-the-box AWS Cloudformation support via generated templates and bootstrapping scripts, including Parameter Store management of secrets and ECS clusters.
  • Oauth support
  • Out-of-the-box Cobra utility commands
  • Support for more additional database engines (currently only supports MySQL-compatible databases)
  • Front end integrations via Horns, a comprehensive, fully-themable, open-source UI framework made for Gatsby and React Emotion with React Native support

Documentation

Index

Constants

View Source
const (
	HeaderAuthorization string = "Authorization"
	HeaderContentType   string = "Content-Type"
	ContentTypeJson     string = "application/json"
	ContentTypeForm     string = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func ApplyQueryToGorm added in v0.2.1

func ApplyQueryToGorm(db *gorm.DB, q query.Builder, paginate bool) (error, query.Template)

func AssertRecordDeleted added in v0.2.1

func AssertRecordDeleted[M any](t *testing.T, db *gorm.DB, input M, msg string)

func AssertValidID

func AssertValidID(t *testing.T, id ID)

func AssertValidInitialCreatedAt

func AssertValidInitialCreatedAt(t *testing.T, d time.Time)

func AssertValidInitialDeletedAt

func AssertValidInitialDeletedAt(t *testing.T, d *time.Time)

func AssertValidInitialUpdatedAt

func AssertValidInitialUpdatedAt(t *testing.T, d *time.Time)

func AssertValidModifiedUpdatedAt

func AssertValidModifiedUpdatedAt(t *testing.T, d *time.Time)

func BindRequest added in v0.2.1

func BindRequest[T any](cx *gin.Context) (T, error)

BindRequest returns a T with values set by binding the request JSON from the provided Gin context.

func DeRef

func DeRef[T any](value *T) T

func EnvBool

func EnvBool(key string, defaultValue bool) bool

EnvBool returns the value of the specified env var or defaultValue if the env var is not set.

func EnvBoolOrNil

func EnvBoolOrNil(key string, defaultValue *bool) *bool

func EnvDuration added in v0.2.1

func EnvDuration(key string, defaultValue time.Duration) time.Duration

EnvDuration returns the value of the specified env var or defaultValue if the env var is not set.

func EnvDurationOrNil

func EnvDurationOrNil(key string, defaultValue *time.Duration) *time.Duration

func EnvFloat64 added in v0.2.1

func EnvFloat64(key string, defaultValue float64) float64

EnvFloat64 returns the value of the specified env var or defaultValue if the env var is not set.

func EnvFloat64OrNil

func EnvFloat64OrNil(key string, defaultValue *float64) *float64

func EnvInt added in v0.1.1

func EnvInt(key string, defaultValue int) int

EnvInt returns the value of the specified env var or defaultValue if the env var is not set.

func EnvInt32 added in v0.2.1

func EnvInt32(key string, defaultValue int32) int32

EnvInt32 returns the value of the specified env var or defaultValue if the env var is not set.

func EnvInt32OrNil

func EnvInt32OrNil(key string, defaultValue *int32) *int32

func EnvInt64 added in v0.2.1

func EnvInt64(key string, defaultValue int64) int64

EnvInt64 returns the value of the specified env var or defaultValue if the env var is not set.

func EnvInt64OrNil

func EnvInt64OrNil(key string, defaultValue *int64) *int64

func EnvIntOrNil

func EnvIntOrNil(key string, defaultValue *int) *int

func EnvIntSlice added in v0.2.1

func EnvIntSlice(key string, defaultValue []int) []int

EnvIntSlice returns the value of the specified env var or defaultValue if the env var is not set.

func EnvString

func EnvString(key string, defaultValue string) string

EnvString returns the value of the specified env var or defaultValue if the env var is not set.

func EnvStringMap added in v0.2.1

func EnvStringMap(key string, defaultValue map[string]any) map[string]any

EnvStringMap returns the value of the specified env var or defaultValue if the env var is not set.

func EnvStringMapString added in v0.2.1

func EnvStringMapString(key string, defaultValue map[string]string) map[string]string

EnvStringMapString returns the value of the specified env var or defaultValue if the env var is not set.

func EnvStringOrNil

func EnvStringOrNil(key string, defaultValue *string) *string

func EnvStringSlice added in v0.2.1

func EnvStringSlice(key string, defaultValue []string) []string

EnvStringSlice returns the value of the specified env var or defaultValue if the env var is not set.

func EnvTime added in v0.2.1

func EnvTime(key string, defaultValue time.Time) time.Time

EnvTime returns the value of the specified env var or defaultValue if the env var is not set.

func EnvTimeOrNil

func EnvTimeOrNil(key string, defaultValue *time.Time) *time.Time

func EnvUint16 added in v0.2.1

func EnvUint16(key string, defaultValue uint16) uint16

EnvUint16 returns the value of the specified env var or defaultValue if the env var is not set.

func EnvUint16OrNil

func EnvUint16OrNil(key string, defaultValue *uint16) *uint16

func EnvUint32 added in v0.2.1

func EnvUint32(key string, defaultValue uint32) uint32

EnvUint32 returns the value of the specified env var or defaultValue if the env var is not set.

func EnvUint32OrNil

func EnvUint32OrNil(key string, defaultValue *uint32) *uint32

func EnvUint64 added in v0.2.1

func EnvUint64(key string, defaultValue uint64) uint64

EnvUint64 returns the value of the specified env var or defaultValue if the env var is not set.

func EnvUint64OrNil

func EnvUint64OrNil(key string, defaultValue *uint64) *uint64

func ErrorBesidesRecordNotFound added in v0.2.1

func ErrorBesidesRecordNotFound(err error) bool

ErrorBesidesRecordNotFound true if the provided error is NOT a Gorm "record not found" error.

func ErrorsToError

func ErrorsToError(errs []error) error

func ExitError added in v0.1.1

func ExitError(err error)

func ExitSuccess

func ExitSuccess()

func FileExists

func FileExists(filePath string) (bool, error)

func GetDB added in v0.1.1

func GetDB(c DatabaseConfig) (*gorm.DB, error)

func GetLogger added in v0.1.1

func GetLogger() *zap.SugaredLogger

func GetMainDB added in v0.1.1

func GetMainDB() (*gorm.DB, error)

func GetMigrationDB added in v0.1.23

func GetMigrationDB(db *gorm.DB) (*sql.DB, error)

func GetStrictLogger added in v0.2.1

func GetStrictLogger() *zap.Logger

func GetUrl added in v0.2.1

func GetUrl(key ...string) *url.URL

func HandleCSVRows

func HandleCSVRows(path string, skipHeaderRow bool, breakOnEOF bool, callback CSVRowCallback) error

func HealthHandler added in v0.2.1

func HealthHandler(path string, message ...string) (string, gin.HandlerFunc)

func Init

func Init() error

Init initializes the Goat runtime services. Goat has three primary concerns, each encapsulated by their own service: - logging - database connections - route-based response hypermedia (linking) This function only needs to be called if you intend to use the database, http, or log services.

func MustInit added in v0.2.1

func MustInit()

func MustRFC3339ToTime

func MustRFC3339ToTime(input string) time.Time

func MustYMDHISStringToTime

func MustYMDHISStringToTime(input string) time.Time

func MustYMDStringToTime

func MustYMDStringToTime(input string) time.Time
func NewResourceLinks(key, path string) *hal.ResourceLinks

func NewValidationError added in v0.2.1

func NewValidationError(field, rule string) error

func ParseParam added in v0.2.1

func ParseParam[T any](cx *gin.Context, key string, parser ParamParser[T]) (T, error)

func Print

func Print(s string, a ...any)

func PrintDanger

func PrintDanger(s string, a ...any)

func PrintHeading

func PrintHeading(s string, a ...any)

func PrintIndent

func PrintIndent(s string, a ...any)

func PrintInfo

func PrintInfo(s string, a ...any)

func PrintSuccess

func PrintSuccess(s string, a ...any)

func PrintWarning

func PrintWarning(s string, a ...any)

func RFCToTime

func RFCToTime(input string) (time.Time, error)

func RandomBool

func RandomBool() bool

func RandomDecimal

func RandomDecimal(min, max int64) decimal.Decimal

func RandomDecimalExp

func RandomDecimalExp(min, max int64, exp int32) decimal.Decimal

func RandomIndex

func RandomIndex(length int) int

func RandomInt

func RandomInt(min, max int) int

func RandomInt32

func RandomInt32(min, max int32) int32

func RandomInt64

func RandomInt64(min, max int64) int64

func RandomPercentage

func RandomPercentage() float64

func ReadDBConfig

func ReadDBConfig() (database.Config, error)

func ReadFileCSV

func ReadFileCSV(path string) (reader *csv.Reader, err error)

func ReadFileJSON

func ReadFileJSON[T any](filePath string, target *T) (*os.File, error)

func RecordNotFound

func RecordNotFound(err error) bool

RecordNotFound returns true if the provided error is the Gorm "record not found" error.

func Ref

func Ref[T any](value T) *T

func RequireDecimalEqual

func RequireDecimalEqual(t *testing.T, exp, act any, msgAndArgs ...any)

func ResetDB

func ResetDB(db *gorm.DB) error

func RespondAccepted added in v0.2.1

func RespondAccepted(cx *gin.Context, data any)

func RespondAlreadyReported

func RespondAlreadyReported(cx *gin.Context, data any)

func RespondBadGateway

func RespondBadGateway(cx *gin.Context, err error)

func RespondBadRequest

func RespondBadRequest(cx *gin.Context, err error)

func RespondConflict

func RespondConflict(cx *gin.Context, err error)

func RespondContinue

func RespondContinue(cx *gin.Context)

func RespondCreated

func RespondCreated(cx *gin.Context, data any)

func RespondEarlyHints

func RespondEarlyHints(cx *gin.Context)

func RespondEntityTooLarge

func RespondEntityTooLarge(cx *gin.Context, err error)

func RespondExpectationFailed

func RespondExpectationFailed(cx *gin.Context, err error)

func RespondFailedDependency

func RespondFailedDependency(cx *gin.Context, err error)

func RespondForbidden added in v0.2.1

func RespondForbidden(cx *gin.Context, err error)

func RespondFound

func RespondFound(cx *gin.Context)

func RespondGatewayTimeout

func RespondGatewayTimeout(cx *gin.Context, err error)

func RespondGone

func RespondGone(cx *gin.Context, err error)

func RespondHeaderFieldsTooLarge

func RespondHeaderFieldsTooLarge(cx *gin.Context, err error)

func RespondInsufficientStorage

func RespondInsufficientStorage(cx *gin.Context, err error)

func RespondLengthRequired

func RespondLengthRequired(cx *gin.Context, err error)

func RespondLocked

func RespondLocked(cx *gin.Context, err error)

func RespondLoopDetected

func RespondLoopDetected(cx *gin.Context, err error)

func RespondMethodNotAllowed

func RespondMethodNotAllowed(cx *gin.Context, err error)

func RespondMisdirected

func RespondMisdirected(cx *gin.Context, err error)

func RespondMovedPermanently

func RespondMovedPermanently(cx *gin.Context)

func RespondMultiStatus

func RespondMultiStatus(cx *gin.Context, data any)

func RespondMultipleChoices

func RespondMultipleChoices(cx *gin.Context)

func RespondNetworkAuthenticationRequired

func RespondNetworkAuthenticationRequired(cx *gin.Context, err error)

func RespondNoContent added in v0.2.1

func RespondNoContent(cx *gin.Context)

func RespondNonAuthoritativeInfo

func RespondNonAuthoritativeInfo(cx *gin.Context, data any)

func RespondNotAcceptable

func RespondNotAcceptable(cx *gin.Context, err error)

func RespondNotExtended

func RespondNotExtended(cx *gin.Context, err error)

func RespondNotFound added in v0.2.1

func RespondNotFound(cx *gin.Context, err error)

func RespondNotImplemented

func RespondNotImplemented(cx *gin.Context, err error)

func RespondNotModified

func RespondNotModified(cx *gin.Context)

func RespondOk added in v0.2.1

func RespondOk(cx *gin.Context, data any)

func RespondPartialContent

func RespondPartialContent(cx *gin.Context, data any)

func RespondPermanentRedirect

func RespondPermanentRedirect(cx *gin.Context)

func RespondPreconditionFailed

func RespondPreconditionFailed(cx *gin.Context, err error)

func RespondPreconditionRequired

func RespondPreconditionRequired(cx *gin.Context, err error)

func RespondProcessing

func RespondProcessing(cx *gin.Context)

func RespondProxyAuthRequired

func RespondProxyAuthRequired(cx *gin.Context, err error)

func RespondRangeNotSatisfiable

func RespondRangeNotSatisfiable(cx *gin.Context, err error)

func RespondRequestTimeout

func RespondRequestTimeout(cx *gin.Context, err error)

func RespondResetContent

func RespondResetContent(cx *gin.Context, data any)

func RespondSeeOther

func RespondSeeOther(cx *gin.Context)

func RespondServerError

func RespondServerError(cx *gin.Context, err error)

func RespondServiceUnavailable

func RespondServiceUnavailable(cx *gin.Context, err error)

func RespondSwitchingProtocols

func RespondSwitchingProtocols(cx *gin.Context)

func RespondTeapot

func RespondTeapot(cx *gin.Context, err error)

func RespondTemporaryRedirect

func RespondTemporaryRedirect(cx *gin.Context)

func RespondTooEarly

func RespondTooEarly(cx *gin.Context, err error)

func RespondTooManyRequests

func RespondTooManyRequests(cx *gin.Context, err error)

func RespondURITooLong

func RespondURITooLong(cx *gin.Context, err error)

func RespondUnauthorized added in v0.2.1

func RespondUnauthorized(cx *gin.Context, err error)

func RespondUnavailableForLegalReasons

func RespondUnavailableForLegalReasons(cx *gin.Context, err error)

func RespondUnprocessableEntity

func RespondUnprocessableEntity(cx *gin.Context, err error)

func RespondUnsupportedMediaType

func RespondUnsupportedMediaType(cx *gin.Context, err error)

func RespondUpgradeRequired

func RespondUpgradeRequired(cx *gin.Context, err error)

func RespondUseProxy

func RespondUseProxy(cx *gin.Context)

func RespondUsed added in v0.2.1

func RespondUsed(cx *gin.Context, data any)

func RespondValidationError

func RespondValidationError(cx *gin.Context, err error)

func RespondVariantAlsoNegotiates

func RespondVariantAlsoNegotiates(cx *gin.Context, err error)

func RespondVersionNotSupported

func RespondVersionNotSupported(cx *gin.Context, err error)

func SetUrl added in v0.2.1

func SetUrl(key string, value *url.URL)

func Spread

func Spread[T any](slices ...[]T) []T

func TimeToPrettyString

func TimeToPrettyString(t time.Time) string

func TimeToYMDHISString

func TimeToYMDHISString(t time.Time) string

func TimeToYMDString

func TimeToYMDString(t time.Time) string

func ValidateDBConfig

func ValidateDBConfig(c database.Config) error

func ValueInArray

func ValueInArray[T comparable](value T, items []T) bool

func ValueOrDefault added in v0.2.1

func ValueOrDefault[T any](input *T, defaultValue T) T

ValueOrDefault returns the value of input or defaultValue if input is nil.

func ValueToString added in v0.2.1

func ValueToString(value any) (string, error)

ValueToString attempts to cast the provided value to a string and returns the result.

func VersionHandler added in v0.2.1

func VersionHandler(path string, version ...string) (string, gin.HandlerFunc)

func WriteFile

func WriteFile(filePath, contents string) error

func WriteFileCSV

func WriteFileCSV(filePath string, rows [][]string) error

func WriteFileJSON

func WriteFileJSON(filePath string, data any) error

func YMDHISStringToTime

func YMDHISStringToTime(str string) (time.Time, error)

func YMDStringToTime

func YMDStringToTime(str string) (time.Time, error)

Types

type ApiProblem added in v0.2.1

type ApiProblem hal.ApiProblem

type CSVRowCallback

type CSVRowCallback func(line []string, eof bool) error

type Collection added in v0.2.1

type Collection[T any] hal.Collection[T]

type DatabaseConfig added in v0.2.1

type DatabaseConfig database.Config

type HandlerTest

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

func NewHandlerTest

func NewHandlerTest(router Router) *HandlerTest

func (*HandlerTest) NewRequest added in v0.2.1

func (h *HandlerTest) NewRequest(path string) (*Request, error)

NewRequest creates a new Request using the HandlerTest remoteAddr as the base url.

func (*HandlerTest) Send

func (*HandlerTest) SetRemoteAddr

func (h *HandlerTest) SetRemoteAddr(ip string) *HandlerTest

SetRemoteAddr overwrites the default remote address to use when sending requests.

func (*HandlerTest) SetRequest added in v0.2.1

func (h *HandlerTest) SetRequest(request *Request) *HandlerTest

type ID

type ID uuid.UUID

ID is a UUID type that implements a custom Value function for storing UUIDs as binary(16) columns in a database using Gorm.

func GetIDParam added in v0.2.1

func GetIDParam(cx *gin.Context) (ID, error)

func MustParseAllIDs

func MustParseAllIDs(input []string) []ID

func MustParseID

func MustParseID(input string) ID

func NewID

func NewID() ID

func NilID

func NilID() ID

func ParseAllIDs

func ParseAllIDs(input []string) ([]ID, error)

func ParseID

func ParseID(s string) (ID, error)

func (ID) MarshalBinary

func (id ID) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*ID) Scan

func (id *ID) Scan(src any) error

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalBinary

func (id *ID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (ID) Valid

func (id ID) Valid() bool

func (ID) Value

func (id ID) Value() (driver.Value, error)

type ParamParser added in v0.2.1

type ParamParser[T any] func(string) (T, error)

type RedirectHandler added in v0.2.1

type RedirectHandler func(req *http.Request, via []*http.Request) error

type Request added in v0.2.1

type Request struct {
	Method  string
	URL     string
	Headers map[string]string
	// contains filtered or unexported fields
}

func NewRequest added in v0.2.1

func NewRequest(baseUrl string) (*Request, error)

func (*Request) AddFormParam added in v0.2.1

func (r *Request) AddFormParam(key, value string) *Request

func (*Request) AddQueryParam added in v0.2.1

func (r *Request) AddQueryParam(key, value string) *Request

func (*Request) Build added in v0.2.1

func (r *Request) Build(cx context.Context) (*http.Request, error)

func (*Request) GetBodyForm added in v0.2.1

func (r *Request) GetBodyForm() (io.Reader, error)

func (*Request) GetBodyJSON added in v0.2.1

func (r *Request) GetBodyJSON() (io.Reader, error)

func (*Request) Send added in v0.2.1

func (r *Request) Send(cx context.Context) (*http.Response, error)

func (*Request) SendAndRead added in v0.2.1

func (r *Request) SendAndRead(cx context.Context, output any) (*http.Response, error)

func (*Request) SetBasicAuth

func (r *Request) SetBasicAuth(username, password string) *Request

func (*Request) SetBearerAuth

func (r *Request) SetBearerAuth(token string) *Request

func (*Request) SetBodyForm added in v0.2.1

func (r *Request) SetBodyForm(data url.Values) *Request

func (*Request) SetBodyJSON added in v0.2.1

func (r *Request) SetBodyJSON(body any) *Request

func (*Request) SetClient

func (r *Request) SetClient(client *http.Client) *Request

func (*Request) SetContentTypeForm added in v0.2.1

func (r *Request) SetContentTypeForm() *Request

func (*Request) SetContentTypeJSON added in v0.2.1

func (r *Request) SetContentTypeJSON() *Request

func (*Request) SetFormParam added in v0.2.1

func (r *Request) SetFormParam(key, value string) *Request

func (*Request) SetHeader added in v0.2.1

func (r *Request) SetHeader(key, value string) *Request

func (*Request) SetMethod added in v0.2.1

func (r *Request) SetMethod(method string) *Request

func (*Request) SetQueryParam added in v0.2.1

func (r *Request) SetQueryParam(key, value string) *Request

func (*Request) SetRedirectHandler added in v0.2.1

func (r *Request) SetRedirectHandler(handler RedirectHandler) *Request

type RequestData added in v0.2.1

type RequestData url.Values

RequestData is an alias of url.Values that supports method chaining.

func MakeRequestData added in v0.2.1

func MakeRequestData() RequestData

func (RequestData) Add added in v0.2.1

func (v RequestData) Add(key, value string) RequestData

func (RequestData) Del added in v0.2.1

func (v RequestData) Del(key string) RequestData

func (RequestData) Get added in v0.2.1

func (v RequestData) Get(key string) string

func (RequestData) Has added in v0.2.1

func (v RequestData) Has(key string) bool

func (RequestData) Set added in v0.2.1

func (v RequestData) Set(key, value string) RequestData

func (RequestData) Values added in v0.2.1

func (v RequestData) Values() url.Values

type Resource added in v0.2.1

type Resource hal.Resource

type Router

type Router http.Router

func InitRouter added in v0.2.1

func InitRouter(baseUrl ...string) (Router, error)

type TestCase

type TestCase[T any] struct {
	Input    T
	Expected T
}

type UniqueItems

type UniqueItems[T comparable] map[T]struct{}

func (UniqueItems[T]) Add

func (u UniqueItems[T]) Add(key T)

func (UniqueItems[T]) Slice

func (u UniqueItems[T]) Slice() []T

Directories

Path Synopsis
sys
log

Jump to

Keyboard shortcuts

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