12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package rest
- import (
- "context"
- "gorm.io/gorm"
- )
- type Options struct {
- EnableNamespace bool
- Namespace string
- ApiPrefix string
- TablePrefix string
- DB *gorm.DB
- Formatter *Formatter
- Delegate *delegate
- Context context.Context
- LookupFunc func(ctx context.Context, ns string, moduleName string, tableName string, scene string) []*Schema
- }
- type Option func(o *Options)
- func WithContext(ctx context.Context) Option {
- return func(o *Options) {
- o.Context = ctx
- }
- }
- func WithDB(db *gorm.DB) Option {
- return func(o *Options) {
- o.DB = db
- }
- }
- func WithNamespace(ns string) Option {
- return func(o *Options) {
- o.EnableNamespace = true
- o.Namespace = ns
- }
- }
- func WithApiPrefix(prefix string) Option {
- return func(o *Options) {
- o.ApiPrefix = prefix
- }
- }
- func WithTablePrefix(prefix string) Option {
- return func(o *Options) {
- o.TablePrefix = prefix
- }
- }
- func newOptions() *Options {
- return &Options{
- Namespace: DefaultNamespace,
- Formatter: DefaultFormatter,
- }
- }
|