-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (47 loc) · 1.17 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
package main
import (
_ "embed"
"log"
"net/http"
"os"
"os/signal"
"text/template"
)
var (
HOST = os.Getenv("RAILWAY_STATIC_URL")
PORT = os.Getenv("GLEAN_PORT")
PATH = os.Getenv("GLEAN_PATH")
PASS = os.Getenv("GLEAN_PASS")
TITLE = os.Getenv("GLEAN_TITLE")
AUTHOR = os.Getenv("GLEAN_AUTHOR")
EMAIL = os.Getenv("GLEAN_EMAIL")
//go:embed tmpl/index.html
INDEX_HTML string
INDEX_TMPL = template.Must(template.New("index").Parse(INDEX_HTML))
//go:embed tmpl/post.html
POST_HTML string
POST_TMPL = template.Must(template.New("post").Parse(POST_HTML))
)
func serve(ch chan error) {
log.Printf("starting HTTP server on port %s\n", PORT)
http.HandleFunc("/", SendIndex)
http.HandleFunc("/new", TakePost)
http.HandleFunc("/posts/", SendPost)
http.HandleFunc("/rss", SendFeed)
ch <- http.ListenAndServe(":"+PORT, nil)
}
func main() {
serveErrs := make(chan error)
go serve(serveErrs)
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
for {
select {
case err := <-serveErrs:
log.Fatalf("error in server: %s\n", err.Error())
case sig := <-signals:
log.Printf("received %s signal, shutting down...\n", sig.String())
os.Exit(0)
}
}
}