Documentation ¶
Index ¶
- Variables
- func AddMiddlewares(e *echo.Echo)
- func Logging(e *echo.Echo, friendly bool)
- type Config
- type Provider
- type Resource
- func (r *Resource[T]) CanDeleteById(predicate func(c echo.Context, entity T) bool)
- func (r *Resource[T]) CanListAll(predicate func(c echo.Context) bool)
- func (r *Resource[T]) CanListById(predicate func(c echo.Context, entity T) bool)
- func (r *Resource[T]) CanWriteById(predicate func(c echo.Context, entity T) bool)
- func (r *Resource[T]) Middlewares(m ...echo.MiddlewareFunc)
- func (r *Resource[T]) OnRegister(f func(e *echo.Echo))
- func (r *Resource[T]) OverrideDeleteByIdQuery(predicate func(c echo.Context, q *gorm.DB, entity T) error)
- func (r *Resource[T]) OverrideListAllQuery(predicate func(c echo.Context, q *gorm.DB) ([]T, error))
- func (r *Resource[T]) OverrideListByIdQuery(predicate func(c echo.Context, q *gorm.DB, id uint) (*T, error))
- func (r *Resource[T]) Register(e *echo.Echo)
- func (r *Resource[T]) SetCreateBindType(t any)
- func (r *Resource[T]) SetCreateTransformer(tf func(c echo.Context) (*T, error))
- func (r *Resource[T]) SetWriteBindType(t any)
- type Server
Constants ¶
This section is empty.
Variables ¶
var ( ErrorNoResourceAccess = errors.New("no resource access") ErrorNoResourceFound = errors.New("no resource found") ErrorDatabase = errors.New("database problem") ErrorNoBindType = errors.New("unable to handle this request") ErrorInvalidData = errors.New("bad data") ErrorInvalidID = errors.New("bad id") )
var ( DevelopmentConfig = Config{ DSN: "", HttpPort: 80, AutoTLS: false, Domains: []string{}, FriendlyLogging: true, } )
Functions ¶
func AddMiddlewares ¶
func AddMiddlewares(e *echo.Echo)
Types ¶
type Resource ¶ added in v1.1.2
Resource is an automatic REST api module which lets the consumer simply define the resource and it will have associated database code, et.c. automatically set up.
func (*Resource[T]) CanDeleteById ¶ added in v1.1.2
CanDeleteById takes a predicate and determines whether the operation can proceed.
func (*Resource[T]) CanListAll ¶ added in v1.1.2
CanListAll takes a predicate and determines whether the operation can proceed.
func (*Resource[T]) CanListById ¶ added in v1.1.2
CanListById takes a predicate and determines whether the operation can proceed.
func (*Resource[T]) CanWriteById ¶ added in v1.1.4
CanWriteById takes a predicate and determines whether the operation can proceed.
func (*Resource[T]) Middlewares ¶ added in v1.1.3
func (r *Resource[T]) Middlewares(m ...echo.MiddlewareFunc)
func (*Resource[T]) OnRegister ¶ added in v1.1.2
func (r *Resource[T]) OnRegister(f func(e *echo.Echo))
OnRegister sets the registration hook to argument f.
func (*Resource[T]) OverrideDeleteByIdQuery ¶ added in v1.1.10
func (r *Resource[T]) OverrideDeleteByIdQuery(predicate func(c echo.Context, q *gorm.DB, entity T) error)
OverrideDeleteByIdQuery lets consumers override the query used in the "Delete By Id" operation.
func (*Resource[T]) OverrideListAllQuery ¶ added in v1.1.2
OverrideListAllQuery lets consumers override the query used in the "List All" operation.
func (*Resource[T]) OverrideListByIdQuery ¶ added in v1.1.2
func (r *Resource[T]) OverrideListByIdQuery(predicate func(c echo.Context, q *gorm.DB, id uint) (*T, error))
OverrideListByIdQuery lets consumers override the query used in the "List By Id" operation.
func (*Resource[T]) Register ¶ added in v1.1.2
func (r *Resource[T]) Register(e *echo.Echo)
Register is called when minimal initializes, and will add routes and trigger the automigration.
func (*Resource[T]) SetCreateBindType ¶ added in v1.1.2
SetCreateBindType will typically be a DTO struct.
func (*Resource[T]) SetCreateTransformer ¶ added in v1.1.8
func (*Resource[T]) SetWriteBindType ¶ added in v1.1.2
SetWriteBindType will typically be a DTO struct.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func New ¶
New creates a minimal Server instance. This is a 'minimal' example of how to configure the library:
//go:embed assets var embeddedFiles embed.FS func embedFS(fs embed.FS) http.FileSystem { return http.FS(fs) } type BaseRoutes struct{} func (br *BaseRoutes) Register(e *echo.Echo) { e.GET("/", func(c echo.Context) error { return c.Render(200, "assets/index.html", nil) }) } func main() { config := server.DevelopmentConfig _ = fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=5432 sslmode=disable TimeZone=Europe/Oslo", "localhost", "postgres", "postgres", "tmp", ) config.DSN = dsn s := server.New(config, []provider.RouteProvider{ &BaseRoutes{}, }, []any{}) s.Init(embedFS(embeddedFiles)) }
func (*Server) Init ¶
func (s *Server) Init(fs http.FileSystem)