MCPcopy
hub / github.com/esm-dev/esm.sh / LoadConfig

Function LoadConfig

server/config.go:86–106  ·  view source on GitHub ↗

LoadConfig loads config from the given file. Panic if failed to load.

(filename string)

Source from the content-addressed store, hash-verified

84
85// LoadConfig loads config from the given file. Panic if failed to load.
86func LoadConfig(filename string) (*Config, error) {
87 file, err := os.Open(filename)
88 if err != nil {
89 return nil, fmt.Errorf("fail to read config file: %w", err)
90 }
91 defer file.Close()
92
93 var config Config
94 err = json.NewDecoder(file).Decode(&config)
95 if err != nil {
96 return nil, fmt.Errorf("fail to parse config: %w", err)
97 }
98 if config.WorkDir != "" && !filepath.IsAbs(config.WorkDir) {
99 config.WorkDir, err = filepath.Abs(config.WorkDir)
100 if err != nil {
101 return nil, fmt.Errorf("fail to get absolute path of the work directory: %w", err)
102 }
103 }
104 normalizeConfig(&config)
105 return &config, nil
106}
107
108func DefaultConfig() *Config {
109 config := &Config{}

Callers 1

StartFunction · 0.85

Calls 2

normalizeConfigFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected