-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (44 loc) · 965 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
49
50
51
package main
import (
"log/slog"
"net/http"
"os"
picocache "picocache/src"
"github.com/docker/go-units"
)
const envSource = "PICOCACHE_SRC"
const envCachedir = "PICOCACHE_DIR"
const envMaxSize = "PICOCACHE_MAXSIZE"
const envListenTo = "PICOCACHE_LISTENTO"
func main() {
source := os.Getenv(envSource)
if source == "" {
panic(envSource + " is empty")
}
cacheDir := os.Getenv(envCachedir)
if cacheDir == "" {
panic(envCachedir + " is empty")
}
maxSize := os.Getenv(envMaxSize)
if maxSize == "" {
panic(envMaxSize + " is empty")
}
listenTo := os.Getenv(envListenTo)
if maxSize == "" {
panic(envListenTo + " is empty")
}
size, err := units.FromHumanSize(maxSize)
if err != nil {
panic("can't parse PICOCACHE_MAXSIZE: " + err.Error())
}
pcache, err := picocache.NewCache(
slog.Default().With(slog.String("ident", "main")),
source,
cacheDir,
size,
)
if err != nil {
panic(err)
}
http.ListenAndServe(listenTo, pcache)
}