This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
68 lines (55 loc) · 1.55 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
package main
import (
"github.com/multiplio/cast-render/render"
"io/ioutil"
"log"
env "github.com/Netflix/go-env"
shell "github.com/ipfs/go-ipfs-api"
"github.com/qiangxue/fasthttp-routing"
"github.com/valyala/fasthttp"
)
type environmentDesc struct {
Name string `env:"NAME"`
Address string `env:"ADDRESS"`
DPI int `env:"DPI"`
PostTemplate string `env:"POST_TEMPLATE"`
FontFile string `env:"FONTFILE"`
IPFSAddress string `env:"IPFS_ADDRESS"`
RootURL string `env:"ROOT_URL"`
}
var environment environmentDesc
func main() {
log.SetFlags(0)
// get environment
_, err := env.UnmarshalFromEnviron(&environment)
if err != nil {
log.Fatal(err)
}
log.SetPrefix(environment.Name + ":")
// init renderer
dpi := float64(environment.DPI)
renderer, err := render.InitRenderer(&environment.FontFile, &dpi)
if err != nil {
log.Fatal("Could not init renderer with fontfile", environment.FontFile, ":", err)
return
}
// read post template
postBytes, err := ioutil.ReadFile(environment.PostTemplate)
if err != nil {
log.Fatal("Could not read template", environment.PostTemplate, ":", err)
return
}
post := string(postBytes)
// renderer context struct
renderContext := &renderContext{
renderer: &renderer,
shell: shell.NewShell(environment.IPFSAddress),
postTemplate: &post,
}
// routes
router := routing.New()
setRoutes(router, renderContext)
// start server
log.Println("Serving at ", environment.Address)
log.Fatal(fasthttp.ListenAndServe(environment.Address, router.HandleRequest))
}