From 9073d9d9011566d6421863510c7e978b1bcb2e2b Mon Sep 17 00:00:00 2001 From: WriterPass Date: Mon, 3 Feb 2025 12:34:58 +0800 Subject: [PATCH] rename ConfigConfigure.Check to ConfigConfigure.Validate update sample in README.md --- README.md | 9 +++++++-- config/config-configure.go | 10 ++++++---- main.go | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index dee427c..6d3fca2 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ go get gitea.v39.writerpass.top/Public/json-configure-golang package main import "log" +import "os" +import "gitea.v39.writerpass.top/Public/json-configure-golang/config" + type AppConfig struct { AppName string `json:"app_name"` @@ -17,12 +20,14 @@ type AppConfig struct { } func main() { + os.Setenv("DEBUG", "true") + configure := AppConfig{ AppName: "aaaaa", } - cc := ConfigConfigure{ + cc := config.ConfigConfigure{ AppName: "json-configure", - ContainerType: BesidesExe, + ContainerType: config.BesidesExe, ConfigureFile: "config.json", } cc.Check() diff --git a/config/config-configure.go b/config/config-configure.go index 1b9af48..69ac299 100644 --- a/config/config-configure.go +++ b/config/config-configure.go @@ -15,19 +15,21 @@ type ConfigConfigure struct { ConfigureFile string } -func (receiver *ConfigConfigure) Check() { +func (receiver *ConfigConfigure) Validate() { 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 { // pass } else if receiver.ContainerType == UserConfig { 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 { 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) } } diff --git a/main.go b/main.go index 17fdd00..3397ec0 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ func main() { ContainerType: config.BesidesExe, ConfigureFile: "config.json", } - cc.Check() + cc.Validate() cc.MakeupContainerPath() log.Println("Configure Container Path:", cc.ContainerPath) cc.EnsureContainer()