From bd529e7b53c7d47fc63d7c167ae18579b132c6a6 Mon Sep 17 00:00:00 2001 From: 1998-felix Date: Fri, 26 Apr 2024 12:21:47 +0300 Subject: [PATCH] refactor: Remove .env file Signed-off-by: 1998-felix --- .env | 9 --------- .gitignore | 12 +++++++++++- Makefile | 1 - README.md | 2 -- cmd/main.go | 15 +++++---------- configs.go | 26 -------------------------- go.mod | 2 -- go.sum | 4 ---- 8 files changed, 16 insertions(+), 55 deletions(-) delete mode 100644 .env delete mode 100644 configs.go diff --git a/.env b/.env deleted file mode 100644 index 0f3ef84..0000000 --- a/.env +++ /dev/null @@ -1,9 +0,0 @@ -COAP_CLI_HOST=localhost -COAP_CLI_PORT=5683 -COAP_CLI_CONTENT_FORMAT=50 -COAP_CLI_AUTH= -COAP_CLI_OBSERVE= -COAP_CLI_CERT_FILE= -COAP_CLI_KEY_FILE= -COAP_CLI_SERVER_CA_FILE= -COAP_CLI_CLIENT_CA_FILE= diff --git a/.gitignore b/.gitignore index 8781a80..dc8e95b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,15 @@ # Copyright (c) Abstract Machines # SPDX-License-Identifier: Apache-2.0 -# build dirs +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test build +# Output of the go coverage tool, specifically when used with LiteIDE +*.out diff --git a/Makefile b/Makefile index d10cea8..b99296f 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,3 @@ all: CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -o build/coap-cli-linux cmd/main.go CGO_ENABLED=0 GOOS=darwin go build -ldflags "-s -w" -o build/coap-cli-darwin cmd/main.go CGO_ENABLED=0 GOOS=windows go build -ldflags "-s -w" -o build/coap-cli-windows cmd/main.go - \ No newline at end of file diff --git a/README.md b/README.md index ddaf088..0ea03c6 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,6 @@ When running, please provide following format: | d | data to be sent in POST or PUT | "" | | cf | content format | 50 (JSON format) | -The default values are as set in the [.env](.env) file. Modify them as required. - ## Examples: ```bash diff --git a/cmd/main.go b/cmd/main.go index 58f58b7..80f5b34 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -12,7 +12,6 @@ import ( "strings" "syscall" - cli "github.com/mainflux/coap-cli" coap "github.com/mainflux/coap-cli/coap" coapmsg "github.com/plgd-dev/go-coap/v3/message" "github.com/plgd-dev/go-coap/v3/message/codes" @@ -36,10 +35,6 @@ func printMsg(m *pool.Message) { } func main() { - config, err := cli.LoadConfig() - if err != nil { - log.Fatalf("Error loading config: %v", err) - } var rootCmd = &cobra.Command{ Use: "coap-cli [options]", @@ -56,7 +51,7 @@ func main() { return }, } - getCmd.Flags().BoolVarP(&observe, "observe", "o", config.Observe, "Observe resource") + getCmd.Flags().BoolVarP(&observe, "observe", "o", false, "Observe resource") getCmd.Example = `coap-cli get channels/0bb5ba61-a66e-4972-bab6-26f19962678f/messages/subtopic -a 1e1017e6-dee7-45b4-8a13-00e6afeb66eb \n coap-cli get channels/0bb5ba61-a66e-4972-bab6-26f19962678f/messages/subtopic --auth 1e1017e6-dee7-45b4-8a13-00e6afeb66eb -o ` @@ -98,10 +93,10 @@ func main() { deleteCmd.Flags().StringVarP(&data, "data", "d", "", "Data") rootCmd.AddCommand(getCmd, putCmd, postCmd, deleteCmd) - rootCmd.PersistentFlags().StringVarP(&host, "host", "H", config.Host, "Host") - rootCmd.PersistentFlags().StringVarP(&port, "port", "p", config.Port, "Port") - rootCmd.PersistentFlags().StringVarP(&auth, "auth", "a", config.Auth, "Auth") - rootCmd.PersistentFlags().IntVarP(&contentFormat, "content-format", "c", config.ContentFormat, "Content format") + rootCmd.PersistentFlags().StringVarP(&host, "host", "H", "localhost", "Host") + rootCmd.PersistentFlags().StringVarP(&port, "port", "p", "5683", "Port") + rootCmd.PersistentFlags().StringVarP(&auth, "auth", "a", "", "Auth") + rootCmd.PersistentFlags().IntVarP(&contentFormat, "content-format", "c", 50, "Content format") if err := rootCmd.Execute(); err != nil { log.Fatalf("Error executing command: %v", err) diff --git a/configs.go b/configs.go deleted file mode 100644 index 7f71bf6..0000000 --- a/configs.go +++ /dev/null @@ -1,26 +0,0 @@ -package coapcli - -import ( - "github.com/caarlos0/env/v10" - "github.com/joho/godotenv" -) - -type Config struct { - Host string `env:"COAP_CLI_HOST"` - Port string `env:"COAP_CLI_PORT"` - ContentFormat int `env:"COAP_CLI_CONTENT_FORMAT"` - Auth string `env:"COAP_CLI_AUTH"` - Observe bool `env:"COAP_CLI_OBSERVE"` -} - -func LoadConfig() (Config, error) { - c := Config{} - err := godotenv.Load() - if err != nil { - panic(err) - } - if err := env.Parse(&c); err != nil { - return Config{}, err - } - return c, nil -} diff --git a/go.mod b/go.mod index 86d06cf..77cb423 100644 --- a/go.mod +++ b/go.mod @@ -10,11 +10,9 @@ require ( ) require ( - github.com/caarlos0/env/v10 v10.0.0 github.com/dsnet/golib/memfile v1.0.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/joho/godotenv v1.5.1 github.com/pion/dtls/v2 v2.2.8-0.20240201071732-2597464081c8 // indirect github.com/pion/logging v0.2.2 // indirect github.com/pion/transport/v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 289b964..51a969e 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/caarlos0/env/v10 v10.0.0 h1:yIHUBZGsyqCnpTkbjk8asUlx6RFhhEs+h7TOBdgdzXA= -github.com/caarlos0/env/v10 v10.0.0/go.mod h1:ZfulV76NvVPw3tm591U4SwL3Xx9ldzBP9aGxzeN7G18= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -13,8 +11,6 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= -github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/pion/dtls/v2 v2.2.8-0.20240201071732-2597464081c8 h1:r7K+oQUYubeA0am08kTAvd2wT2D8PZggs/CpMGp0nkM= github.com/pion/dtls/v2 v2.2.8-0.20240201071732-2597464081c8/go.mod h1:/gft3czh67pwl4nM1BBUvF7eTy72uGkObJXOYfxRDbA= github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=