goat

package module
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2019 License: MIT Imports: 33 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

This section is empty.

Variables

This section is empty.

Functions

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 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 EnvBool

func EnvBool(s string, defaultValue bool) bool

func EnvInt added in v0.1.1

func EnvInt(s string, defaultValue int) int

func EnvString

func EnvString(s string, defaultValue string) string

func ErrorIfProd added in v0.1.1

func ErrorIfProd() error

func ErrorsBesidesRecordNotFound

func ErrorsBesidesRecordNotFound(errs []error) bool

Returns true if there are any errors in the provided array that are NOT a 'record not found' error

func ErrorsToError

func ErrorsToError(errs []error) error

func ErrorsToString

func ErrorsToString(errs []error) string

func ErrorsToStrings

func ErrorsToStrings(errs []error) []string

func ExitError added in v0.1.1

func ExitError(err error)

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

func GetDB(key string) (*gorm.DB, error)

func GetFileLogger added in v0.1.1

func GetFileLogger(name string) (*logrus.Logger, error)

func GetLogger added in v0.1.1

func GetLogger() *logrus.Logger

func GetMainDB added in v0.1.1

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

func GetRequest

func GetRequest(c *gin.Context) interface{}

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

func GetRouter() app.Router

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 OpenCSV

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

func PrependErrors

func PrependErrors(errs []error, err error) []error

func PrintFail

func PrintFail(s string)

func PrintHeading

func PrintHeading(s string)

func PrintIndent

func PrintIndent(s string)

func PrintInfo

func PrintInfo(s string)

func PrintSuccess

func PrintSuccess(s string)

func PrintWarning

func PrintWarning(s string)

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 RecordNotFound

func RecordNotFound(errs []error) bool

Returns true if the provided slice of errors

func RequireDecimalEqual

func RequireDecimalEqual(t *testing.T, exp, act interface{}, msgAndArgs ...interface{})

func RespondAuthenticationError

func RespondAuthenticationError(c *gin.Context)

func RespondBadRequestError

func RespondBadRequestError(c *gin.Context, err error)

func RespondBadRequestErrors

func RespondBadRequestErrors(c *gin.Context, errs []error)

func RespondCreated

func RespondCreated(c *gin.Context, data interface{})

func RespondData

func RespondData(c *gin.Context, data interface{})

func RespondInvalid

func RespondInvalid(c *gin.Context)

func RespondMessage

func RespondMessage(c *gin.Context, m string)

func RespondNotFoundError

func RespondNotFoundError(c *gin.Context, err error)

func RespondNotFoundErrors

func RespondNotFoundErrors(c *gin.Context, errs []error)

func RespondServerError

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

func RespondServerErrors

func RespondServerErrors(c *gin.Context, errs []error)

func RespondUnauthorizedError

func RespondUnauthorizedError(c *gin.Context)

func RespondValid

func RespondValid(c *gin.Context)

func RespondValidationError

func RespondValidationError(c *gin.Context, errs map[string]error)

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 YMDHISStringToTime

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

func YMDStringToTime

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

Types

type CSVCallback added in v0.1.1

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

type ContextResponder

type ContextResponder func(c *gin.Context)

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 ErrorResponder func(c *gin.Context, e error)

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

type ID uuid.UUID

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

func NewID

func NewID() ID

func NilID

func NilID() ID

func ParseAllIDs

func ParseAllIDs(s []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 interface{}) 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 Model

type Model struct {
	ID        ID         `json:"id" gorm:"primary_key"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at"`
}

func (Model) BeforeCreate

func (m Model) BeforeCreate(scope *gorm.Scope) error

type RequestValidator

type RequestValidator struct {
	*validator.Validate
}

func (*RequestValidator) ValidateStruct

func (v *RequestValidator) ValidateStruct(i interface{}) error

Directories

Path Synopsis
src
cmd
sys

Jump to

Keyboard shortcuts

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