Add 'konnectd/' from commit '3829df495cbcad9bb261518b4afb7d15ba53d54c'

git-subtree-dir: konnectd
git-subtree-mainline: ab1e6d4689
git-subtree-split: 3829df495c
This commit is contained in:
A.Unger
2020-09-18 13:00:53 +02:00
115 changed files with 6955 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
package assets
import (
"net/http"
"os"
"path"
"github.com/owncloud/ocis-konnectd/pkg/config"
"github.com/owncloud/ocis-pkg/v2/log"
)
//go:generate go run github.com/UnnoTed/fileb0x embed.yml
// assets gets initialized by New and provides the handler.
type assets struct {
logger log.Logger
config *config.Config
}
// Open just implements the HTTP filesystem interface.
func (a assets) Open(original string) (http.File, error) {
if a.config.Asset.Path != "" {
if stat, err := os.Stat(a.config.Asset.Path); err == nil && stat.IsDir() {
custom := path.Join(
a.config.Asset.Path,
original,
)
if _, err := os.Stat(custom); !os.IsNotExist(err) {
f, err := os.Open(custom)
if err != nil {
return nil, err
}
return f, nil
}
} else {
a.logger.Warn().
Str("path", a.config.Asset.Path).
Msg("Assets directory doesn't exist")
}
}
return FS.OpenFile(
CTX,
original,
os.O_RDONLY,
0644,
)
}
// New returns a new http filesystem to serve assets.
func New(opts ...Option) http.FileSystem {
options := newOptions(opts...)
return assets{
logger: options.Logger,
config: options.Config,
}
}
+9
View File
@@ -0,0 +1,9 @@
package assets
import (
// Fake the import to make the dep tree happy.
_ "golang.org/x/net/context"
// Fake the import to make the dep tree happy.
_ "golang.org/x/net/webdav"
)
File diff suppressed because one or more lines are too long
+20
View File
@@ -0,0 +1,20 @@
---
pkg: "assets"
dest: "."
output: "embed.go"
fmt: true
noprefix: true
compression:
compress: true
custom:
- files:
- "../../assets/"
base: "../../assets/"
prefix: ""
exclude:
- "asset-manifest.json"
- "precache-manifest.*.js"
...
+40
View File
@@ -0,0 +1,40 @@
package assets
import (
"github.com/owncloud/ocis-konnectd/pkg/config"
"github.com/owncloud/ocis-pkg/v2/log"
)
// Option defines a single option function.
type Option func(o *Options)
// Options defines the available options for this package.
type Options struct {
Logger log.Logger
Config *config.Config
}
// newOptions initializes the available default options.
func newOptions(opts ...Option) Options {
opt := Options{}
for _, o := range opts {
o(&opt)
}
return opt
}
// Logger provides a function to set the logger option.
func Logger(val log.Logger) Option {
return func(o *Options) {
o.Logger = val
}
}
// Config provides a function to set the config option.
func Config(val *config.Config) Option {
return func(o *Options) {
o.Config = val
}
}