36 lines
591 B
Go
36 lines
591 B
Go
package rpirelay
|
|
|
|
import (
|
|
"embed"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/gabriel-vasile/mimetype"
|
|
)
|
|
|
|
//go:embed spec.json
|
|
var spec []byte
|
|
|
|
//go:embed public/*
|
|
var public embed.FS
|
|
|
|
func GetSpec() []byte { return spec }
|
|
|
|
func GetWebFile(fp string) (body []byte, mime string, err error) {
|
|
p := path.Join("public/swagger", fp)
|
|
b, err := public.ReadFile(p)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
|
|
mt := mimetype.Detect(b)
|
|
mime = mt.String()
|
|
if strings.HasSuffix(fp, ".css") {
|
|
mime = "text/css"
|
|
} else if strings.HasSuffix(fp, ".js") {
|
|
mime = "text/javascript"
|
|
}
|
|
|
|
return b, mime, nil
|
|
}
|