Skip to content

Commit

Permalink
Merge pull request #427 from mesg-foundation/feature/better-config
Browse files Browse the repository at this point in the history
Refactor package config
  • Loading branch information
antho1404 authored Sep 11, 2018
2 parents 33fb3a3 + 5f87cde commit 052c4ae
Show file tree
Hide file tree
Showing 155 changed files with 908 additions and 24,283 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- run: docker swarm init
- run: docker pull nginx:stable-alpine
- run: docker pull alpine
- run: env MESG_CORE_IMAGE=mesg/core:$CIRCLE_SHA1 go test -timeout 180s -p 1 -coverprofile=coverage.txt ./...
- run: env MESG_CORE_IMAGE=mesg/core:$CIRCLE_SHA1 go test -ldflags="-X 'github.com/mesg-foundation/core/config.Path=./'" -timeout 180s -p 1 -coverprofile=coverage.txt ./... # TODO: should remove ldflags when package database is mocked
- run: bash <(curl -s https://codecov.io/bash)

"publish_docker_dev":
Expand Down
98 changes: 10 additions & 88 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@
[[constraint]]
name = "github.com/satori/go.uuid"
version = "1.2.0"

[[constraint]]
name = "github.com/kelseyhightower/envconfig"
version = "1.3.0"
5 changes: 3 additions & 2 deletions cmd/service/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"github.com/mesg-foundation/core/config"
"github.com/mesg-foundation/core/interface/grpc/core"
"github.com/mesg-foundation/core/service/importer"
"github.com/spf13/viper"
"google.golang.org/grpc"
)

func cli() core.CoreClient {
connection, err := grpc.Dial(viper.GetString(config.APIClientTarget), grpc.WithInsecure())
c, err := config.Global()
utils.HandleError(err)
connection, err := grpc.Dial(c.Client.Address, grpc.WithInsecure())
utils.HandleError(err)
return core.NewCoreClient(connection)
}
Expand Down
13 changes: 10 additions & 3 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/mesg-foundation/core/daemon"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// Start the MESG Core.
Expand All @@ -28,7 +27,11 @@ func (v *logFormatValue) Set(value string) error {
if value != "text" && value != "json" {
return fmt.Errorf("%s is not valid log format", value)
}
viper.Set(config.LogFormat, value)
c, err := config.Global()
if err != nil {
return err
}
c.Log.Format = value
*v = logFormatValue(value)
return nil
}
Expand All @@ -42,7 +45,11 @@ func (v *logLevelValue) Set(value string) error {
if _, err := logrus.ParseLevel(value); err != nil {
return fmt.Errorf("%s is not valid log level", value)
}
viper.Set(config.LogLevel, value)
c, err := config.Global()
if err != nil {
return err
}
c.Log.Level = value
*v = logLevelValue(value)
return nil
}
Expand Down
14 changes: 8 additions & 6 deletions cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/mesg-foundation/core/interface/grpc/core"
"github.com/mesg-foundation/core/service"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -41,13 +40,16 @@ func stopHandler(cmd *cobra.Command, args []string) {
fmt.Println(aurora.Green("MESG Core stopped"))
}

func getCli() (cli core.CoreClient, err error) {
connection, err := grpc.Dial(viper.GetString(config.APIClientTarget), grpc.WithInsecure())
func getCli() (core.CoreClient, error) {
c, err := config.Global()
if err != nil {
return
return nil, err
}
cli = core.NewCoreClient(connection)
return
connection, err := grpc.Dial(c.Client.Address, grpc.WithInsecure())
if err != nil {
return nil, err
}
return core.NewCoreClient(connection), nil
}

func stopServices() (err error) {
Expand Down
37 changes: 0 additions & 37 deletions config/api.go

This file was deleted.

27 changes: 0 additions & 27 deletions config/api_test.go

This file was deleted.

Loading

0 comments on commit 052c4ae

Please sign in to comment.