MCPcopy Index your code
hub / github.com/writefreely/writefreely / Load

Function Load

config/config.go:269–301  ·  view source on GitHub ↗

Load reads the given configuration file, then parses and returns it as a Config.

(fname string)

Source from the content-addressed store, hash-verified

267
268// Load reads the given configuration file, then parses and returns it as a Config.
269func Load(fname string) (*Config, error) {
270 if fname == "" {
271 fname = FileName
272 }
273 cfg, err := ini.Load(fname)
274 if err != nil {
275 return nil, err
276 }
277
278 // Parse INI file
279 uc := &Config{}
280 err = cfg.MapTo(uc)
281 if err != nil {
282 return nil, err
283 }
284
285 // Do any transformations
286 u, err := url.Parse(uc.App.Host)
287 if err != nil {
288 return nil, err
289 }
290 d, err := idna.ToASCII(u.Hostname())
291 if err != nil {
292 log.Error("idna.ToASCII for %s: %s", u.Hostname(), err)
293 return nil, err
294 }
295 uc.App.Host = u.Scheme + "://" + d
296 if u.Port() != "" {
297 uc.App.Host += ":" + u.Port()
298 }
299
300 return uc, nil
301}
302
303// Save writes the given Config to the given file.
304func Save(uc *Config, fname string) error {

Callers 2

LoadConfigMethod · 0.92
ConfigureFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected