-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (61 loc) · 1.5 KB
/
main.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
68
69
package main
import (
"fmt"
"os"
"runtime"
"github.com/bakkerme/metacomposite/v2/api"
"github.com/bakkerme/metacomposite/v2/env"
"github.com/bakkerme/metacomposite/v2/reddit"
"github.com/bakkerme/metacomposite/v2/rss"
"github.com/kelseyhightower/envconfig"
"github.com/labstack/echo/v4"
)
func main() {
var spec env.Specification
err := envconfig.Process("mt", &spec)
if err != nil {
panic(err.Error())
}
configPath := ""
if spec.Environment == env.Production {
currOS := runtime.GOOS
if currOS == "windows" {
appdataPath := os.Getenv("appdata")
configPath = appdataPath + "/Metacomposite/config.json"
} else if currOS == "linux" {
homepath := os.Getenv("HOME")
configPath = homepath + "/.config/metacomposite/config.json"
} else {
panic(fmt.Sprintf("OS %s not yet supported", currOS))
}
} else if spec.Environment == env.Local {
configPath = "./api/config.json"
}
cfgProvider := api.FileConfigProvider{}
cfg, err := cfgProvider.LoadConfig(configPath)
if err != nil {
panic(err)
}
cfg.Credentials = []api.Credentials{
{
Type: "reddit",
Values: map[string]string{
"ID": spec.RedditId,
"Secret": spec.RedditSecret,
},
},
}
mAPI := api.API{
CFG: cfg,
Loaders: api.Loaders{
RSS: rss.Load{},
Reddit: reddit.Load{
ID: spec.RedditId,
Secret: spec.RedditSecret,
},
},
}
e := echo.New()
api.RegisterHandlers(e, &mAPI)
e.Logger.Fatal(e.Start(":3030"))
}