From e8b29d5baa18ca5fe78a31e479fb4b7edf1652fd Mon Sep 17 00:00:00 2001 From: raul Date: Mon, 3 Jun 2024 09:24:18 +0200 Subject: [PATCH] Prepare listening servers --- cmd/httpServer.go | 27 +++++++++++++++++++++++++++ cmd/root.go | 25 +++++++------------------ cmd/server.go | 38 ++++++++++++++++++++++++++++++++++++++ cmd/serverFunc.go | 39 +++++++++++++++++++++++++++++++++++++++ main.go | 4 ++-- 5 files changed, 113 insertions(+), 20 deletions(-) create mode 100644 cmd/httpServer.go create mode 100644 cmd/server.go create mode 100644 cmd/serverFunc.go diff --git a/cmd/httpServer.go b/cmd/httpServer.go new file mode 100644 index 0000000..b6a7440 --- /dev/null +++ b/cmd/httpServer.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/spf13/viper" +) + +var ( + WebPort string = "8080" +) + +func WebServer() { + p := viper.GetString("Server.WebPort") + if p != "" { + WebPort = p + } + gin.SetMode(gin.ReleaseMode) + r := gin.Default() + r.GET("/", getRoot) + r.Run(":" + WebPort) +} + +func getRoot(c *gin.Context) { + c.String(http.StatusOK, "Hello world!\n") +} diff --git a/cmd/root.go b/cmd/root.go index f2a4b00..2475b3d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,11 +1,10 @@ /* -Copyright © 2024 raul - +Copyright © 2024 raul */ + package cmd import ( - "fmt" "os" "github.com/spf13/cobra" @@ -40,16 +39,7 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) - - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.tiamat.yaml)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/tiamat/tiamat.toml)") } // initConfig reads in config file and ENV variables if set. @@ -62,16 +52,15 @@ func initConfig() { home, err := os.UserHomeDir() cobra.CheckErr(err) - // Search config in home directory with name ".tiamat" (without extension). - viper.AddConfigPath(home) - viper.SetConfigType("yaml") - viper.SetConfigName(".tiamat") + // Search config in home directory with name ".tune" (without extension). + viper.AddConfigPath(home + "/.config/tiamat") + viper.SetConfigType("toml") + viper.SetConfigName("tiamat") } viper.AutomaticEnv() // read in environment variables that match // If a config file is found, read it in. if err := viper.ReadInConfig(); err == nil { - fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) } } diff --git a/cmd/server.go b/cmd/server.go new file mode 100644 index 0000000..80a60e4 --- /dev/null +++ b/cmd/server.go @@ -0,0 +1,38 @@ +/* +Copyright © 2024 raul */ + package main import "tiamat/cmd"