From 7ff4cac4fc23060a56b9c33a3453c2d26629b699 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Tue, 11 Jun 2024 20:59:02 +0200 Subject: feat: Add server listen configuration --- pkg/config/config.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'pkg/config') diff --git a/pkg/config/config.go b/pkg/config/config.go index 3e539f7..0e85b5a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -32,6 +32,7 @@ type ( configuration struct { Scan *scan RootReadme string + ListenAddr string Repositories []*GitRepositoryConfiguration } @@ -49,6 +50,7 @@ type ( // information. ConfigurationRepository struct { rootReadme string + listenAddr string repositories []*GitRepositoryConfiguration } ) @@ -66,6 +68,7 @@ func LoadConfigurationRepository(configPath string) (*ConfigurationRepository, e repo := &ConfigurationRepository{ rootReadme: config.RootReadme, + listenAddr: config.ListenAddr, repositories: config.Repositories, } @@ -85,6 +88,10 @@ func (c *ConfigurationRepository) GetRootReadme() string { return c.rootReadme } +func (c *ConfigurationRepository) GetListenAddr() string { + return c.listenAddr +} + // GetByName returns configuration of repository for a given name. // It returns nil if there is not match for it. func (c *ConfigurationRepository) GetByName(name string) *GitRepositoryConfiguration { @@ -157,6 +164,11 @@ func parse(r io.Reader) (*configuration, error) { return nil, err } + err = setListenAddr(block, &config.ListenAddr) + if err != nil { + return nil, err + } + err = setRepositories(block, &config.Repositories) if err != nil { return nil, err @@ -215,6 +227,7 @@ func defaultConfiguration() *configuration { return &configuration{ Scan: defaultScan(), RootReadme: "", + ListenAddr: "http//0.0.0.0:8080", Repositories: make([]*GitRepositoryConfiguration, 0), } } @@ -241,6 +254,11 @@ func setRootReadme(block scfg.Block, readme *string) error { return setString(scanDir, readme) } +func setListenAddr(block scfg.Block, listenAddr *string) error { + scanDir := block.Get("listen-addr") + return setString(scanDir, listenAddr) +} + func setScan(block scfg.Block, scan *scan) error { scanDir := block.Get("scan") if scanDir == nil { -- cgit v1.2.3