rename ConfigConfigure.Check to ConfigConfigure.Validate

update sample in README.md
This commit is contained in:
2025-02-03 12:34:58 +08:00
parent c61fa68041
commit 9073d9d901
3 changed files with 14 additions and 7 deletions

View File

@@ -10,6 +10,9 @@ go get gitea.v39.writerpass.top/Public/json-configure-golang
package main package main
import "log" import "log"
import "os"
import "gitea.v39.writerpass.top/Public/json-configure-golang/config"
type AppConfig struct { type AppConfig struct {
AppName string `json:"app_name"` AppName string `json:"app_name"`
@@ -17,12 +20,14 @@ type AppConfig struct {
} }
func main() { func main() {
os.Setenv("DEBUG", "true")
configure := AppConfig{ configure := AppConfig{
AppName: "aaaaa", AppName: "aaaaa",
} }
cc := ConfigConfigure{ cc := config.ConfigConfigure{
AppName: "json-configure", AppName: "json-configure",
ContainerType: BesidesExe, ContainerType: config.BesidesExe,
ConfigureFile: "config.json", ConfigureFile: "config.json",
} }
cc.Check() cc.Check()

View File

@@ -15,19 +15,21 @@ type ConfigConfigure struct {
ConfigureFile string ConfigureFile string
} }
func (receiver *ConfigConfigure) Check() { func (receiver *ConfigConfigure) Validate() {
if receiver.ContainerType == None { if receiver.ContainerType == None {
log.Fatal("Check, ContainerType should not be None or Empty ") log.Fatal("Validate, ContainerType should not be None or Empty")
} else if receiver.ContainerType == BesidesExe { } else if receiver.ContainerType == BesidesExe {
// pass // pass
} else if receiver.ContainerType == UserConfig { } else if receiver.ContainerType == UserConfig {
if receiver.AppName == "" { if receiver.AppName == "" {
log.Fatal("Check, AppName should not be None while ContainerType == UserConfig") log.Fatal("Validate, AppName should not be None while ContainerType == UserConfig")
} }
} else if receiver.ContainerType == SystemConfig { } else if receiver.ContainerType == SystemConfig {
if receiver.AppName == "" { if receiver.AppName == "" {
log.Fatal("Check, AppName should not be None while ContainerType == SystemConfig\nBesides SystemConfig is not supported for now") log.Fatal("Validate, AppName should not be None while ContainerType == SystemConfig\nBesides SystemConfig is not supported for now")
} }
} else {
log.Fatalf("Validate, ContainerType should not be %s \n", receiver.ContainerType)
} }
} }

View File

@@ -19,7 +19,7 @@ func main() {
ContainerType: config.BesidesExe, ContainerType: config.BesidesExe,
ConfigureFile: "config.json", ConfigureFile: "config.json",
} }
cc.Check() cc.Validate()
cc.MakeupContainerPath() cc.MakeupContainerPath()
log.Println("Configure Container Path:", cc.ContainerPath) log.Println("Configure Container Path:", cc.ContainerPath)
cc.EnsureContainer() cc.EnsureContainer()