Skip to content

Commit

Permalink
add initial code with cobra/viper
Browse files Browse the repository at this point in the history
  • Loading branch information
pog7x committed Jul 16, 2024
1 parent 58aa260 commit 9b45191
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bindir:

.PHONY: build
build: bindir
GOBIN=${BINDIR} go install ./cmd/...
GOBIN=${BINDIR} go install ./main.go

.PHONY: clean
clean:
Expand All @@ -29,7 +29,7 @@ test: golangci

.PHONY: run-dev
run-dev:
go run ./cmd/...
go run ./main.go runworker -c=./internal/app/config/.config.dev.yml

.PHONY: run-server
run-server: all
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@
## Golang RMQ asynchronous worker template

### Technologies used:

- App build: [spf13/cobra](https://github.com/spf13/cobra)
- Env: [pf13/viper](https://github.com/spf13/viper)
- Logger: [zap](https://github.com/uber-go/zap)
- RMQ: [streadway/amqp](https://github.com/streadway/amqp), [ThreeDotsLabs/watermill](https://github.com/ThreeDotsLabs/watermill)
- Metrics: [prometheus/client_golang](https://github.com/prometheus/client_golang), [TheZeroSlave/zapsentry](https://github.com/TheZeroSlave/zapsentry)
- Linter: [golangci/golangci-lint](https://github.com/golangci/golangci-lint)
- Tests: [stretchr/testify](https://github.com/stretchr/testify)

### Run dev with docker-compose

```bash
docker-compose -f docker-compose.dev.yml up -d
docker-compose -f docker-compose.dev.yml up -d
```

### Run tests

```bash
./scripts/test.sh
```

### RMQ worker with using [spf13/cobra](https://github.com/spf13/cobra) + [pf13/viper](https://github.com/spf13/viper) tools [](https://github.com/pog7x/go-rmq-worker-tmpl/tree/master-cobra)
### RMQ worker with using [spf13/cobra](https://github.com/spf13/cobra) + [pf13/viper](https://github.com/spf13/viper) tools [](https://github.com/pog7x/go-rmq-worker-tmpl/tree/master-cobra)
60 changes: 60 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package cmd

import (
"fmt"
"os"

"github.com/mitchellh/mapstructure"
"github.com/pog7x/go-rmq-worker-tmpl/internal/app/config"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var cfgFile string

var rootCmd = &cobra.Command{
Use: "root",
Short: "go-rmq-worker-tmpl",
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}

func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "path to config file")

rootCmd.AddCommand(runWorkerCmd)
}

func initConfig() {
v := viper.New()
if cfgFile != "" {
v.SetConfigFile(cfgFile)

if err := v.ReadInConfig(); err != nil {
panic(fmt.Errorf("reading config %s error: %w", v.ConfigFileUsed(), err))
}
}

v.AutomaticEnv()

envKeysMap := map[string]interface{}{}
if err := mapstructure.Decode(*config.Configuration, &envKeysMap); err != nil {
panic(fmt.Errorf("decoding config to mapstructure error: %w", err))
}

for k := range envKeysMap {
if bindErr := v.BindEnv(k); bindErr != nil {
panic(fmt.Errorf("binding viper env variable '%s' error: %w", k, bindErr))
}
}

if err := v.Unmarshal(config.Configuration); err != nil {
panic(fmt.Errorf("decoding env configuration error: %w", err))
}
}
20 changes: 11 additions & 9 deletions cmd/go-rmq-worker-tmpl/main.go → cmd/runworker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cmd

import (
"context"
Expand All @@ -12,17 +12,19 @@ import (
"github.com/pog7x/go-rmq-worker-tmpl/internal/app/config"
"github.com/pog7x/go-rmq-worker-tmpl/internal/app/logger"

"github.com/kelseyhightower/envconfig"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

func main() {
var cfg config.Config
if err := envconfig.Process("", &cfg); err != nil {
log.Printf("Parsing config error: %v\nexiting...", err)
os.Exit(1)
}
var runWorkerCmd = &cobra.Command{
Use: "runworker",
Short: "Launching and serving RMQ worker",
Run: func(cmd *cobra.Command, args []string) {
runworker(context.Background(), config.Configuration)
},
}

func runworker(ctx context.Context, cfg *config.Config) {
appLogger, err := logger.ConfigureLogger(cfg.LogLevel, cfg.SentryDSN)
if err != nil {
log.Printf("Configuring logger error: %v\nexiting...", err)
Expand All @@ -31,7 +33,7 @@ func main() {

appLogger.Sugar().Infof("Application config: %+v", cfg)

application, err := app.NewApp(appLogger, &cfg)
application, err := app.NewApp(appLogger, cfg)
if err != nil {
appLogger.Error("Failed initialize application", zap.Error(err))
os.Exit(1)
Expand Down
11 changes: 0 additions & 11 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ services:
- custom
ports:
- 8080:8080
environment:
- RMQ_USER=pog7x
- RMQ_PASSWORD=pass
- RMQ_HOST=rmq
- RMQ_PORT=5672

- RMQ_VHOST=/

- RMQ_EXCHANGE=pog7x.go-rmq-worker-tmpl.exchange
- RMQ_QUEUE=pog7x.go-rmq-worker-tmpl.queue
- RMQ_ROUTING_KEY=pog7x.go-rmq-worker-tmpl.key

rmq:
image: rabbitmq:3.11-management-alpine
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ services:
- RMQ_EXCHANGE=pog7x.go-rmq-worker-tmpl.exchange
- RMQ_QUEUE=pog7x.go-rmq-worker-tmpl.queue
- RMQ_ROUTING_KEY=pog7x.go-rmq-worker-tmpl.key
- RMQ_QOS_PREFETCH_COUNT=1

- SERVER_LISTEN_ADDR=0.0.0.0:8080
- SERVER_READ_TIMEOUT=3s
- SERVER_WRITE_TIMEOUT=3s
- LOG_LEVEL=debug

- MAX_RETRIES=5
- RETRIES_INTERVAL=3s

rmq:
image: rabbitmq:3.11-management-alpine
environment:
- RABBITMQ_DEFAULT_USER=pog7x
- RABBITMQ_DEFAULT_PASS=pass
ports:
- 35672:15672
- 25672:5672
healthcheck:
test: [ "CMD", "nc", "-z", "localhost", "5672" ]
interval: 10s
Expand Down
15 changes: 14 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ require (
github.com/garsue/watermillzap v1.1.1
github.com/go-resty/resty/v2 v2.7.0
github.com/hashicorp/go-multierror v1.1.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/mitchellh/mapstructure v1.1.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.3.2
github.com/streadway/amqp v1.0.0
github.com/stretchr/testify v1.8.1
go.uber.org/zap v1.24.0
Expand All @@ -22,21 +24,32 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/getsentry/sentry-go v0.12.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lithammer/shortuuid/v3 v3.0.7 // indirect
github.com/magiconair/properties v1.8.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
17 changes: 15 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
Expand Down Expand Up @@ -90,6 +91,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/garsue/watermillzap v1.1.1 h1:qReFh5goSOoub8x0cc+iSaaeIMJF0m66nmdesqG7VBg=
github.com/garsue/watermillzap v1.1.1/go.mod h1:6wdF9VgwK7JMANUtlpUUfNwkrFRWQ4G+U/dgBcWpvTA=
Expand Down Expand Up @@ -193,10 +195,12 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
Expand All @@ -220,8 +224,6 @@ github.com/kataras/iris/v12 v12.1.8/go.mod h1:LMYy4VlP67TQ3Zgriz8RE2h2kMZV2SgMYb
github.com/kataras/neffos v0.0.14/go.mod h1:8lqADm8PnbeFfL7CLXh1WHw53dG27MC3pgi2R1rmoTE=
github.com/kataras/pio v0.0.2/go.mod h1:hAoW0t9UmXi4R5Oyq5Z4irTbaTsOemSrDGUtaTl7Dro=
github.com/kataras/sitemap v0.0.5/go.mod h1:KY2eugMKiPwsJgx7+U103YZehfvNGOXURubcGyk0Bz8=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
Expand All @@ -240,6 +242,7 @@ github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL
github.com/lithammer/shortuuid/v3 v3.0.4/go.mod h1:RviRjexKqIzx/7r1peoAITm6m7gnif/h+0zmolKJjzw=
github.com/lithammer/shortuuid/v3 v3.0.7 h1:trX0KTHy4Pbwo/6ia8fscyHoGA+mf1jWbPJVuvyJQQ8=
github.com/lithammer/shortuuid/v3 v3.0.7/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand All @@ -255,6 +258,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand All @@ -273,6 +277,7 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
Expand Down Expand Up @@ -319,11 +324,17 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
Expand Down Expand Up @@ -532,6 +543,7 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -681,6 +693,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
19 changes: 19 additions & 0 deletions internal/app/config/.config.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
RMQ_USER: pog7x
RMQ_PASSWORD: pass
RMQ_HOST: rmq
RMQ_PORT: 5672

RMQ_VHOST: /

RMQ_EXCHANGE: pog7x.go-rmq-worker-tmpl.exchange
RMQ_QUEUE: pog7x.go-rmq-worker-tmpl.queue
RMQ_ROUTING_KEY: pog7x.go-rmq-worker-tmpl.key
RMQ_QOS_PREFETCH_COUNT: 1

SERVER_LISTEN_ADDR: 0.0.0.0:8080
SERVER_READ_TIMEOUT: 3s
SERVER_WRITE_TIMEOUT: 3s
LOG_LEVEL: debug

MAX_RETRIES: 5
RETRIES_INTERVAL: 3s
34 changes: 18 additions & 16 deletions internal/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ package config
import "time"

type Config struct {
ServerListenAddr string `envconfig:"SERVER_LISTEN_ADDR" default:"0.0.0.0:8080"`
ServerReadTimeout time.Duration `envconfig:"SERVER_READ_TIMEOUT" default:"3s"`
ServerWriteTimeout time.Duration `envconfig:"SERVER_WRITE_TIMEOUT" default:"3s"`
LogLevel string `envconfig:"LOG_LEVEL" default:"debug"`
SentryDSN string `envconfig:"SENTRY_DSN"`
ServerListenAddr string `mapstructure:"SERVER_LISTEN_ADDR"`
ServerReadTimeout time.Duration `mapstructure:"SERVER_READ_TIMEOUT"`
ServerWriteTimeout time.Duration `mapstructure:"SERVER_WRITE_TIMEOUT"`
LogLevel string `mapstructure:"LOG_LEVEL"`
SentryDSN string `mapstructure:"SENTRY_DSN"`

MaxRetries int `envconfig:"MAX_RETRIES" default:"5"`
RetriesInterval time.Duration `envconfig:"RETRIES_INTERVAL" default:"3s"`
MaxRetries int `mapstructure:"MAX_RETRIES"`
RetriesInterval time.Duration `mapstructure:"RETRIES_INTERVAL"`

RMQUser string `envconfig:"RMQ_USER" required:"true"`
RMQPassword string `envconfig:"RMQ_PASSWORD" required:"true"`
RMQHost string `envconfig:"RMQ_HOST" required:"true"`
RMQPort int `envconfig:"RMQ_PORT" required:"true"`
RMQQosPrefetchCount int `envconfig:"RMQ_QOS_PREFETCH_COUNT" default:"1"`
RMQUser string `mapstructure:"RMQ_USER"`
RMQPassword string `mapstructure:"RMQ_PASSWORD"`
RMQHost string `mapstructure:"RMQ_HOST"`
RMQPort int `mapstructure:"RMQ_PORT"`
RMQQosPrefetchCount int `mapstructure:"RMQ_QOS_PREFETCH_COUNT"`

RMQVHost string `envconfig:"RMQ_VHOST" required:"true"`
RMQVHost string `mapstructure:"RMQ_VHOST"`

RMQExchange string `envconfig:"RMQ_EXCHANGE" required:"true"`
RMQQueue string `envconfig:"RMQ_QUEUE" required:"true"`
RMQRoutingKey string `envconfig:"RMQ_ROUTING_KEY" required:"true"`
RMQExchange string `mapstructure:"RMQ_EXCHANGE"`
RMQQueue string `mapstructure:"RMQ_QUEUE"`
RMQRoutingKey string `mapstructure:"RMQ_ROUTING_KEY"`
}

var Configuration = new(Config)
Loading

0 comments on commit 9b45191

Please sign in to comment.