Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove system services and deprecated service sdk #1361

Merged
merged 4 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 13 additions & 27 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"sync"
"time"

"github.com/kelseyhightower/envconfig"
Expand All @@ -25,11 +24,6 @@ const (
processDBVersion = "v2"
)

var (
_instance *Config
once sync.Once
)

// Config contains all the configuration needed.
type Config struct {
Name string
Expand Down Expand Up @@ -58,8 +52,6 @@ type Config struct {
}

Cosmos CosmosConfig

SystemServices []*ServiceConfig
}

// CosmosConfig is the struct to hold cosmos related configs.
Expand All @@ -78,7 +70,7 @@ type CosmosConfig struct {
}

// New creates a new config with default values.
func New() (*Config, error) {
func Default() (*Config, error) {
home, err := homedir.Dir()
if err != nil {
return nil, err
Expand All @@ -102,31 +94,25 @@ func New() (*Config, error) {
c.Tendermint.Config.P2P.AllowDuplicateIP = true
c.Tendermint.Config.Consensus.TimeoutCommit = 10 * time.Second

return &c, c.setupServices()
return &c, nil
}

// Global returns a singleton of a Config after loaded ENV and validate the values.
func Global() (*Config, error) {
var err error
once.Do(func() {
_instance, err = New()
if err != nil {
return
}
if err = _instance.Load(); err != nil {
return
}
if err = _instance.Prepare(); err != nil {
return
}
})
// New returns a Config after loaded ENV and validate the values.
func New() (*Config, error) {
c, err := Default()
if err != nil {
return nil, err
}
if err := _instance.Validate(); err != nil {
if err := c.Load(); err != nil {
return nil, err
}
if err := c.Prepare(); err != nil {
return nil, err
}
if err := c.Validate(); err != nil {
return nil, err
}
return _instance, nil
return c, nil
}

// Load reads config from environmental variables.
Expand Down
14 changes: 7 additions & 7 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestDefaultValue(t *testing.T) {
home, _ := homedir.Dir()
c, err := New()
c, err := Default()
require.NoError(t, err)
require.Equal(t, ":50052", c.Server.Address)
require.Equal(t, "text", c.Log.Format)
Expand All @@ -24,8 +24,8 @@ func TestDefaultValue(t *testing.T) {
require.Equal(t, "engine", c.Name)
}

func TestGlobal(t *testing.T) {
c, err := Global()
func TestNew(t *testing.T) {
c, err := New()
require.NoError(t, err)
require.NotNil(t, c)
}
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestLoad(t *testing.T) {
os.Setenv("MESG_TENDERMINT_P2P_PERSISTENTPEERS", "localhost")
os.Setenv("MESG_COSMOS_VALIDATORPUBKEY", "0000000000000000000000000000000000000000000000000000000000000001")

c, _ := New()
c, _ := Default()
c.Load()
require.Equal(t, "test_server_address", c.Server.Address)
require.Equal(t, "test_log_format", c.Log.Format)
Expand All @@ -66,14 +66,14 @@ func TestLoad(t *testing.T) {
}

func TestValidate(t *testing.T) {
c, _ := New()
c, _ := Default()
require.NoError(t, c.Validate())

c, _ = New()
c, _ = Default()
c.Log.Format = "wrongValue"
require.Error(t, c.Validate())

c, _ = New()
c, _ = Default()
c.Log.Level = "wrongValue"
require.Error(t, c.Validate())
}
70 changes: 0 additions & 70 deletions config/services.go

This file was deleted.

Loading