forked from roobre/mastodon-api-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (40 loc) · 811 Bytes
/
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
package main
import (
"log/slog"
"net/http"
"os"
"time"
"roob.re/mastodon-api-proxy/proxy"
)
func main() {
log := slog.Default()
opts := proxy.Options{
Logger: log,
}
minAgeStr := os.Getenv("MIN_AGE")
if minAgeStr != "" {
minAge, err := time.ParseDuration(minAgeStr)
if err != nil {
log.With("MIN_AGE", minAgeStr).Error("parsing MIN_AGE")
return
}
log.With("minAge", minAge).Info("Restricting account age")
opts.MinAge = minAge
}
proxy, err := proxy.New(
os.Getenv("BACKEND_URL"),
os.Getenv("DOMAIN"),
opts,
)
if err != nil {
log.Error("building proxy", "error", err)
return
}
const addr = ":8080"
log.Info("Starting server", "address", addr)
err = http.ListenAndServe(addr, proxy)
if err != nil {
log.Error("running server", "error", err)
return
}
}