Documentation ¶
Index ¶
- Constants
- func ApplyQueryToGorm(db *gorm.DB, q query.Builder, paginate bool) (error, query.Template)
- func AssertRecordDeleted[M any](t *testing.T, db *gorm.DB, input M, msg string)
- func AssertValidID(t *testing.T, id ID)
- func AssertValidInitialCreatedAt(t *testing.T, d time.Time)
- func AssertValidInitialDeletedAt(t *testing.T, d *time.Time)
- func AssertValidInitialUpdatedAt(t *testing.T, d *time.Time)
- func AssertValidModifiedUpdatedAt(t *testing.T, d *time.Time)
- func BindRequest[T any](cx *gin.Context) (T, error)
- func EnvBool(key string, defaultValue bool) bool
- func EnvDuration(key string, defaultValue time.Duration) time.Duration
- func EnvFloat64(key string, defaultValue float64) float64
- func EnvInt(key string, defaultValue int) int
- func EnvInt32(key string, defaultValue int32) int32
- func EnvInt64(key string, defaultValue int64) int64
- func EnvIntSlice(key string, defaultValue []int) []int
- func EnvString(key string, defaultValue string) string
- func EnvStringMap(key string, defaultValue map[string]any) map[string]any
- func EnvStringMapString(key string, defaultValue map[string]string) map[string]string
- func EnvStringSlice(key string, defaultValue []string) []string
- func EnvTime(key string, defaultValue time.Time) time.Time
- func EnvUint16(key string, defaultValue uint16) uint16
- func EnvUint32(key string, defaultValue uint32) uint32
- func EnvUint64(key string, defaultValue uint64) uint64
- func ErrorBesidesRecordNotFound(err error) bool
- func ErrorsToError(errs []error) error
- func ExitError(err error)
- func ExitSuccess()
- func FileExists(filePath string) (bool, error)
- func GetDB(c DatabaseConfig) (*gorm.DB, error)
- func GetLogger() *zap.SugaredLogger
- func GetMainDB() (*gorm.DB, error)
- func GetMigrationDB(db *gorm.DB) (*sql.DB, error)
- func GetStrictLogger() *zap.Logger
- func GetUrl(key ...string) *url.URL
- func HandleCSVRows(path string, skipHeaderRow bool, breakOnEOF bool, callback CSVRowCallback) error
- func HealthHandler(path string, message ...string) (string, gin.HandlerFunc)
- func Init() error
- func MustInit()
- func NewResourceLinks(key, path string) *hal.ResourceLinks
- func NewValidationError(field, rule string) error
- func ParseParam[T any](cx *gin.Context, key string, parser ParamParser[T]) (T, error)
- func Print(s string, a ...any)
- func PrintDanger(s string, a ...any)
- func PrintHeading(s string, a ...any)
- func PrintIndent(s string, a ...any)
- func PrintInfo(s string, a ...any)
- func PrintSuccess(s string, a ...any)
- func PrintWarning(s string, a ...any)
- func RandomBool() bool
- func RandomDecimal(min, max int64) decimal.Decimal
- func RandomDecimalExp(min, max int64, exp int32) decimal.Decimal
- func RandomIndex(length int) int
- func RandomInt(min, max int) int
- func RandomInt32(min, max int32) int32
- func RandomInt64(min, max int64) int64
- func ReadFileCSV(path string) (reader *csv.Reader, err error)
- func ReadFileJSON[T any](filePath string, target *T) (*os.File, error)
- func RecordNotFound(err error) bool
- func RequireDecimalEqual(t *testing.T, exp, act any, msgAndArgs ...any)
- func ResetDB(db *gorm.DB) error
- func RespondAccepted(cx *gin.Context, data any)
- func RespondBadRequest(cx *gin.Context, err error)
- func RespondCreated(cx *gin.Context, data any)
- func RespondForbidden(cx *gin.Context, err error)
- func RespondNoContent(cx *gin.Context)
- func RespondNotFound(cx *gin.Context, err error)
- func RespondOk(cx *gin.Context, data any)
- func RespondServerError(cx *gin.Context, err error)
- func RespondUnauthorized(cx *gin.Context, err error)
- func RespondUsed(cx *gin.Context, data any)
- func RespondValidationError(cx *gin.Context, err error)
- func SetUrl(key string, value *url.URL)
- func TimeToPrettyString(t time.Time) string
- func TimeToYMDHISString(t time.Time) string
- func TimeToYMDString(t time.Time) string
- func ValueOrDefault[T any](input *T, defaultValue T) T
- func ValueToString(value any) (string, error)
- func VersionHandler(path string, version ...string) (string, gin.HandlerFunc)
- func WriteFile(filePath, contents string) error
- func WriteFileCSV(filePath string, rows [][]string) error
- func WriteFileJSON(filePath string, data any) error
- func YMDHISStringToTime(str string) (time.Time, error)
- func YMDStringToTime(str string) (time.Time, error)
- type ApiProblem
- type CSVRowCallback
- type Collection
- type DatabaseConfig
- type HandlerTest
- type ID
- func (id ID) MarshalBinary() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id *ID) Scan(src any) error
- func (id ID) String() string
- func (id *ID) UnmarshalBinary(data []byte) error
- func (id *ID) UnmarshalText(data []byte) error
- func (id ID) Valid() bool
- func (id ID) Value() (driver.Value, error)
- type ParamParser
- type RedirectHandler
- type Request
- func (r *Request) AddFormParam(key, value string) *Request
- func (r *Request) AddQueryParam(key, value string) *Request
- func (r *Request) Build() (*http.Request, error)
- func (r *Request) GetBodyForm() (io.Reader, error)
- func (r *Request) GetBodyJSON() (io.Reader, error)
- func (r *Request) Send() (*http.Response, error)
- func (r *Request) SendAndRead(output any) (*http.Response, error)
- func (r *Request) SetBodyForm(data url.Values) *Request
- func (r *Request) SetBodyJSON(body any) *Request
- func (r *Request) SetContentTypeForm() *Request
- func (r *Request) SetContentTypeJSON() *Request
- func (r *Request) SetFormParam(key, value string) *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetMethod(method string) *Request
- func (r *Request) SetQueryParam(key, value string) *Request
- func (r *Request) SetRedirectHandler(handler RedirectHandler) *Request
- type RequestData
- type Resource
- type Router
Constants ¶
const ( 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 AssertRecordDeleted ¶ added in v0.2.1
func AssertValidID ¶
func BindRequest ¶ added in v0.2.1
BindRequest returns a T with values set by binding the request JSON from the provided Gin context.
func EnvBool ¶
EnvBool returns the value of the specified env var or defaultValue if the env var is not set.
func EnvDuration ¶ added in v0.2.1
EnvDuration returns the value of the specified env var or defaultValue if the env var is not set.
func EnvFloat64 ¶ added in v0.2.1
EnvFloat64 returns the value of the specified env var or defaultValue if the env var is not set.
func EnvInt ¶ added in v0.1.1
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
EnvInt32 returns the value of the specified env var or defaultValue if the env var is not set.
func EnvInt64 ¶ added in v0.2.1
EnvInt64 returns the value of the specified env var or defaultValue if the env var is not set.
func EnvIntSlice ¶ added in v0.2.1
EnvIntSlice returns the value of the specified env var or defaultValue if the env var is not set.
func EnvString ¶
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
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
EnvStringMapString returns the value of the specified env var or defaultValue if the env var is not set.
func EnvStringSlice ¶ added in v0.2.1
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
EnvTime returns the value of the specified env var or defaultValue if the env var is not set.
func EnvUint16 ¶ added in v0.2.1
EnvUint16 returns the value of the specified env var or defaultValue if the env var is not set.
func EnvUint32 ¶ added in v0.2.1
EnvUint32 returns the value of the specified env var or defaultValue if the env var is not set.
func EnvUint64 ¶ added in v0.2.1
EnvUint64 returns the value of the specified env var or defaultValue if the env var is not set.
func ErrorBesidesRecordNotFound ¶ added in v0.2.1
ErrorBesidesRecordNotFound true if the provided error is NOT a Gorm "record not found" error.
func ErrorsToError ¶
func ExitSuccess ¶
func ExitSuccess()
func FileExists ¶
func GetLogger ¶ added in v0.1.1
func GetLogger() *zap.SugaredLogger
func GetStrictLogger ¶ added in v0.2.1
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 NewResourceLinks ¶ added in v0.2.1
func NewResourceLinks(key, path string) *hal.ResourceLinks
func NewValidationError ¶ added in v0.2.1
func ParseParam ¶ added in v0.2.1
func PrintDanger ¶
func PrintHeading ¶
func PrintIndent ¶
func PrintSuccess ¶
func PrintWarning ¶
func RandomBool ¶
func RandomBool() bool
func RandomDecimal ¶
func RandomIndex ¶
func RandomInt32 ¶
func RandomInt64 ¶
func RecordNotFound ¶
RecordNotFound returns true if the provided error is the Gorm "record not found" error.
func RespondAccepted ¶ added in v0.2.1
func RespondBadRequest ¶
func RespondCreated ¶
func RespondForbidden ¶ added in v0.2.1
func RespondNoContent ¶ added in v0.2.1
func RespondNotFound ¶ added in v0.2.1
func RespondServerError ¶
func RespondUnauthorized ¶ added in v0.2.1
func RespondUsed ¶ added in v0.2.1
func RespondValidationError ¶
func TimeToPrettyString ¶
func TimeToYMDHISString ¶
func TimeToYMDString ¶
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
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 WriteFileCSV ¶
func WriteFileJSON ¶
Types ¶
type ApiProblem ¶ added in v0.2.1
type ApiProblem hal.ApiProblem
type CSVRowCallback ¶
type Collection ¶ added in v0.2.1
type Collection[T any] hal.Collection[T]
type DatabaseConfig ¶ added in v0.2.1
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 (h *HandlerTest) Send() (*httptest.ResponseRecorder, error)
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 ¶
ID is a UUID type that implements a custom Value function for storing UUIDs as binary(16) columns in a database using Gorm.
func ParseAllIDs ¶
func (ID) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (ID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*ID) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler.
func (*ID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type ParamParser ¶ added in v0.2.1
type RedirectHandler ¶ added in v0.2.1
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 (*Request) AddFormParam ¶ added in v0.2.1
func (*Request) AddQueryParam ¶ added in v0.2.1
func (*Request) SendAndRead ¶ added in v0.2.1
func (*Request) SetBodyForm ¶ added in v0.2.1
func (*Request) SetBodyJSON ¶ added in v0.2.1
func (*Request) SetContentTypeForm ¶ added in v0.2.1
func (*Request) SetContentTypeJSON ¶ added in v0.2.1
func (*Request) SetFormParam ¶ added in v0.2.1
func (*Request) SetQueryParam ¶ added in v0.2.1
func (*Request) SetRedirectHandler ¶ added in v0.2.1
func (r *Request) SetRedirectHandler(handler RedirectHandler) *Request
type RequestData ¶ added in v0.2.1
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