Merge pull request #2631 from kobergj/go-embed

Go embed
This commit is contained in:
kobergj
2021-10-20 11:31:31 +02:00
committed by GitHub
36 changed files with 173 additions and 3818 deletions
+8
View File
@@ -0,0 +1,8 @@
package idp
import (
"embed"
)
//go:embed assets/*
var Assets embed.FS
-61
View File
@@ -1,61 +0,0 @@
package assets
import (
"net/http"
"os"
"path"
"github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
)
//go:generate make -C ../.. 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
@@ -1,9 +0,0 @@
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
@@ -1,20 +0,0 @@
---
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"
...
+10
View File
@@ -1,10 +1,20 @@
package assets
import (
"net/http"
"github.com/owncloud/ocis/idp"
"github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/assetsfs"
"github.com/owncloud/ocis/ocis-pkg/log"
)
// New returns a new http filesystem to serve assets.
func New(opts ...Option) http.FileSystem {
options := newOptions(opts...)
return assetsfs.New(idp.Assets, options.Config.Asset.Path, options.Logger)
}
// Option defines a single option function.
type Option func(o *Options)