Documentation ¶
Index ¶
- 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 BindMiddleware(r interface{}) gin.HandlerFunc
- func BindRequestMiddleware(req interface{}) gin.HandlerFunc
- func DebugEnabled() bool
- func EnvBool(s string, defaultValue bool) bool
- func EnvInt(s string, defaultValue int) int
- func EnvString(s string, defaultValue string) string
- func ErrorIfProd() error
- func ErrorsBesidesRecordNotFound(errs []error) bool
- func ErrorsToError(errs []error) error
- func ErrorsToString(errs []error) string
- func ErrorsToStrings(errs []error) []string
- func ExitError(err error)
- func ExitErrors(errs []error)
- func ExitSuccess()
- func GenerateToken() string
- func GetDB(key string) (*gorm.DB, error)
- func GetFileLogger(name string) (*logrus.Logger, error)
- func GetLogger() *logrus.Logger
- func GetMainDB() (*gorm.DB, error)
- func GetRequest(c *gin.Context) interface{}
- func GetRouter() app.Router
- func HandleCSVRows(path string, skipHeaderRow bool, breakOnEOF bool, callback CSVCallback) error
- func Init()
- func OpenCSV(path string) (reader *csv.Reader, err error)
- func PrependErrors(errs []error, err error) []error
- func PrintFail(s string)
- func PrintHeading(s string)
- func PrintIndent(s string)
- func PrintInfo(s string)
- func PrintSuccess(s string)
- func PrintWarning(s string)
- 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 RecordNotFound(errs []error) bool
- func RequireDecimalEqual(t *testing.T, exp, act interface{}, msgAndArgs ...interface{})
- func RespondAuthenticationError(c *gin.Context)
- func RespondBadRequestError(c *gin.Context, err error)
- func RespondBadRequestErrors(c *gin.Context, errs []error)
- func RespondCreated(c *gin.Context, data interface{})
- func RespondData(c *gin.Context, data interface{})
- func RespondInvalid(c *gin.Context)
- func RespondMessage(c *gin.Context, m string)
- func RespondNotFoundError(c *gin.Context, err error)
- func RespondNotFoundErrors(c *gin.Context, errs []error)
- func RespondServerError(c *gin.Context, err error)
- func RespondServerErrors(c *gin.Context, errs []error)
- func RespondUnauthorizedError(c *gin.Context)
- func RespondValid(c *gin.Context)
- func RespondValidationError(c *gin.Context, errs map[string]error)
- func TimeToPrettyString(t time.Time) string
- func TimeToYMDHISString(t time.Time) string
- func TimeToYMDString(t time.Time) string
- func YMDHISStringToTime(str string) (time.Time, error)
- func YMDStringToTime(str string) (time.Time, error)
- type CSVCallback
- type ContextResponder
- type ErrorHandler
- type ErrorHandlerGin
- func (h ErrorHandlerGin) HandleContext(c *gin.Context, m string, responder ContextResponder)
- func (h ErrorHandlerGin) HandleError(c *gin.Context, err error, responder ErrorResponder)
- func (h ErrorHandlerGin) HandleErrorM(c *gin.Context, err error, m string, responder ErrorResponder)
- func (h ErrorHandlerGin) HandleErrors(c *gin.Context, errs []error, responder ErrorResponder)
- func (h ErrorHandlerGin) HandleErrorsM(c *gin.Context, errs []error, m string, responder ErrorResponder)
- func (h ErrorHandlerGin) HandleMessage(c *gin.Context, m string, responder ErrorResponder)
- type ErrorResponder
- type HandlerTest
- func (h *HandlerTest) Body(data *map[string]interface{}) *HandlerTest
- func (h *HandlerTest) Delete(url string) *HandlerTest
- func (h *HandlerTest) DeleteF(urlf string, a ...interface{}) *HandlerTest
- func (h *HandlerTest) Get(url string) *HandlerTest
- func (h *HandlerTest) GetF(urlf string, a ...interface{}) *HandlerTest
- func (h *HandlerTest) Headers(headers map[string]string) *HandlerTest
- func (h *HandlerTest) Post(url string) *HandlerTest
- func (h *HandlerTest) PostF(urlf string, a ...interface{}) *HandlerTest
- func (h *HandlerTest) Put(url string) *HandlerTest
- func (h *HandlerTest) PutF(urlf string, a ...interface{}) *HandlerTest
- func (h *HandlerTest) Request(method, url string) *HandlerTest
- func (h *HandlerTest) RequestF(method, urlf string, a ...interface{}) *HandlerTest
- func (h *HandlerTest) Send() *HandlerTestResponse
- func (h *HandlerTest) SetRemoteAddr(ip string)
- type HandlerTestResponse
- type ID
- func (id ID) MarshalBinary() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id *ID) Scan(src interface{}) 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 Model
- type RequestValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertValidID ¶
func BindMiddleware ¶ added in v0.1.1
func BindMiddleware(r interface{}) gin.HandlerFunc
func BindRequestMiddleware ¶
func BindRequestMiddleware(req interface{}) gin.HandlerFunc
Validates an incoming request and binds the request body to the provided struct if the validation passes.
Returns a 400 error with validation errors if binding fails.
Sets the bound request as an interface{} in the Gin registry if binding succeeds. You can retrieve in your handlers it like this:
r, ok := goat.GetRequest(c).(*yourRequestStruct)
This middleware allows you to annotate your request struct fields with `binding:"required"` to make required fields.
@TODO it seems that if a request struct has a field that is named the same as one of it's child struct's fields that the validation messages don't prefix the field name with child struct's name
func DebugEnabled ¶ added in v0.1.1
func DebugEnabled() bool
func ErrorIfProd ¶ added in v0.1.1
func ErrorIfProd() error
func ErrorsBesidesRecordNotFound ¶
Returns true if there are any errors in the provided array that are NOT a 'record not found' error
func ErrorsToError ¶
func ErrorsToString ¶
func ErrorsToStrings ¶
func ExitErrors ¶ added in v0.1.1
func ExitErrors(errs []error)
func ExitSuccess ¶
func ExitSuccess()
func GenerateToken ¶
func GenerateToken() string
Returns a random string that can be used as a Basic Auth token.
func GetRequest ¶
Returns true and a request object from the Gin context created by the bindRequestMiddleware. If the request is not set, false is returned and 500 response headers are set.
func HandleCSVRows ¶
func HandleCSVRows(path string, skipHeaderRow bool, breakOnEOF bool, callback CSVCallback) error
func Init ¶
func Init()
Goat has three primary concerns: database connections and schema management, request handling, and logging. These concerns are encapsulated inside of services that are bootstrapped when goat.Init() is called.
func PrependErrors ¶
func PrintHeading ¶
func PrintHeading(s string)
func PrintIndent ¶
func PrintIndent(s string)
func PrintSuccess ¶
func PrintSuccess(s string)
func PrintWarning ¶
func PrintWarning(s string)
func RandomBool ¶
func RandomBool() bool
func RandomDecimal ¶
func RandomIndex ¶
func RandomInt32 ¶
func RandomInt64 ¶
func RecordNotFound ¶
Returns true if the provided slice of errors
func RequireDecimalEqual ¶
func RespondBadRequestError ¶
func RespondBadRequestErrors ¶
func RespondCreated ¶
func RespondData ¶
func RespondInvalid ¶
func RespondMessage ¶
func RespondNotFoundError ¶
func RespondNotFoundErrors ¶
func RespondServerError ¶
func RespondServerErrors ¶
func RespondValid ¶
func TimeToPrettyString ¶
func TimeToYMDHISString ¶
func TimeToYMDString ¶
Types ¶
type CSVCallback ¶ added in v0.1.1
type ContextResponder ¶
type ErrorHandler ¶
type ErrorHandler interface { HandleContext(c *gin.Context, m string, responder ContextResponder) HandleMessage(c *gin.Context, m string, responder ErrorResponder) HandleError(c *gin.Context, err error, responder ErrorResponder) HandleErrorM(c *gin.Context, err error, m string, responder ErrorResponder) HandleErrors(c *gin.Context, errs []error, responder ErrorResponder) HandleErrorsM(c *gin.Context, errs []error, m string, responder ErrorResponder) }
func NewErrorHandler ¶
func NewErrorHandler(l *logrus.Logger) ErrorHandler
type ErrorHandlerGin ¶
type ErrorHandlerGin struct {
// contains filtered or unexported fields
}
func (ErrorHandlerGin) HandleContext ¶
func (h ErrorHandlerGin) HandleContext(c *gin.Context, m string, responder ContextResponder)
func (ErrorHandlerGin) HandleError ¶
func (h ErrorHandlerGin) HandleError(c *gin.Context, err error, responder ErrorResponder)
func (ErrorHandlerGin) HandleErrorM ¶
func (h ErrorHandlerGin) HandleErrorM(c *gin.Context, err error, m string, responder ErrorResponder)
func (ErrorHandlerGin) HandleErrors ¶
func (h ErrorHandlerGin) HandleErrors(c *gin.Context, errs []error, responder ErrorResponder)
func (ErrorHandlerGin) HandleErrorsM ¶
func (h ErrorHandlerGin) HandleErrorsM(c *gin.Context, errs []error, m string, responder ErrorResponder)
func (ErrorHandlerGin) HandleMessage ¶
func (h ErrorHandlerGin) HandleMessage(c *gin.Context, m string, responder ErrorResponder)
type ErrorResponder ¶
type HandlerTest ¶
type HandlerTest struct {
// contains filtered or unexported fields
}
func NewHandlerTest ¶
func NewHandlerTest(r *ghttp.RouterGin) *HandlerTest
func (*HandlerTest) Body ¶
func (h *HandlerTest) Body(data *map[string]interface{}) *HandlerTest
Set the body for the current request.
func (*HandlerTest) Delete ¶
func (h *HandlerTest) Delete(url string) *HandlerTest
func (*HandlerTest) DeleteF ¶
func (h *HandlerTest) DeleteF(urlf string, a ...interface{}) *HandlerTest
func (*HandlerTest) Get ¶
func (h *HandlerTest) Get(url string) *HandlerTest
func (*HandlerTest) GetF ¶
func (h *HandlerTest) GetF(urlf string, a ...interface{}) *HandlerTest
func (*HandlerTest) Headers ¶
func (h *HandlerTest) Headers(headers map[string]string) *HandlerTest
Set the headers for the current request.
func (*HandlerTest) Post ¶
func (h *HandlerTest) Post(url string) *HandlerTest
func (*HandlerTest) PostF ¶
func (h *HandlerTest) PostF(urlf string, a ...interface{}) *HandlerTest
func (*HandlerTest) Put ¶
func (h *HandlerTest) Put(url string) *HandlerTest
func (*HandlerTest) PutF ¶
func (h *HandlerTest) PutF(urlf string, a ...interface{}) *HandlerTest
func (*HandlerTest) Request ¶
func (h *HandlerTest) Request(method, url string) *HandlerTest
func (*HandlerTest) RequestF ¶
func (h *HandlerTest) RequestF(method, urlf string, a ...interface{}) *HandlerTest
func (*HandlerTest) Send ¶
func (h *HandlerTest) Send() *HandlerTestResponse
Returns the result of sending the current request. Panics if the request creation fails.
func (*HandlerTest) SetRemoteAddr ¶
func (h *HandlerTest) SetRemoteAddr(ip string)
Overwrite the default remote address to use when sending requests.
type HandlerTestResponse ¶
type HandlerTestResponse struct { *httptest.ResponseRecorder BodyString string }
func (*HandlerTestResponse) Map ¶
func (r *HandlerTestResponse) Map(m interface{}) error
Map a handler test response to the provided struct.
type ID ¶
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 Model ¶
type RequestValidator ¶
type RequestValidator struct {
*validator.Validate
}
func (*RequestValidator) ValidateStruct ¶
func (v *RequestValidator) ValidateStruct(i interface{}) error