123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- // Code generated by fileb0x at "2022-06-10 22:55:21.84892167 +0300 EEST m=+0.038018428" from config file "b0x.yaml" DO NOT EDIT.
- // modification hash(c06e09df5514d5bdf3c145144658221e.84893f7d7f6af7d7916db9fe20160151)
- package swaggerFiles
- 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
- }
- func init() {
- err := CTX.Err()
- 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
- }
|