-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
66 lines (54 loc) · 1.29 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
package main
import (
"errors"
"fmt"
"mnk-rss/lib"
"net/http"
"github.com/ardanlabs/conf/v3"
"github.com/coocood/freecache"
cache "github.com/gitsight/go-echo-cache"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
)
func main() {
e := echo.New()
const prefix = "APP"
cfg := struct {
Address string `conf:"default:0.0.0.0:8010"`
ConfigPath string `conf:"default:/mnk-rss/config.yaml"`
LogLevel log.Lvl `conf:"default:0"`
}{}
help, err := conf.Parse(prefix, &cfg)
if err != nil {
if errors.Is(err, conf.ErrHelpWanted) {
fmt.Println(help)
}
e.Logger.Error(nil)
return
}
c := freecache.NewCache(7 * 1024 * 1024)
e.Use(cache.New(&cache.Config{}, c))
e.Logger.SetLevel(cfg.LogLevel)
e.GET("/*", func(c echo.Context) error {
config, err := lib.ReadConfig(cfg.ConfigPath)
if err != nil {
return err
}
feedConfig, ok := config.Paths[c.Request().URL.Path]
if !ok {
return c.NoContent(http.StatusNotFound)
}
var result string
switch feedConfig.Type {
case "comments":
result, err = lib.HandleComments(c.Request(), config, feedConfig)
default:
result, err = lib.HandleWFS(c.Request(), config, feedConfig)
}
if err != nil {
return err
}
return c.String(http.StatusOK, result)
})
e.Logger.Fatal(e.Start(cfg.Address))
}