From c2369cca8af5a18b8b724fb5fdb7c21fd2aaa04c Mon Sep 17 00:00:00 2001 From: Darko Luketic Date: Mon, 19 Aug 2024 13:54:46 +0200 Subject: [PATCH] config --- cmd/root.go | 14 -------------- cmd/serve.go | 37 +++++++++++++++++++++++++++++++++++++ configuration/app.go | 6 ++++++ configuration/mail.go | 8 ++++++++ go.mod | 2 ++ go.sum | 5 +++++ service/account.go | 1 + service/email.go | 1 + 8 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 cmd/serve.go create mode 100644 configuration/app.go create mode 100644 configuration/mail.go create mode 100644 service/account.go create mode 100644 service/email.go diff --git a/cmd/root.go b/cmd/root.go index 30cadc7..d33c78e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,7 +1,3 @@ -/* -Copyright © 2024 Darko Luketic - -*/ package cmd import ( @@ -10,18 +6,10 @@ import ( "github.com/spf13/cobra" ) - - // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "accountserver", Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, // Uncomment the following line if your bare application // has an action associated with it: // Run: func(cmd *cobra.Command, args []string) { }, @@ -47,5 +35,3 @@ func init() { // when this action is called directly. rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } - - diff --git a/cmd/serve.go b/cmd/serve.go new file mode 100644 index 0000000..8490fee --- /dev/null +++ b/cmd/serve.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "code.icod.de/auth/accountserver/configuration" + "github.com/spf13/cobra" +) + +// serveCmd represents the serve command +var serveCmd = &cobra.Command{ + Use: "serve", + Short: "Run the account server", + RunE: func(cmd *cobra.Command, args []string) error { + return nil + }, +} + +func init() { + rootCmd.AddCommand(serveCmd) + + // Here you will define your flags and configuration settings. + + serveCmd.Flags().BoolVar(&configuration.RunHTTP, "http", true, "Run http server") + serveCmd.Flags().BoolVar(&configuration.RunGRPC, "grpc", true, "Run grpc server") + + serveCmd.Flags().StringVar(&configuration.SMTPHost, "smtp-host", "localhost", "SMTP host") + serveCmd.Flags().IntVar(&configuration.SMTPPort, "smtp-port", 587, "SMTP port") + serveCmd.Flags().StringVar(&configuration.SMTPUser, "smtp-user", "", "SMTP user") + serveCmd.Flags().StringVar(&configuration.SMTPPass, "smtp-pass", "", "SMTP password") + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // serveCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // serveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/configuration/app.go b/configuration/app.go new file mode 100644 index 0000000..e2c4da2 --- /dev/null +++ b/configuration/app.go @@ -0,0 +1,6 @@ +package configuration + +var ( + RunHTTP = true + RunGRPC = true +) diff --git a/configuration/mail.go b/configuration/mail.go new file mode 100644 index 0000000..34460ac --- /dev/null +++ b/configuration/mail.go @@ -0,0 +1,8 @@ +package configuration + +var ( + SMTPHost = "smtp.example.com" + SMTPPort = 587 + SMTPUser = "admin" + SMTPPass = "admin" +) diff --git a/go.mod b/go.mod index fa0761c..b2bb87c 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,8 @@ require ( ) require ( + github.com/idc77/gomail v0.0.0-20240819113050-ac97008b42eb // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect ) diff --git a/go.sum b/go.sum index 4a1619b..4a0d9e4 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/idc77/gomail v0.0.0-20240819113050-ac97008b42eb h1:eoCCdEgNvIAO3+sb7drW2gV36JOkILxyJllfEUHoo1A= +github.com/idc77/gomail v0.0.0-20240819113050-ac97008b42eb/go.mod h1:iRMDvqBOUICvDAsSzKcIBfFLghLJ1EeXBe6tH7Mmv6U= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -16,6 +18,9 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk= +gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/mail.v2 v2.3.1/go.mod h1:htwXN1Qh09vZJ1NVKxQqHPBaCBbzKhp5GzuJEA4VJWw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/service/account.go b/service/account.go new file mode 100644 index 0000000..6d43c33 --- /dev/null +++ b/service/account.go @@ -0,0 +1 @@ +package service diff --git a/service/email.go b/service/email.go new file mode 100644 index 0000000..6d43c33 --- /dev/null +++ b/service/email.go @@ -0,0 +1 @@ +package service