MCPcopy Index your code
hub / github.com/perkeep/perkeep / loadConfig

Function loadConfig

server/perkeepd/perkeepd.go:139–183  ·  view source on GitHub ↗

loadConfig returns the server's parsed config file, locating it using the provided arg. The arg may be of the form: - empty, to mean automatic (will write a default high-level config if no cloud config is available) - a filepath absolute or relative to the user's configuration directory, - a URL

(arg string)

Source from the content-addressed store, hash-verified

137// - a filepath absolute or relative to the user's configuration directory,
138// - a URL
139func loadConfig(arg string) (*serverinit.Config, error) {
140 if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") {
141 contents, err := slurpURL(arg, 256<<10)
142 if err != nil {
143 return nil, err
144 }
145 return serverinit.Load(contents)
146 }
147 var absPath string
148 switch {
149 case arg == "":
150 absPath = osutil.UserServerConfigPath()
151 _, err := wkfs.Stat(absPath)
152 if err == nil {
153 break
154 }
155 if !os.IsNotExist(err) {
156 return nil, err
157 }
158 conf, err := serverinit.DefaultEnvConfig()
159 if err != nil || conf != nil {
160 return conf, err
161 }
162 configDir, err := osutil.PerkeepConfigDir()
163 if err != nil {
164 return nil, err
165 }
166 if err := wkfs.MkdirAll(configDir, 0700); err != nil {
167 return nil, err
168 }
169 log.Printf("Generating template config file %s", absPath)
170 if err := serverinit.WriteDefaultConfigFile(absPath); err != nil {
171 return nil, err
172 }
173 case filepath.IsAbs(arg):
174 absPath = arg
175 default:
176 configDir, err := osutil.PerkeepConfigDir()
177 if err != nil {
178 return nil, err
179 }
180 absPath = filepath.Join(configDir, arg)
181 }
182 return serverinit.LoadFile(absPath)
183}
184
185// If cert/key files are specified, and found, use them.
186// If cert/key files are specified, not found, and the default values, generate

Callers 1

mainFunction · 0.85

Calls 11

LoadFunction · 0.92
UserServerConfigPathFunction · 0.92
DefaultEnvConfigFunction · 0.92
PerkeepConfigDirFunction · 0.92
WriteDefaultConfigFileFunction · 0.92
LoadFileFunction · 0.92
slurpURLFunction · 0.85
HasPrefixMethod · 0.80
PrintfMethod · 0.80
StatMethod · 0.65
MkdirAllMethod · 0.65

Tested by

no test coverage detected