From c67da73f30ec57653bc3cb9cf07994f7076af03e Mon Sep 17 00:00:00 2001 From: kingecg Date: Tue, 28 Nov 2023 23:26:58 +0800 Subject: [PATCH] add bannner --- .vscode/launch.json | 7 ++++++- cli/root.go | 31 +++++++++++++++++++++++++------ config.json | 23 +++++++++++++++++++++++ main.go | 14 ++++++++++++++ 4 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 config.json diff --git a/.vscode/launch.json b/.vscode/launch.json index caf17f8..003ae4f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,12 @@ "type": "go", "request": "launch", "mode": "auto", - "program": "${fileDirname}" + "program": "${fileDirname}", + "args": [ + "--config", + "config.json", + "version" + ] }, { "name": "Launch file", diff --git a/cli/root.go b/cli/root.go index c527fbf..e2bc3f4 100644 --- a/cli/root.go +++ b/cli/root.go @@ -4,15 +4,34 @@ import ( "fmt" "os" + "git.pyer.club/kingecg/gologger" + "git.pyer.club/kingecg/gosocketio/config" "github.com/spf13/cobra" ) -var rootCmd = &cobra.Command{ - Use: "gosocketio", - Short: "A golang socket.io server", - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("gossocketio called") - }, +var ( + configFile string + rootCmd = &cobra.Command{ + Use: "gosocketio", + Short: "A golang socket.io server", + Run: func(cmd *cobra.Command, args []string) { + + }, + } +) + +func init() { + cobra.OnInitialize(initConfig) + rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "config file") +} + +func initConfig() { + if configFile != "" { + config.LoadConfig(configFile) + } + gologger.Configure(config.GetConfig().Logging) + logger := gologger.GetLogger("main") + logger.Debug("On init") } // run app cmd diff --git a/config.json b/config.json new file mode 100644 index 0000000..a8058c3 --- /dev/null +++ b/config.json @@ -0,0 +1,23 @@ +{ + "host": "localhost", + "port": 3306, + "logging": { + "appenders": { + "out": { + "type": "console" + }, + "server": { + "type": "file", + "options":{ + "file": "./logs/server.log" + } + } + }, + "categories": { + "default": { + "appenders": ["out","server"], + "level": "debug" + } + } + } +} \ No newline at end of file diff --git a/main.go b/main.go index 8a05103..24d7027 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,23 @@ package main import ( + "fmt" + "git.pyer.club/kingecg/gosocketio/cli" ) +const title string = ` + + ___ __ _ _____ __ + / _ \___ / _\ ___ ___| | _____ \_ \___ / _\ ___ _ ____ _____ _ __ + / /_\/ _ \ \ \ / _ \ / __| |/ / _ \ / /\/ _ \ \ \ / _ \ '__\ \ / / _ \ '__| +/ /_\\ (_) | _\ \ (_) | (__| < __/\/ /_| (_) | _\ \ __/ | \ V / __/ | +\____/\___/ \__/\___/ \___|_|\_\___\____/ \___/ \__/\___|_| \_/ \___|_| + + +` + func main() { + fmt.Print(title) cli.Execute() }