forked from lmika/oaipmh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
64 lines (50 loc) · 1.22 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
package main
import (
"log"
"os"
"os/user"
"path/filepath"
"code.google.com/p/gcfg"
)
// The provider struct
type Provider struct {
// The provider URL
Url string
// The default set
Set string
}
// Baseline configuration
type Config struct {
// Provider aliases
Provider map[string]*Provider
}
// Looks up a provider. If one is not defined, creates a dummy provider.
func (cfg *Config) LookupProvider(endpoint string) *Provider {
if endpoint == "" {
return nil
}
if prov, hasProv := cfg.Provider[endpoint] ; hasProv {
return prov
} else {
return &Provider{ Url: endpoint }
}
}
func ReadConfig() *Config {
c := &Config{
Provider: make(map[string]*Provider),
}
u, err := user.Current()
if (err != nil) {
log.Println("Error trying to get local user. Using default config. Error = %s\n", err.Error())
return c
}
// Read the home config file
homeConfig := filepath.Join(u.HomeDir, ".oaipmh.cfg")
if _, err := os.Stat(homeConfig) ; err == nil {
err := gcfg.ReadFileInto(c, homeConfig)
if (err != nil) {
panic(err)
}
}
return c;
}