123456789101112131415161718192021222324252627282930313233343536373839 |
- package rest
- import (
- "git.nspix.com/golang/micro/gateway/http"
- "gorm.io/gorm"
- "strings"
- )
- type Options struct {
- EnableNamespace bool
- DB *gorm.DB
- Prefix string
- Formatter *Formatter
- Middleware []http.Middleware
- }
- type Option func(o *Options)
- func WithPrefix(prefix string) Option {
- return func(o *Options) {
- if !strings.HasPrefix(prefix, "/") {
- prefix = "/" + prefix
- }
- o.Prefix = prefix
- }
- }
- func WithDB(db *gorm.DB) Option {
- return func(o *Options) {
- o.DB = db
- }
- }
- func NewOptions() *Options {
- return &Options{
- Formatter: DefaultFormatter,
- Middleware: make([]http.Middleware, 0),
- }
- }
|