Skip to content

Commit

Permalink
change app config from slice to map
Browse files Browse the repository at this point in the history
  • Loading branch information
Kifen committed Jan 6, 2020
1 parent 7650c1c commit 3f6e9d5
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 218 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/google/uuid v1.1.1
github.com/gorilla/handlers v1.4.2
github.com/gorilla/securecookie v1.1.1
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/profile v1.3.0
github.com/prometheus/client_golang v1.2.1
github.com/prometheus/common v0.7.0
Expand Down
6 changes: 3 additions & 3 deletions pkg/visor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func (c *Config) RoutingTable() (routing.Table, error) {
}

// AppsConfig decodes AppsConfig from a local json config file.
func (c *Config) AppsConfig() ([]AppConfig, error) {
apps := make([]AppConfig, 0)
func (c *Config) AppsConfig() (map[string]AppConfig, error) {
apps := make(map[string]AppConfig)
for _, app := range c.Apps {
if app.Version == "" {
app.Version = c.Version
}
apps = append(apps, app)
apps[app.App] = app
}

return apps, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/visor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ func TestAppsConfig(t *testing.T) {
appsConf, err := conf.AppsConfig()
require.NoError(t, err)

app1 := appsConf[0]
app1 := appsConf["foo"]
assert.Equal(t, "foo", app1.App)
assert.Equal(t, "1.1", app1.Version)
assert.Equal(t, routing.Port(1), app1.Port)
assert.False(t, app1.AutoStart)

app2 := appsConf[1]
app2 := appsConf["bar"]
assert.Equal(t, "bar", app2.App)
assert.Equal(t, "1.0", app2.Version)
assert.Equal(t, routing.Port(2), app2.Port)
Expand Down
15 changes: 8 additions & 7 deletions pkg/visor/visor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Node struct {

appsPath string
localPath string
appsConf []AppConfig
appsConf map[string]AppConfig

startedAt time.Time
restartCtx *restart.Context
Expand Down Expand Up @@ -487,11 +487,12 @@ func (node *Node) StopApp(appName string) error {

// SetAutoStart sets an app to auto start or not.
func (node *Node) SetAutoStart(appName string, autoStart bool) error {
for i, ac := range node.appsConf {
if ac.App == appName {
node.appsConf[i].AutoStart = autoStart
return nil
}
appConf, ok := node.appsConf[appName]
if !ok {
return ErrUnknownApp
}
return ErrUnknownApp

appConf.AutoStart = autoStart
node.appsConf[appName] = appConf
return nil
}
21 changes: 0 additions & 21 deletions vendor/github.com/mitchellh/go-homedir/LICENSE

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/github.com/mitchellh/go-homedir/README.md

This file was deleted.

1 change: 0 additions & 1 deletion vendor/github.com/mitchellh/go-homedir/go.mod

This file was deleted.

167 changes: 0 additions & 167 deletions vendor/github.com/mitchellh/go-homedir/homedir.go

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ github.com/mattn/go-isatty
github.com/matttproud/golang_protobuf_extensions/pbutil
# github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
github.com/mgutz/ansi
# github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/go-homedir
# github.com/pkg/profile v1.3.0
github.com/pkg/profile
# github.com/pmezard/go-difflib v1.0.0
Expand Down

0 comments on commit 3f6e9d5

Please sign in to comment.