first go:embed 1.16 implementation

This commit is contained in:
Florian Schade
2021-04-29 01:25:28 +02:00
parent 7405812ad9
commit 47bd449fac
38 changed files with 153 additions and 3443 deletions

22
accounts/accounts.go Normal file
View File

@@ -0,0 +1,22 @@
package accounts
import (
"embed"
"io/fs"
"net/http"
)
//go:embed assets/*
var assets embed.FS
// Assets FS
var Assets http.FileSystem
func init() {
embedFS, err := fs.Sub(assets, "assets")
if err != nil {
panic(err)
}
Assets = http.FS(embedFS)
}

View File

@@ -29,7 +29,6 @@ require (
github.com/thejerf/suture/v4 v4.0.0
go.opencensus.io v0.23.0
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea
google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.26.0

View File

@@ -1,22 +1,15 @@
package assets
import (
"github.com/owncloud/ocis/accounts"
"net/http"
"os"
"path"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
// 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"
)
//go:generate make -C ../.. embed.yml
// assets gets initialized by New and provides the handler.
type assets struct {
logger log.Logger
@@ -48,12 +41,7 @@ func (a assets) Open(original string) (http.File, error) {
}
}
return FS.OpenFile(
CTX,
original,
os.O_RDONLY,
0644,
)
return accounts.Assets.Open(original)
}
// New returns a new http filesystem to serve assets.

File diff suppressed because one or more lines are too long

View File

@@ -1,17 +0,0 @@
---
pkg: "assets"
dest: "."
output: "embed.go"
fmt: true
noprefix: true
compression:
compress: true
custom:
- files:
- "../../assets/"
base: "../../assets/"
prefix: ""
...

View File

