mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-09 21:08:11 +02:00
allow pomerium to be embedded as a library (#3415)
This commit is contained in:
parent
6e1ebffc59
commit
d1037d784a
27 changed files with 292 additions and 207 deletions
37
ui/embed_ext.go
Normal file
37
ui/embed_ext.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
//go:build embed_pomerium
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
var (
|
||||
// ExtUIFS must be set to provide access to UI dist/ files
|
||||
ExtUIFS fs.FS
|
||||
)
|
||||
|
||||
func openFile(name string) (f fs.File, etag string, err error) {
|
||||
if ExtUIFS == nil {
|
||||
return nil, "", fmt.Errorf("ui package was incorrectly compiled with embed_pomerium yet no FS was provided")
|
||||
}
|
||||
f, err = ExtUIFS.Open(name)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("open %s: %w", name, err)
|
||||
}
|
||||
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
modTime := fi.ModTime()
|
||||
if modTime.IsZero() {
|
||||
modTime = startTime
|
||||
}
|
||||
etag = fmt.Sprintf("%x", modTime.UnixNano())
|
||||
|
||||
return f, etag, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue