ui-assets: Integrate UI assets.

master
Harshavardhana 9 years ago
parent 53a983659e
commit a066184bed
  1. 3
      .gitignore
  2. 10
      Makefile
  3. 6
      appveyor.yml
  4. 4
      routers.go
  5. 2
      vendor/github.com/elazarl/go-bindata-assetfs/README.md
  6. 25
      vendor/github.com/elazarl/go-bindata-assetfs/assetfs.go
  7. 4
      vendor/vendor.json

3
.gitignore vendored

@ -9,4 +9,5 @@ site/
/.idea/
/Minio.iml
**/access.log
assetfs.go
ui-assets.go
ui-assets.asc

@ -3,6 +3,8 @@ DOCKER_BIN := $(shell which docker)
DOCKER_LDFLAGS := '$(LDFLAGS) -extldflags "-static"'
BUILD_LDFLAGS := '$(LDFLAGS)'
TAG := latest
UI_ASSETS := ui-assets.go
UI_ASSETS_ARMOR := ui-assets.asc
all: install
@ -25,6 +27,12 @@ getdeps: checkdeps checkgopath
@go get -u github.com/fzipp/gocyclo && echo "Installed gocyclo:"
@go get -u github.com/remyoudompheng/go-misc/deadcode && echo "Installed deadcode:"
$(UI_ASSETS):
@curl -s https://dl.minio.io/assets/server/$(UI_ASSETS_ARMOR) 2>&1 > $(UI_ASSETS_ARMOR) && echo "Downloading signature file $(UI_ASSETS_ARMOR) for verification:"
@gpg --batch --no-tty --yes --keyserver pgp.mit.edu --recv-keys F9AAC728 2>&1 > /dev/null && echo "Importing public key:"
@curl -s https://dl.minio.io/assets/server/$@ 2>&1 > $@ && echo "Downloading UI assets file $@:"
@gpg --batch --no-tty --verify $(UI_ASSETS_ARMOR) $@ 2>&1 > /dev/null && echo "Verifying signature of downloaded assets."
verifiers: getdeps vet fmt lint cyclo
vet:
@ -49,7 +57,7 @@ cyclo:
@GO15VENDOREXPERIMENT=1 ${GOPATH}/bin/gocyclo -over 65 *.go
@GO15VENDOREXPERIMENT=1 ${GOPATH}/bin/gocyclo -over 65 pkg
build: getdeps verifiers
build: getdeps verifiers $(UI_ASSETS)
@echo "Installing minio:"
deadcode:

@ -10,6 +10,8 @@ clone_folder: c:\gopath\src\github.com\minio\minio
environment:
GOPATH: c:\gopath
GO15VENDOREXPERIMENT: 1
UI_ASSETS: ui-assets.go
UI_ASSETS_ARMOR: ui-assets.asc
# scripts that run after cloning repository
install:
@ -19,6 +21,10 @@ install:
# to run your custom scripts instead of automatic MSBuild
build_script:
- curl -o ui-assets.go -L https://dl.minio.io/assets/server/%UI_ASSETS%
- curl -o ui-assets.asc -L https://dl.minio.io/assets/server/%UI_ASSETS_ARMOR%
- gpg --batch --no-tty --yes --keyserver pgp.mit.edu --recv-keys F9AAC728
- gpg --batch --no-tty --verify %UI_ASSETS_ARMOR% %UI_ASSETS%
- go test .
- go test -race .
- go test github.com/minio/minio/pkg...

@ -75,8 +75,8 @@ func getWebAPIHandler(web *WebAPI) http.Handler {
root.Handle("/rpc", s)
// Enable this when we add assets.
// root.PathPrefix("/login").Handler(http.StripPrefix("/login", http.FileServer(assetFS())))
// root.Handle("/{file:.*}", http.FileServer(assetFS()))
root.PathPrefix("/login").Handler(http.StripPrefix("/login", http.FileServer(assetFS())))
root.Handle("/{file:.*}", http.FileServer(assetFS()))
return registerHandlers(mux, handlerFns...)
}

@ -41,6 +41,6 @@ use
...
http.Handle("/",
http.FileServer(
&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: "data"}))
&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: "data"}))
to serve files embedded from the `data` directory.

@ -13,7 +13,7 @@ import (
)
var (
fileTimestamp = time.Now()
defaultFileTimestamp = time.Now()
)
// FakeFile implements os.FileInfo interface for a given path and size
@ -24,6 +24,8 @@ type FakeFile struct {
Dir bool
// Len is the length of the fake file, zero if it is a directory
Len int64
// Timestamp is the ModTime of this file
Timestamp time.Time
}
func (f *FakeFile) Name() string {
@ -40,7 +42,7 @@ func (f *FakeFile) Mode() os.FileMode {
}
func (f *FakeFile) ModTime() time.Time {
return fileTimestamp
return f.Timestamp
}
func (f *FakeFile) Size() int64 {
@ -62,11 +64,14 @@ type AssetFile struct {
FakeFile
}
func NewAssetFile(name string, content []byte) *AssetFile {
func NewAssetFile(name string, content []byte, timestamp time.Time) *AssetFile {
if timestamp.IsZero() {
timestamp = defaultFileTimestamp
}
return &AssetFile{
bytes.NewReader(content),
ioutil.NopCloser(nil),
FakeFile{name, false, int64(len(content))}}
FakeFile{name, false, int64(len(content)), timestamp}}
}
func (f *AssetFile) Readdir(count int) ([]os.FileInfo, error) {
@ -92,13 +97,13 @@ func NewAssetDirectory(name string, children []string, fs *AssetFS) *AssetDirect
fileinfos := make([]os.FileInfo, 0, len(children))
for _, child := range children {
_, err := fs.AssetDir(filepath.Join(name, child))
fileinfos = append(fileinfos, &FakeFile{child, err == nil, 0})
fileinfos = append(fileinfos, &FakeFile{child, err == nil, 0, time.Time{}})
}
return &AssetDirectory{
AssetFile{
bytes.NewReader(nil),
ioutil.NopCloser(nil),
FakeFile{name, true, 0},
FakeFile{name, true, 0, time.Time{}},
},
0,
fileinfos}
@ -127,6 +132,8 @@ type AssetFS struct {
Asset func(path string) ([]byte, error)
// AssetDir should return list of files in the path
AssetDir func(path string) ([]string, error)
// AssetInfo should return the info of file in path if exists
AssetInfo func(path string) (os.FileInfo, error)
// Prefix would be prepended to http requests
Prefix string
}
@ -137,7 +144,11 @@ func (fs *AssetFS) Open(name string) (http.File, error) {
name = name[1:]
}
if b, err := fs.Asset(name); err == nil {
return NewAssetFile(name, b), nil
timestamp := defaultFileTimestamp
if info, err := fs.AssetInfo(name); err == nil {
timestamp = info.ModTime()
}
return NewAssetFile(name, b, timestamp), nil
}
if children, err := fs.AssetDir(name); err == nil {
return NewAssetDirectory(name, children, fs), nil

@ -19,8 +19,8 @@
},
{
"path": "github.com/elazarl/go-bindata-assetfs",
"revision": "d5cac425555ca5cf00694df246e04f05e6a55150",
"revisionTime": "2015-08-13T07:46:22+03:00"
"revision": "57eb5e1fc594ad4b0b1dbea7b286d299e0cb43c2",
"revisionTime": "2015-12-24T06:54:52+02:00"
},
{
"path": "github.com/fatih/color",

Loading…
Cancel
Save