-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
67 lines (53 loc) · 2.16 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2024 Outreach Corporation. All Rights Reserved.
// Description: This file is the focal point of configuration that needs passed
// to various parts of the service.
// Managed: true
package vcluster_fs_syncer //nolint:revive // Why: We allow [-_].
import (
"context"
"github.com/getoutreach/gobox/pkg/cfg"
"github.com/getoutreach/gobox/pkg/log"
// <<Stencil::Block(configImports)>>
// <</Stencil::Block>>
)
// Config tracks config needed for vcluster-fs-syncer
type Config struct {
ListenHost string `yaml:"ListenHost"`
HTTPPort int `yaml:"HTTPPort"`
// <<Stencil::Block(config)>>
FromPath string `yaml:"fromPath"`
ToPath string `yaml:"toPath"`
// <</Stencil::Block>>
}
// MarshalLog can be used to write config to log
func (c *Config) MarshalLog(addfield func(key string, value interface{})) {
// <<Stencil::Block(marshalconfig)>>
// <</Stencil::Block>>
}
// LoadConfig returns a new Config type that has been loaded in accordance to the environment
// that the service was deployed in, with all necessary tweaks made before returning.
// nolint: funlen // Why: This function is long for extensibility reasons since it is generated by stencil.
func LoadConfig(ctx context.Context) (*Config, error) {
// NOTE: Defaults should generally be set in the config
// override jsonnet file: deployments/vcluster-fs-syncer/vcluster-fs-syncer.config.jsonnet
c := Config{
// Defaults to [::]/0.0.0.0 which will broadcast to all reachable
// IPs on a server on the given port for the respective service.
ListenHost: "",
HTTPPort: 8000,
/// !!! DEPRECATED: This block is deprecated and will be removed in an upcoming release.
/// All configuration should be defined in deployments/vcluster-fs-syncer/vcluster-fs-syncer.config.jsonnet.
///
// <<Stencil::Block(defconfig)>>
// <</Stencil::Block>>
}
// Attempt to load a local config file on top of the defaults
if err := cfg.Load("vcluster-fs-syncer.yaml", &c); err != nil {
return nil, err
}
// Do any necessary tweaks/augmentations to your configuration here
// <<Stencil::Block(configtweak)>>
// <</Stencil::Block>>
log.Info(ctx, "Configuration data of the application:\n", &c)
return &c, nil
}