Skip to content

Commit

Permalink
update service config
Browse files Browse the repository at this point in the history
  • Loading branch information
antho1404 committed Feb 3, 2019
1 parent 493a949 commit 470a753
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
28 changes: 2 additions & 26 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ var (
once sync.Once
)

// ServiceConfig contains information related to services that the config knows about
type ServiceConfig struct {
URL string
Env map[string]string
Sid string
Hash string
}

// ServiceConfigWithKey contains information related to services that the config knows about and their key
type ServiceConfigWithKey struct {
*ServiceConfig
Key string
}

// Config contains all the configuration needed.
type Config struct {
Server struct {
Expand Down Expand Up @@ -63,17 +49,7 @@ type Config struct {
}
}

// You can add any attribute that will be a `ServiceConfig` type
// example: `Foo ServiceConfig`
// You can then access it with config.Service.Foo.Sid in order to access the Sid of this service.
// The services in this struct are automatically started when Core starts based on the URL and Env.
// Sid and Hash are populated only after the deployment.
// You need to initialize these services in the `New` function
// example: `c.Service.Foo = ServiceConfig{URL: "https://api.github.com/repos/mesg-foundation/service-ethereum-erc20/tarball/master"}`
// Also add it in the `Services()` function
// example: `[]*ServiceConfigWithKey{{&c.Service.Foo, "Foo"}}`
Service struct {
}
Service ServiceConfigGroup

Docker struct {
Socket string
Expand Down Expand Up @@ -103,7 +79,7 @@ func New() (*Config, error) {
c.Core.Database.ExecutionRelativePath = filepath.Join("database", "executions")
c.Docker.Core.Path = "/mesg"
c.Docker.Socket = "/var/run/docker.sock"
c.initServices()
c.Service = c.getServiceConfigGroup()
return &c, nil
}

Expand Down
37 changes: 32 additions & 5 deletions config/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,42 @@ package config
// The service name should be the name of the directory inside `systemservices` but capitalized
// example:
// var (
// FooURL string
// BarURL string
// )
var ()
var (
EthwalletURL string
)

func (c *Config) initServices() {
// ServiceConfig contains information related to services that the config knows about
type ServiceConfig struct {
URL string
Env map[string]string
Sid string
Hash string
}

// ServiceConfigWithKey contains information related to services that the config knows about and their key
type ServiceConfigWithKey struct {
*ServiceConfig
Key string
}

// ServiceConfigGroup is the struct that contains all the `ServiceConfig` related to the config
type ServiceConfigGroup struct {
Ethwallet ServiceConfig
}

// getServiceConfigGroup return the config for all services.
// DO NOT USE STRING HERE but variable defined on top of this file `XxxURL` for config injection
func (c *Config) getServiceConfigGroup() ServiceConfigGroup {
return ServiceConfigGroup{
Ethwallet: ServiceConfig{URL: EthwalletURL},
}
}

// Services returns all services that the configuration package is aware of
func (c *Config) Services() []ServiceConfig {
return []ServiceConfig{}
func (c *Config) Services() []*ServiceConfigWithKey {
return []*ServiceConfigWithKey{
{&c.Service.Ethwallet, "Ethwallet"},
}
}

0 comments on commit 470a753

Please sign in to comment.