Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
cc5c9f89
Commit
cc5c9f89
authored
Jul 23, 2015
by
Vish Kannan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11580 from ingvagabund/update-go-bindata-assetfs
golang 1.5 issues
parents
dfe1eb9b
defe0f82
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
9 deletions
+105
-9
Godeps.json
Godeps/Godeps.json
+1
-1
README.md
...space/src/github.com/elazarl/go-bindata-assetfs/README.md
+33
-5
assetfs.go
...pace/src/github.com/elazarl/go-bindata-assetfs/assetfs.go
+9
-3
main.go
...com/elazarl/go-bindata-assetfs/go-bindata-assetfs/main.go
+62
-0
No files found.
Godeps/Godeps.json
View file @
cc5c9f89
...
...
@@ -195,7 +195,7 @@
},
{
"ImportPath"
:
"github.com/elazarl/go-bindata-assetfs"
,
"Rev"
:
"
ae4665cf2d188c65764c73fe4af5378acc549510
"
"Rev"
:
"
c57a80f1ab2ad67bafa83f5fd0b4c2ecbd253dd5
"
},
{
"ImportPath"
:
"github.com/emicklei/go-restful"
,
...
...
Godeps/_workspace/src/github.com/elazarl/go-bindata-assetfs/README.md
View file @
cc5c9f89
go-bindata-http
===============
# go-bindata-assetfs
Serve embedded files from
[
jteeuwen/go-bindata
](
https://github.com/jteeuwen/go-bindata
)
with
`net/http`
.
[
GoDoc
](
http://godoc.org/github.com/elazarl/go-bindata-assetfs
)
After running
### Installation
$ go-bindata data/...
Install with
Use
$ go get github.com/jteeuwen/go-bindata/...
$ go get github.com/elazarl/go-bindata-assetfs/...
### Creating embedded data
Usage is identical to
[
jteeuwen/go-bindata
](
https://github.com/jteeuwen/go-bindata
)
usage,
instead of running
`go-bindata`
run
`go-bindata-assetfs`
.
The tool will create a
`bindata_assetfs.go`
file, which contains the embedded data.
A typical use case is
$ go-bindata-assetfs data/...
### Using assetFS in your code
The generated file provides an
`assetFS()`
function that returns a
`http.Filesystem`
wrapping the embedded files. What you usually want to do is:
http.Handle("/", http.FileServer(assetFS()))
This would run an HTTP server serving the embedded files.
## Without running binary tool
You can always just run the
`go-bindata`
tool, and then
use
import "github.com/elazarl/go-bindata-assetfs"
...
http.Handle("/",
http.FileServer(
&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: "data"}))
...
...
Godeps/_workspace/src/github.com/elazarl/go-bindata-assetfs/assetfs.go
View file @
cc5c9f89
...
...
@@ -3,7 +3,6 @@ package assetfs
import
(
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
...
...
@@ -13,6 +12,10 @@ import (
"time"
)
var
(
fileTimestamp
=
time
.
Now
()
)
// FakeFile implements os.FileInfo interface for a given path and size
type
FakeFile
struct
{
// Path is the path of this file
...
...
@@ -37,7 +40,7 @@ func (f *FakeFile) Mode() os.FileMode {
}
func
(
f
*
FakeFile
)
ModTime
()
time
.
Time
{
return
time
.
Unix
(
0
,
0
)
return
fileTimestamp
}
func
(
f
*
FakeFile
)
Size
()
int64
{
...
...
@@ -70,6 +73,10 @@ func (f *AssetFile) Readdir(count int) ([]os.FileInfo, error) {
return
nil
,
errors
.
New
(
"not a directory"
)
}
func
(
f
*
AssetFile
)
Size
()
int64
{
return
f
.
FakeFile
.
Size
()
}
func
(
f
*
AssetFile
)
Stat
()
(
os
.
FileInfo
,
error
)
{
return
f
,
nil
}
...
...
@@ -98,7 +105,6 @@ func NewAssetDirectory(name string, children []string, fs *AssetFS) *AssetDirect
}
func
(
f
*
AssetDirectory
)
Readdir
(
count
int
)
([]
os
.
FileInfo
,
error
)
{
fmt
.
Println
(
f
,
count
)
if
count
<=
0
{
return
f
.
Children
,
nil
}
...
...
Godeps/_workspace/src/github.com/elazarl/go-bindata-assetfs/go-bindata-assetfs/main.go
0 → 100644
View file @
cc5c9f89
package
main
import
(
"bufio"
"bytes"
"fmt"
"os"
"os/exec"
)
const
bindatafile
=
"bindata.go"
func
main
()
{
if
_
,
err
:=
exec
.
LookPath
(
"go-bindata"
);
err
!=
nil
{
fmt
.
Println
(
"Cannot find go-bindata executable in path"
)
fmt
.
Println
(
"Maybe you need: go get github.com/elazarl/go-bindata-assetfs/..."
)
os
.
Exit
(
1
)
}
cmd
:=
exec
.
Command
(
"go-bindata"
,
os
.
Args
[
1
:
]
...
)
cmd
.
Stdin
=
os
.
Stdin
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
if
err
:=
cmd
.
Run
();
err
!=
nil
{
os
.
Exit
(
1
)
}
in
,
err
:=
os
.
Open
(
bindatafile
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
"Cannot read"
,
bindatafile
,
err
)
return
}
out
,
err
:=
os
.
Create
(
"bindata_assetfs.go"
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
"Cannot write 'bindata_assetfs.go'"
,
err
)
return
}
r
:=
bufio
.
NewReader
(
in
)
done
:=
false
for
line
,
isPrefix
,
err
:=
r
.
ReadLine
();
err
==
nil
;
line
,
isPrefix
,
err
=
r
.
ReadLine
()
{
line
=
append
(
line
,
'\n'
)
if
_
,
err
:=
out
.
Write
(
line
);
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
"Cannot write to 'bindata_assetfs.go'"
,
err
)
return
}
if
!
done
&&
!
isPrefix
&&
bytes
.
HasPrefix
(
line
,
[]
byte
(
"import ("
))
{
fmt
.
Fprintln
(
out
,
"
\t\"
github.com/elazarl/go-bindata-assetfs
\"
"
)
done
=
true
}
}
fmt
.
Fprintln
(
out
,
`
func assetFS() *assetfs.AssetFS {
for k := range _bintree.Children {
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: k}
}
panic("unreachable")
}`
)
// Close files BEFORE remove calls (don't use defer).
in
.
Close
()
out
.
Close
()
if
err
:=
os
.
Remove
(
bindatafile
);
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
"Cannot remove"
,
bindatafile
,
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment