options.go 573 B

1234567891011121314151617181920212223242526272829303132333435
  1. package rest
  2. import (
  3. "git.nspix.com/golang/micro/gateway/http"
  4. "gorm.io/gorm"
  5. )
  6. type Options struct {
  7. EnableNamespace bool
  8. DB *gorm.DB
  9. Prefix string
  10. Formatter *Formatter
  11. Middleware []http.Middleware
  12. }
  13. type Option func(o *Options)
  14. func WithPrefix(prefix string) Option {
  15. return func(o *Options) {
  16. o.Prefix = prefix
  17. }
  18. }
  19. func WithDB(db *gorm.DB) Option {
  20. return func(o *Options) {
  21. o.DB = db
  22. }
  23. }
  24. func NewOptions() *Options {
  25. return &Options{
  26. Formatter: DefaultFormatter,
  27. Middleware: make([]http.Middleware, 0),
  28. }
  29. }