forked from mirror/pkger
ruby soho
This commit is contained in:
parent
28af04274c
commit
b3ed58d6e9
|
@ -2,4 +2,6 @@ module github.com/markbates/pkger/examples/app
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require github.com/markbates/pkger v0.0.0-20190830024022-c5e3a7de4d41
|
require github.com/markbates/pkger v0.0.0
|
||||||
|
|
||||||
|
replace github.com/markbates/pkger => ../../
|
||||||
|
|
|
@ -10,6 +10,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
|
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
|
||||||
github.com/markbates/pkger v0.0.0-20190830024022-c5e3a7de4d41 h1:bFEHpLBby7Qdvq92qw0TudeOfUKIZLcrweE/MMlNueI=
|
github.com/markbates/pkger v0.0.0-20190830024022-c5e3a7de4d41 h1:bFEHpLBby7Qdvq92qw0TudeOfUKIZLcrweE/MMlNueI=
|
||||||
github.com/markbates/pkger v0.0.0-20190830024022-c5e3a7de4d41/go.mod h1:M9VeozwduQUCr6z54kJrK9JegpbOv4wiePSbgSbFOew=
|
github.com/markbates/pkger v0.0.0-20190830024022-c5e3a7de4d41/go.mod h1:M9VeozwduQUCr6z54kJrK9JegpbOv4wiePSbgSbFOew=
|
||||||
|
github.com/markbates/pkger/examples/app v0.0.0-20190830175641-68f3a2a4571d/go.mod h1:cWIt8Tz1UjmFa2KRaVgTfWPfHP+gprnzxDxNpo4YDxo=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
|
|
@ -18,11 +18,7 @@ func main() {
|
||||||
}
|
}
|
||||||
defer pub.Close()
|
defer pub.Close()
|
||||||
|
|
||||||
fi, err := pub.Stat()
|
fmt.Println(pub.Path())
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fmt.Println(fi)
|
|
||||||
|
|
||||||
mux.Handle("/t", http.StripPrefix("/t", tmplHandler()))
|
mux.Handle("/t", http.StripPrefix("/t", tmplHandler()))
|
||||||
mux.Handle("/", http.FileServer(pub))
|
mux.Handle("/", http.FileServer(pub))
|
||||||
|
|
5
go.mod
5
go.mod
|
@ -1,11 +1,8 @@
|
||||||
module github.com/markbates/pkger
|
module github.com/markbates/pkger
|
||||||
|
|
||||||
go 1.12
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
|
||||||
github.com/markbates/errx v1.1.0
|
github.com/markbates/errx v1.1.0
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
9
go.sum
9
go.sum
|
@ -1,12 +1,5 @@
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI=
|
github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI=
|
||||||
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
|
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
@ -16,7 +9,5 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
|
|
@ -135,48 +135,48 @@ func (s Suite) Test_HTTP_Dir_IndexHTML(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (s Suite) Test_HTTP_File(t *testing.T) {
|
func (s Suite) Test_HTTP_File(t *testing.T) {
|
||||||
// r := require.New(t)
|
r := require.New(t)
|
||||||
//
|
|
||||||
// cur, err := s.Current()
|
cur, err := s.Current()
|
||||||
// r.NoError(err)
|
r.NoError(err)
|
||||||
// ip := cur.ImportPath
|
ip := cur.ImportPath
|
||||||
//
|
|
||||||
// table := []struct {
|
table := []struct {
|
||||||
// in string
|
in string
|
||||||
// }{
|
}{
|
||||||
// {in: "/public"},
|
{in: "/public"},
|
||||||
// {in: ":" + "/public"},
|
{in: ":" + "/public"},
|
||||||
// {in: ip + ":" + "/public"},
|
{in: ip + ":" + "/public"},
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for _, tt := range table {
|
for _, tt := range table {
|
||||||
// s.Run(t, tt.in, func(st *testing.T) {
|
s.Run(t, tt.in, func(st *testing.T) {
|
||||||
//
|
|
||||||
// r := require.New(st)
|
r := require.New(st)
|
||||||
//
|
|
||||||
// r.NoError(s.LoadFolder())
|
r.NoError(s.LoadFolder())
|
||||||
//
|
|
||||||
// dir, err := s.Open(tt.in)
|
dir, err := s.Open(tt.in)
|
||||||
// r.NoError(err)
|
r.NoError(err)
|
||||||
// defer dir.Close()
|
defer dir.Close()
|
||||||
//
|
|
||||||
// ts := httptest.NewServer(http.FileServer(dir))
|
ts := httptest.NewServer(http.FileServer(dir))
|
||||||
// defer ts.Close()
|
defer ts.Close()
|
||||||
//
|
|
||||||
// res, err := http.Get(ts.URL + "/images/mark.png")
|
res, err := http.Get(ts.URL + "/images/mark.png")
|
||||||
// r.NoError(err)
|
r.NoError(err)
|
||||||
// r.Equal(200, res.StatusCode)
|
r.Equal(200, res.StatusCode)
|
||||||
//
|
|
||||||
// b, err := ioutil.ReadAll(res.Body)
|
b, err := ioutil.ReadAll(res.Body)
|
||||||
// r.NoError(err)
|
r.NoError(err)
|
||||||
//
|
|
||||||
// body := string(b)
|
body := string(b)
|
||||||
// r.Contains(body, `!/public/images/mark.png`)
|
r.Contains(body, `!/public/images/mark.png`)
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// func (s Suite) Test_HTTP_Dir_Memory_StripPrefix(t *testing.T) {
|
// func (s Suite) Test_HTTP_Dir_Memory_StripPrefix(t *testing.T) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package stdos
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/markbates/pkger/here"
|
"github.com/markbates/pkger/here"
|
||||||
"github.com/markbates/pkger/pkging"
|
"github.com/markbates/pkger/pkging"
|
||||||
|
@ -60,8 +61,31 @@ func (f *File) Name() string {
|
||||||
return f.info.Name()
|
return f.info.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HTTP struct {
|
||||||
|
pkging.File
|
||||||
|
osf *os.File
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *HTTP) Readdir(count int) ([]os.FileInfo, error) {
|
||||||
|
osinfos, err := f.osf.Readdir(count)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
infos := make([]os.FileInfo, len(osinfos))
|
||||||
|
for i, info := range osinfos {
|
||||||
|
infos[i] = pkging.WithName(info.Name(), info)
|
||||||
|
}
|
||||||
|
return infos, err
|
||||||
|
}
|
||||||
|
|
||||||
func (f *File) Open(name string) (http.File, error) {
|
func (f *File) Open(name string) (http.File, error) {
|
||||||
return f.File, nil
|
fp := path.Join(f.Path().Name, name)
|
||||||
|
f2, err := f.pkging.Open(fp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &HTTP{File: f2, osf: f.File}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *File) Path() pkging.Path {
|
func (f *File) Path() pkging.Path {
|
||||||
|
|
Loading…
Reference in New Issue