all repos — legit @ 8586d930a3f4a8235d6383e90bbcd22762060126

web frontend for git, written in go

config: Ensure we always have an absolute path

Having this consistent across the code is handy when we're building
paths, counting separators and other path manipulation.
Daniele Sluijters daenney@users.noreply.github.com
Tue, 03 Jan 2023 14:35:36 +0100
commit

8586d930a3f4a8235d6383e90bbcd22762060126

parent

1e7b63814fc003577e14356c79793cc827661270

1 files changed, 11 insertions(+), 0 deletions(-)

jump to
M config/config.goconfig/config.go

@@ -3,6 +3,7 @@

import ( "fmt" "os" + "path/filepath" "gopkg.in/yaml.v3" )

@@ -38,6 +39,16 @@

c := Config{} if err := yaml.Unmarshal(b, &c); err != nil { return nil, fmt.Errorf("parsing config: %w", err) + } + + if c.Repo.ScanPath, err = filepath.Abs(c.Repo.ScanPath); err != nil { + return nil, err + } + if c.Dirs.Templates, err = filepath.Abs(c.Dirs.Templates); err != nil { + return nil, err + } + if c.Dirs.Static, err = filepath.Abs(c.Dirs.Static); err != nil { + return nil, err } return &c, nil