From b56d0a82fe165245add03eea293f1df646332ae3 Mon Sep 17 00:00:00 2001 From: godcong Date: Fri, 16 Aug 2024 17:39:33 +0800 Subject: [PATCH] feat(config): add enable flags for app components and services Introduce boolean 'Enable' fields for various components and services within the application configuration. This allows for finer-grained control over the application's modules and services, enabling or disabling them as needed. BREAKING CHANGE: The configuration structure has been extended with 'Enable' flags. Users will need to update their configuration files to include these new fields for each component and service. --- config/app.go | 1 + config/backend.go | 1 + config/config.go | 24 +++++++++++----------- config/config_test.go | 46 +++++++++++++++++++++++++++++++++++++++++++ config/extention.go | 1 + config/fontend.go | 1 + config/service.go | 5 +++++ 7 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 config/config_test.go create mode 100644 config/service.go diff --git a/config/app.go b/config/app.go index 1b56509..7ddc588 100644 --- a/config/app.go +++ b/config/app.go @@ -4,4 +4,5 @@ package config type App struct { + Enable bool } diff --git a/config/backend.go b/config/backend.go index 2484307..733f1cb 100644 --- a/config/backend.go +++ b/config/backend.go @@ -4,4 +4,5 @@ package config type Backend struct { + Enable bool } diff --git a/config/config.go b/config/config.go index e108690..e4f3e85 100644 --- a/config/config.go +++ b/config/config.go @@ -16,17 +16,19 @@ const Application = `Origen` // Config is the configuration of admin-cli. type Config struct { - Application string `json:"application" yaml:"application" toml:"application"` // app_name - PackageName string `json:"package_name" yaml:"package_name" toml:"package_name"` // package_name - Author string `json:"author" yaml:"author" toml:"author"` // author - WirePath string `json:"wire_path" yaml:"wire_path" toml:"wire_path"` // wire_path - SwaggerPath string `json:"swagger_path" yaml:"swagger_path" toml:"swagger_path"` // swagger_path - Fontend Fontend `json:"fontend" yaml:"fontend" toml:"fontend"` // fontend - Backend Backend `json:"backend" yaml:"backend" toml:"backend"` // backend - Database Database `json:"database" yaml:"database" toml:"database"` // database - Extension Extension `json:"extension" yaml:"extension" toml:"extension"` // extension - Description string `json:"description" yaml:"description" toml:"description"` // description - Version string `json:"version" yaml:"version" toml:"version"` // version + Application string + PackageName string + Author string + WirePath string + SwaggerPath string + Description string + Version string + App App `json:"app" yaml:"app" toml:"app"` // app + Fontend Fontend `json:"fontend" yaml:"fontend" toml:"fontend"` // fontend + Backend Backend `json:"backend" yaml:"backend" toml:"backend"` // backend + Database Database `json:"database" yaml:"database" toml:"database"` // database + Extension Extension `json:"extension" yaml:"extension" toml:"extension"` // extension + Services map[string]Service `json:"services" yaml:"services" toml:"services"` // services } // Save saves config to file diff --git a/config/config_test.go b/config/config_test.go new file mode 100644 index 0000000..0cff078 --- /dev/null +++ b/config/config_test.go @@ -0,0 +1,46 @@ +// Copyright (c) 2024 OrigAdmin. All rights reserved. + +// Package config is the config package for origen +package config_test + +import ( + "testing" + + "github.com/origadmin/toolkits/codec" + + "github.com/origadmin/origen/config" +) + +func TestC(t *testing.T) { + config := config.Config{ + Application: "Origen", + PackageName: "origen", + Author: "OrigAdmin", + WirePath: "wire", + SwaggerPath: "swag", + Fontend: config.Fontend{ + Enable: false, + }, + Backend: config.Backend{ + Enable: true, + }, + Database: config.Database{ + Enable: false, + }, + Extension: config.Extension{ + Enable: false, + }, + Services: map[string]config.Service{ + "user": { + Enable: true, + }, + }, + Description: "Origen is a CLI scaffolding for quickly setting up a project.", + Version: "v0.0.0", + } + + err := codec.EncodeTOMLFile("config.toml", config) + if err != nil { + t.Fatal(err) + } +} diff --git a/config/extention.go b/config/extention.go index e9fe233..f19fe33 100644 --- a/config/extention.go +++ b/config/extention.go @@ -4,4 +4,5 @@ package config type Extension struct { + Enable bool } diff --git a/config/fontend.go b/config/fontend.go index ac4bb67..afa6a2a 100644 --- a/config/fontend.go +++ b/config/fontend.go @@ -4,4 +4,5 @@ package config type Fontend struct { + Enable bool } diff --git a/config/service.go b/config/service.go new file mode 100644 index 0000000..4ca1671 --- /dev/null +++ b/config/service.go @@ -0,0 +1,5 @@ +package config + +type Service struct { + Enable bool +}