mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
Some of the files were quite big:
- asns.csv ~ 3 MB
- index.js ~ 1.5 MB
- *.svg ~ 2 MB
Use a ZIP archive to put them all and embed it. This reduce the binary
size from 89 MB to 82 MB. 🤯
This also pulls some code modernization (use of http.ServeFileFS).
42 lines
794 B
Go
42 lines
794 B
Go
// SPDX-FileCopyrightText: 2025 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
// Package embed provides access to the compressed archive containing all the
|
|
// embedded files.
|
|
package embed
|
|
|
|
import (
|
|
"archive/zip"
|
|
"bytes"
|
|
_ "embed"
|
|
"fmt"
|
|
"io/fs"
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
//go:embed data/embed.zip
|
|
embeddedZip []byte
|
|
data fs.FS
|
|
dataOnce sync.Once
|
|
dataReady chan struct{}
|
|
)
|
|
|
|
// Data returns a filesystem with the files contained in the embedded archive.
|
|
func Data() fs.FS {
|
|
dataOnce.Do(func() {
|
|
r, err := zip.NewReader(bytes.NewReader(embeddedZip), int64(len(embeddedZip)))
|
|
if err != nil {
|
|
panic(fmt.Sprintf("cannot read embedded archive: %s", err))
|
|
}
|
|
data = r
|
|
close(dataReady)
|
|
})
|
|
<-dataReady
|
|
return data
|
|
}
|
|
|
|
func init() {
|
|
dataReady = make(chan struct{})
|
|
}
|