options.go 531 B

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