@@ -1,6 +1,6 @@
module github.com/owncloud/ocis/graph-explorer
go 1.13
go 1.16
require (
contrib.go.opencensus.io/exporter/jaeger v0.2.1
@@ -16,7 +16,6 @@ require (
github.com/spf13/viper v1.7.1
github.com/thejerf/suture/v4 v4.0.0
go.opencensus.io v0.23.0
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
)
replace (

View File

@@ -346,7 +346,6 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/structs v1.0.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=

View File

@@ -0,0 +1,22 @@
package graph_explorer
import (
"embed"
"io/fs"
"net/http"
)
//go:embed assets/*
var assets embed.FS
// Assets FS
var Assets http.FileSystem
func init() {
embedFS, err := fs.Sub(assets, "assets")
if err != nil {
panic(err)
}
Assets = http.FS(embedFS)
}

View File

@@ -1,15 +1,12 @@
package assets
import (
"net/http"
"os"
graph_explorer "github.com/owncloud/ocis/graph-explorer"
"github.com/owncloud/ocis/graph-explorer/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"net/http"
)
//go:generate make -C ../.. embed.yml
// assets gets initialized by New and provides the handler.
type assets struct {
logger log.Logger
@@ -18,12 +15,7 @@ type assets struct {
// Open just implements the HTTP filesystem interface.
func (a assets) Open(original string) (http.File, error) {
return FS.OpenFile(
CTX,
original,
os.O_RDONLY,
0644,
)
return graph_explorer.Assets.Open(original)
}
// New returns a new http filesystem to serve assets.

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

View File

@@ -1,16 +0,0 @@
---
pkg: "assets"
dest: "."
output: "embed.go"
fmt: true
noprefix: true
compression:
compress: true
custom:
- files:
- "../../assets/"
base: "../../assets/"
prefix: ""
...

View File

@@ -20,7 +20,6 @@ require (
github.com/spf13/viper v1.7.1
github.com/thejerf/suture/v4 v4.0.0
go.opencensus.io v0.23.0
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
stash.kopano.io/kc/konnect v0.33.3
stash.kopano.io/kgol/rndm v1.1.0
)

22
idp/idp.go Normal file
View File

@@ -0,0 +1,22 @@
package idp
import (
"embed"
"io/fs"
"net/http"
)
//go:embed assets/*
var assets embed.FS
// Assets FS
var Assets http.FileSystem
func init() {
embedFS, err := fs.Sub(assets, "assets")
if err != nil {
panic(err)
}
Assets = http.FS(embedFS)
}

View File

@@ -1,6 +1,7 @@
package assets
import (
"github.com/owncloud/ocis/idp"
"net/http"
"os"
"path"
@@ -9,8 +10,6 @@ import (
"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
@@ -42,12 +41,7 @@ func (a assets) Open(original string) (http.File, error) {
}
}
return FS.OpenFile(
CTX,
original,
os.O_RDONLY,
0644,
)
return idp.Assets.Open(original)
}
// New returns a new http filesystem to serve assets.

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

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"
...

View File

@@ -8,9 +8,11 @@ require (
contrib.go.opencensus.io/exporter/zipkin v0.1.2
github.com/asim/go-micro/plugins/logger/zerolog/v3 v3.0.0-20210217182006-0f0ace1a44a9
github.com/asim/go-micro/v3 v3.5.1-0.20210217182006-0f0ace1a44a9
github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d // indirect
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/micro/cli/v2 v2.1.2
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/olekukonko/tablewriter v0.0.5
@@ -33,6 +35,7 @@ require (
github.com/rs/zerolog v1.21.0
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/thejerf/suture/v4 v4.0.0
go.opencensus.io v0.23.0
honnef.co/go/tools v0.0.1-2020.1.5 // indirect

View File

@@ -1718,9 +1718,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181003184128-c57b0facaced/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=

View File

@@ -22,14 +22,14 @@ require (
github.com/owncloud/ocis/proxy v0.0.0-20210412105747-9b95e9b1191b
github.com/owncloud/ocis/settings v0.0.0-20210413063522-955bd60edf33
github.com/owncloud/ocis/store v0.0.0-20210413063522-955bd60edf33
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.10.0
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/thejerf/suture/v4 v4.0.0
go.opencensus.io v0.23.0
google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea
google.golang.org/grpc v1.37.0 // indirect
google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.26.0
)

View File

@@ -15,7 +15,6 @@ require (
github.com/spf13/viper v1.7.1
github.com/thejerf/suture/v4 v4.0.0
go.opencensus.io v0.23.0
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
)
replace (

22
onlyoffice/onlyoffice.go Normal file
View File

@@ -0,0 +1,22 @@
package onlyoffice
import (
"embed"
"io/fs"
"net/http"
)
//go:embed assets/*
var assets embed.FS
// Assets FS
var Assets http.FileSystem
func init() {
embedFS, err := fs.Sub(assets, "assets")
if err != nil {
panic(err)
}
Assets = http.FS(embedFS)
}

View File

@@ -1,6 +1,7 @@
package assets
import (
"github.com/owncloud/ocis/onlyoffice"
"net/http"
"os"
"path"
@@ -9,8 +10,6 @@ import (
"github.com/owncloud/ocis/onlyoffice/pkg/config"
)
//go:generate make -C ../.. embed.yml
// assets gets initialized by New and provides the handler.
type assets struct {
logger log.Logger
@@ -42,12 +41,7 @@ func (a assets) Open(original string) (http.File, error) {
}
}
return FS.OpenFile(
CTX,
original,
os.O_RDONLY,
0644,
)
return onlyoffice.Assets.Open(original)
}
// New returns a new http filesystem to serve assets.

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"
)

View File

@@ -1,173 +0,0 @@
// Code generated by fileb0x at "2021-03-25 14:27:31.932190269 +0100 CET m=+0.008272608" from config file "embed.yml" DO NOT EDIT.
// modification hash(68316e8085d7d3372b3644eba5397ee6.8058aec596c5fb73022d09bb97af796e)
package assets
import (
"bytes"
"compress/gzip"
"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
}
// FileOnlyofficeJs is "onlyoffice.js"
var FileOnlyofficeJs = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x90\xc1\x4a\x33\x31\x14\x46\xf7\xff\x53\x94\xd0\xc5\x0c\xa4\xed\x3e\xa5\xbf\x8b\x82\xd0\x85\x56\x44\x57\x22\x76\x4c\xbe\xd8\x60\xe6\xde\x30\xc9\x38\x53\x42\xde\x5d\x50\xda\xea\xc2\x7d\x77\x39\x10\x2e\xe7\x7c\x06\xd6\x11\xaa\xca\xf6\xa4\x93\x63\xaa\xea\x2c\xfa\x88\x49\x4c\x9d\xd3\x49\x2c\x3b\xa4\xbe\xa3\xdc\x84\xb0\x21\xcb\x2a\x53\xd3\x42\x89\x2d\xf9\xc3\xd6\x5a\xa7\x21\xa4\x33\x4a\x30\xf9\x03\x1f\x59\x33\x29\x31\xce\xbe\x79\x66\x58\xf7\x2d\x28\x09\x89\x31\x81\xa2\x63\x8a\xea\x29\x9f\x40\x09\xc3\x7a\x14\x72\xdf\x90\xf1\xe8\xd4\x49\xe4\xfc\x65\xcd\x64\xdd\x9b\x82\xb4\xce\xe3\xae\x49\x7b\x45\x5f\xcf\x8d\x51\x5c\xea\x3c\x38\x32\x3c\xcc\x39\x80\xaa\xdd\x34\x63\x1e\xd1\x7d\xa0\x2b\x8b\x26\x84\xb8\x38\xab\x2d\xa6\x99\xcb\xd5\xf1\xc6\x6a\x9a\x41\x9a\x0d\x1e\xef\x37\x6b\x6e\x03\x13\x28\x55\x54\x97\x9d\x14\x2f\xaf\xbe\xa1\x77\x51\x17\x49\x18\xae\x9d\xc7\x0d\xa8\x57\xb9\x05\xf5\x0f\x2e\x79\x28\xac\xfe\xa3\x12\xb7\x18\x26\xe7\x25\x26\xa7\xd2\xfa\xcf\x0d\x4a\x91\x3f\xcb\x47\x1f\x2f\xb5\xfc\xb7\x68\x08\xe9\x62\x45\x9f\x4b\x29\x75\xbd\xfc\xf7\x19\x00\x00\xff\xff\xf5\x4b\xd1\x2b\xca\x02\x00\x00")
func init() {
err := CTX.Err()
if err != nil {
panic(err)
}
var f webdav.File
var rb *bytes.Reader
var r *gzip.Reader
rb = bytes.NewReader(FileOnlyofficeJs)
r, err = gzip.NewReader(rb)
if err != nil {
panic(err)
}
err = r.Close()
if err != nil {
panic(err)
}
f, err = FS.OpenFile(CTX, "onlyoffice.js", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
if err != nil {
panic(err)
}
_, err = io.Copy(f, r)
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
}

View File

@@ -1,17 +0,0 @@
---
pkg: "assets"
dest: "."
output: "embed.go"
fmt: true
noprefix: true
compression:
compress: true
custom:
- files:
- "../../assets/"
base: "../../assets/"
prefix: ""
...

View File

@@ -23,7 +23,6 @@ require (
github.com/stretchr/testify v1.7.0
github.com/thejerf/suture/v4 v4.0.0
go.opencensus.io v0.23.0
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea
google.golang.org/protobuf v1.26.0
gotest.tools v2.2.0+incompatible

View File

@@ -1,22 +1,15 @@
package assets
import (
"github.com/owncloud/ocis/settings"
"net/http"
"os"
"path/filepath"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/settings/pkg/config"
// 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"
)
//go:generate make -C ../.. embed.yml
// assets gets initialized by New and provides the handler.
type assets struct {
logger log.Logger
@@ -48,12 +41,7 @@ func (a assets) Open(original string) (http.File, error) {
}
}
return FS.OpenFile(
CTX,
original,
os.O_RDONLY,
0644,
)
return settings.Assets.Open(original)
}
// New returns a new http filesystem to serve assets.

File diff suppressed because one or more lines are too long

View File

@@ -1,17 +0,0 @@
---
pkg: "assets"
dest: "."
output: "embed.go"
fmt: true
noprefix: true
compression:
compress: true
custom:
- files:
- "../../assets/"
base: "../../assets/"
prefix: ""
...

22
settings/settings.go Normal file
View File

@@ -0,0 +1,22 @@
package settings
import (
"embed"
"io/fs"
"net/http"
)
//go:embed assets/*
var assets embed.FS
// Assets FS
var Assets http.FileSystem
func init() {
embedFS, err := fs.Sub(assets, "assets")
if err != nil {
panic(err)
}
Assets = http.FS(embedFS)
}

View File

@@ -15,7 +15,6 @@ require (
github.com/spf13/viper v1.7.1
github.com/thejerf/suture/v4 v4.0.0
go.opencensus.io v0.23.0
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
)
replace (

View File

@@ -1,6 +1,7 @@
package assets
import (
"github.com/owncloud/ocis/web"
"net/http"
"os"
"path"
@@ -9,8 +10,6 @@ import (
"github.com/owncloud/ocis/web/pkg/config"
)
//go:generate make -C ../.. embed.yml
// assets gets initialized by New and provides the handler.
type assets struct {
logger log.Logger
@@ -42,12 +41,7 @@ func (a assets) Open(original string) (http.File, error) {
}
}
return FS.OpenFile(
CTX,
original,
os.O_RDONLY,
0644,
)
return web.Assets.Open(original)
}
// New returns a new http filesystem to serve assets.

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

View File

@@ -1,23 +0,0 @@
---
pkg: "assets"
dest: "."
output: "embed.go"
fmt: true
noprefix: true
compression:
compress: true
custom:
- files:
- "../../assets/"
base: "../../assets/"
prefix: ""
exclude:
- "appinfo/**"
- "LICENSE/**"
- "CHANGELOG.md"
- "README.md"
- "config.json"
...

23
web/web.go Normal file
View File

@@ -0,0 +1,23 @@
package web
import (
"embed"
"io/fs"
"net/http"
)
//go:embed assets/*
//go:embed assets/js/*
var assets embed.FS
// Assets FS
var Assets http.FileSystem
func init() {
embedFS, err := fs.Sub(assets, "assets")
if err != nil {
panic(err)
}
Assets = http.FS(embedFS)
}