package aeusadmin import ( "git.nobla.cn/golang/aeus/pkg/cache" "git.nobla.cn/golang/aeus/transport/http" "git.nobla.cn/golang/rest" "git.nobla.cn/golang/rest/types" "gorm.io/gorm" ) var ( defaultScenarios = []string{ types.ScenarioList, types.ScenarioCreate, types.ScenarioUpdate, types.ScenarioDelete, types.ScenarioView, types.ScenarioExport, } ) type ( options struct { db *gorm.DB cache cache.Cache domain string moduleName string apiPrefix string //接口前缀 viewPrefix string //生成菜单View的前缀路径 vuePath string //生成Vue文件的路径,如果指定了启动的时候会自动生成Vue的文件 translate Translate disableDefault bool disableRecorder bool httpServer *http.Server restOpts []rest.Option } Option func(*options) Translate interface { Menu(model *rest.Model, label string) string Permission(model *rest.Model, scene string, label string) string } MenuBuild interface { Label(model *rest.Model) string Title(model *rest.Model) string Icon(model *rest.Model) string Uri(model *rest.Model) string ViewPath(model *rest.Model) string } vueTemplateData struct { ModuleName string TableName string ApiPrefix string Readonly bool Permissions map[string]string } ) func WithDB(db *gorm.DB) Option { return func(o *options) { o.db = db } } func WithCache(cache cache.Cache) Option { return func(o *options) { o.cache = cache } } func WithoutDefault() Option { return func(o *options) { o.disableDefault = true } } func WithoutRecorder() Option { return func(o *options) { o.disableRecorder = true } } func WithHttpServer(server *http.Server) Option { return func(o *options) { o.httpServer = server } } func WithApiPrefix(apiPrefix string) Option { return func(o *options) { o.apiPrefix = apiPrefix } } func WithModuleName(moduleName string) Option { return func(o *options) { o.moduleName = moduleName } } func WithViewPrefix(viewPath string) Option { return func(o *options) { o.viewPrefix = viewPath } } func WithTranslate(t Translate) Option { return func(o *options) { o.translate = t } } func WithRestOptions(opts ...rest.Option) Option { return func(o *options) { o.restOpts = opts } } func WithVuePath(path string) Option { return func(o *options) { o.vuePath = path } } func newOptions(opts ...Option) *options { o := &options{ viewPrefix: "views", moduleName: "organize", domain: "localhost", } for _, opt := range opts { opt(o) } return o }