Skip to content

Commit ce8a7be

Browse files
committed
fix load from single file
1 parent a23faed commit ce8a7be

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

config.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
package main
22

33
import (
4-
"time"
5-
"github.com/reddec/container"
6-
"github.com/reddec/container/plugin"
7-
"log"
8-
"os"
9-
"github.com/hashicorp/consul/api"
104
"context"
11-
"sync"
12-
"github.com/Pallinder/go-randomdata"
135
"errors"
146
"io/ioutil"
7+
"log"
8+
"os"
9+
"path"
10+
"path/filepath"
1511
"strings"
16-
"gopkg.in/yaml.v2"
12+
"sync"
13+
"time"
14+
15+
"github.com/Pallinder/go-randomdata"
16+
"github.com/hashicorp/consul/api"
17+
"github.com/reddec/container"
18+
"github.com/reddec/container/plugin"
1719
"github.com/reddec/monexec/monexec"
18-
"path"
20+
"gopkg.in/yaml.v2"
1921
)
2022

2123
type Config struct {
22-
Services []monexec.Executable `yaml:"services"`
23-
Critical []string `yaml:"critical,omitempty"`
24-
Consul struct {
24+
Services []monexec.Executable `yaml:"services"`
25+
Critical []string `yaml:"critical,omitempty"`
26+
Consul struct {
2527
URL string `yaml:"url"`
2628
TTL time.Duration `yaml:"ttl"`
2729
AutoDeregistrationTimeout time.Duration `yaml:"timeout"`
2830
Dynamic []string `yaml:"register,omitempty"`
2931
Permanent []string `yaml:"permanent,omitempty"`
30-
} `yaml:"consul"`
31-
Telegram *Telegram `yaml:"telegram,omitempty"`
32+
} `yaml:"consul"`
33+
Telegram *Telegram `yaml:"telegram,omitempty"`
3234
}
3335

3436
func (c *Config) MergeFrom(other *Config) error {
@@ -157,6 +159,7 @@ func LoadConfig(locations ...string) (*Config, error) {
157159
}
158160
files = fs
159161
} else {
162+
location = filepath.Dir(location)
160163
files = []os.FileInfo{stat}
161164
}
162165
for _, info := range files {
@@ -165,7 +168,7 @@ func LoadConfig(locations ...string) (*Config, error) {
165168
if err != nil {
166169
return nil, err
167170
}
168-
var conf Config = DefaultConfig()
171+
var conf = DefaultConfig()
169172
err = yaml.Unmarshal(data, &conf)
170173
if err != nil {
171174
return nil, err

0 commit comments

Comments
 (0)