You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wireguird/static/ab0x.go

160 lines
229 KiB

// Code generated by fileb0x at "2023-10-01 00:24:10.779914994 +0200 CEST m=+0.007497526" from config file "fileb0x.toml" DO NOT EDIT.
// modification hash(2708cdf7520cea1555d9794eb83c02ff.370050f9606640156d65adf676074775)
4 years ago
package static
import (
"bytes"
"context"
"io"
"net/http"
"os"
"path"
"golang.org/x/net/webdav"
)
var (
// CTX is a context for webdav vfs
CTX = context.Background()
// FS is a virtual memory file system
FS = webdav.NewMemFS()
// Handler is used to server files through a http handler
Handler *webdav.Handler
// HTTP is the http file system
HTTP http.FileSystem = new(HTTPFS)
)
// HTTPFS implements http.FileSystem
type HTTPFS struct {
// Prefix allows to limit the path of all requests. F.e. a prefix "css" would allow only calls to /css/*
Prefix string
}
// FileWireguirdGlade is "wireguird.glade"
var FileWireguirdGlade = []byte("\x3c\x3f\x78\x6d\x6c\x20\x76\x65\x72\x73\x69\x6f\x6e\x3d\x22\x31\x2e\x30\x22\x20\x65\x6e\x63\x6f\x64\x69\x6e\x67\x3d\x22\x55\x54\x46\x2d\x38\x22\x3f\x3e\x0a\x3c\x21\x2d\x2d\x20\x47\x65\x6e\x65\x72\x61\x74\x65\x64\x20\x77\x69\x74\x68\x20\x67\x6c\x61\x64\x65\x20\x33\x2e\x34\x30\x2e\x30\x20\x2d\x2d\x3e\x0a\x3c\x69\x6e\x74\x65\x72\x66\x61\x63\x65\x3e\x0a\x20\x20\x3c\x72\x65\x71\x75\x69\x72\x65\x73\x20\x6c\x69\x62\x3d\x22\x67\x74\x6b\x2b\x22\x20\x76\x65\x72\x73\x69\x6f\x6e\x3d\x22\x33\x2e\x32\x32\x22\x2f\x3e\x0a\x20\x20\x3c\x6f\x62\x6a\x65\x63\x74\x20\x63\x6c\x61\x73\x73\x3d\x22\x47\x74\x6b\x57\x69\x6e\x64\x6f\x77\x22\x20\x69\x64\x3d\x22\x65\x64\x69\x74\x6f\x72\x5f\x77\x69\x6e\x64\x6f\x77\x22\x3e\x0a\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x63\x61\x6e\x2d\x66\x6f\x63\x75\x73\x22\x3e\x46\x61\x6c\x73\x65\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x64\x65\x66\x61\x75\x6c\x74\x2d\x77\x69\x64\x74\x68\x22\x3e\x34\x38\x30\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x64\x65\x66\x61\x75\x6c\x74\x2d\x68\x65\x69\x67\x68\x74\x22\x3e\x33\x34\x30\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x3c\x63\x68\x69\x6c\x64\x3e\x0a\x20\x20\x20\x20\x20\x20\x3c\x6f\x62\x6a\x65\x63\x74\x20\x63\x6c\x61\x73\x73\x3d\x22\x47\x74\x6b\x42\x6f\x78\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x76\x69\x73\x69\x62\x6c\x65\x22\x3e\x54\x72\x75\x65\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x63\x61\x6e\x2d\x66\x6f\x63\x75\x73\x22\x3e\x46\x61\x6c\x73\x65\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x6d\x61\x72\x67\x69\x6e\x2d\x6c\x65\x66\x74\x22\x3e\x38\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x6d\x61\x72\x67\x69\x6e\x2d\x72\x69\x67\x68\x74\x22\x3e\x38\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x6d\x61\x72\x67\x69\x6e\x2d\x74\x6f\x70\x22\x3e\x38\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x6d\x61\x72\x67\x69\x6e\x2d\x62\x6f\x74\x74\x6f\x6d\x22\x3e\x38\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x6f\x72\x69\x65\x6e\x74\x61\x74\x69\x6f\x6e\x22\x3e\x76\x65\x72\x74\x69\x63\x61\x6c\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x73\x70\x61\x63\x69\x6e\x67\x22\x3e\x34\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x63\x68\x69\x6c\x64\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x21\x2d\x2d\x20\x6e\x2d\x63\x6f\x6c\x75\x6d\x6e\x73\x3d\x33\x20\x6e\x2d\x72\x6f\x77\x73\x3d\x33\x20\x2d\x2d\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x6f\x62\x6a\x65\x63\x74\x20\x63\x6c\x61\x73\x73\x3d\x22\x47\x74\x6b\x47\x72\x69\x64\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x76\x69\x73\x69\x62\x6c\x65\x22\x3e\x54\x72\x75\x65\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x63\x61\x6e\x2d\x66\x6f\x63\x75\x73\x22\x3e\x46\x61\x6c\x73\x65\x3c\x2f\x70\x72\x6f\x70\x65\x72\x74\x79\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x72\x6f\x70\x65\x72\x74\x79\x20\x6e\x61\x6d\x65\x3d\x22\x72\x6f\x77\x2d\x73\x70\x61\x63\x69\x6e\x67\x22\x3e\x36\x
4 years ago
func init() {
err := CTX.Err()
if err != nil {
panic(err)
}
var f webdav.File
f, err = FS.OpenFile(CTX, "wireguird.glade", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
if err != nil {
panic(err)
}
_, err = f.Write(FileWireguirdGlade)
if err != nil {
panic(err)
}
err = f.Close()
if err != nil {
panic(err)
}
Handler = &webdav.Handler{
FileSystem: FS,
LockSystem: webdav.NewMemLS(),
}
}
// Open a file
func (hfs *HTTPFS) Open(path string) (http.File, error) {
path = hfs.Prefix + path
f, err := FS.OpenFile(CTX, path, os.O_RDONLY, 0644)
if err != nil {
return nil, err
}
return f, nil
}
// ReadFile is adapTed from ioutil
func ReadFile(path string) ([]byte, error) {
f, err := FS.OpenFile(CTX, path, os.O_RDONLY, 0644)
if err != nil {
return nil, err
}
buf := bytes.NewBuffer(make([]byte, 0, bytes.MinRead))
// If the buffer overflows, we will get bytes.ErrTooLarge.
// Return that as an error. Any other panic remains.
defer func() {
e := recover()
if e == nil {
return
}
if panicErr, ok := e.(error); ok && panicErr == bytes.ErrTooLarge {
err = panicErr
} else {
panic(e)
}
}()
_, err = buf.ReadFrom(f)
return buf.Bytes(), err
}
// WriteFile is adapTed from ioutil
func WriteFile(filename string, data []byte, perm os.FileMode) error {
f, err := FS.OpenFile(CTX, filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
if err != nil {
return err
}
n, err := f.Write(data)
if err == nil && n < len(data) {
err = io.ErrShortWrite
}
if err1 := f.Close(); err == nil {
err = err1
}
return err
}
// WalkDirs looks for files in the given dir and returns a list of files in it
// usage for all files in the b0x: WalkDirs("", false)
func WalkDirs(name string, includeDirsInList bool, files ...string) ([]string, error) {
f, err := FS.OpenFile(CTX, name, os.O_RDONLY, 0)
if err != nil {
return nil, err
}
fileInfos, err := f.Readdir(0)
if err != nil {
return nil, err
}
err = f.Close()
if err != nil {
return nil, err
}
for _, info := range fileInfos {
filename := path.Join(name, info.Name())
if includeDirsInList || !info.IsDir() {
files = append(files, filename)
}
if info.IsDir() {
files, err = WalkDirs(filename, includeDirsInList, files...)
if err != nil {
return nil, err
}
}
}
return files, nil
}