refactor to go-restful
This commit is contained in:
cmd/dkl-local-server
go.modgo.sumpkg/apiutils
vendor
github.com
PuerkitoBio
emicklei
go-restful-openapi
.gitignore.travis.ymlCHANGES.mdLICENSEREADME.mdbuild_definitions.gobuild_path.goconfig.godefinition_builder.golookup.goproperty_ext.gospec_resource.go
go-restful
.gitignore.travis.ymlCHANGES.mdLICENSEMakefileREADME.mdSrcfilebench_test.shcompress.gocompressor_cache.gocompressor_pools.gocompressors.goconstants.gocontainer.gocors_filter.gocoverage.shcurly.gocurly_route.godoc.goentity_accessors.gofilter.gojson.gojsoniter.gojsr311.go
log
logger.gomime.gooptions_filter.goparameter.gopath_expression.gopath_processor.gorequest.goresponse.goroute.goroute_builder.gorouter.goservice_error.goweb_service.goweb_service_container.gogo-openapi
jsonpointer
jsonreference
spec
.editorconfig.gitignore.golangci.yml.travis.ymlCODE_OF_CONDUCT.mdLICENSEREADME.mdbindata.gocontact_info.godebug.goexpander.goexternal_docs.gogo.modgo.sumheader.goinfo.goitems.golicense.gooperation.goparameter.gopath_item.gopaths.goref.goresponse.goresponses.goschema.gosecurity_scheme.gospec.goswagger.gotag.goxml_object.go
swag
gobuffalo
envy
.env.gitignore.gometalinter.json.travis.ymlLICENSE.txtMakefileREADME.mdenvy.gogo.modgo.sumshoulders.mdversion.go
packd
.gitignore.gometalinter.json.travis.ymlLICENSEMakefileREADME.mdfile.gofile_info.gogo.modgo.suminterfaces.gomemory_box.goskip_walker.goversion.go
packr
.codeclimate.yml.gitignore.gometalinter.json.goreleaser.yml.goreleaser.yml.plush.travis.ymlLICENSE.txtMakefileREADME.mdSHOULDERS.mdbox.goenv.gofile.gogo.modgo.sumpackr.gotravis.shversion.gowalk.go
syncx
joho
json-iterator
go
.codecov.yml.gitignore.travis.ymlGopkg.lockGopkg.tomlLICENSEREADME.mdadapter.goany.goany_array.goany_bool.goany_float.goany_int32.goany_int64.goany_invalid.goany_nil.goany_number.goany_object.goany_str.goany_uint32.goany_uint64.gobuild.shconfig.gofuzzy_mode_convert_table.mditer.goiter_array.goiter_float.goiter_int.goiter_object.goiter_skip.goiter_skip_sloppy.goiter_skip_strict.goiter_str.gojsoniter.gopool.goreflect.goreflect_array.goreflect_dynamic.goreflect_extension.goreflect_json_number.goreflect_json_raw_message.goreflect_map.goreflect_marshaler.goreflect_native.goreflect_optional.goreflect_slice.goreflect_struct_decoder.goreflect_struct_encoder.gostream.gostream_float.gostream_int.gostream_str.gotest.sh
mailru
easyjson
mcluseau
modern-go
concurrent
.gitignore.travis.ymlLICENSEREADME.mdexecutor.gogo_above_19.gogo_below_19.golog.gotest.shunbounded_executor.go
reflect2
.gitignore.travis.ymlGopkg.lockGopkg.tomlLICENSEREADME.mdgo_above_17.gogo_above_19.gogo_below_17.gogo_below_19.goreflect2.goreflect2_amd64.sreflect2_kind.gorelfect2_386.srelfect2_amd64p32.srelfect2_arm.srelfect2_arm64.srelfect2_mips64x.srelfect2_mipsx.srelfect2_ppc64x.srelfect2_s390x.ssafe_field.gosafe_map.gosafe_slice.gosafe_struct.gosafe_type.gotest.shtype_map.gounsafe_array.gounsafe_eface.gounsafe_field.gounsafe_iface.gounsafe_link.gounsafe_map.gounsafe_ptr.gounsafe_slice.gounsafe_struct.gounsafe_type.go
oklog
ulid
pkg
rogpeppe
golang.org
x
crypto
net
text
AUTHORSCONTRIBUTORSLICENSEPATENTS
secure
transform
unicode
bidi
bidi.gobracket.gocore.gogen.gogen_ranges.gogen_trieval.goprop.gotables10.0.0.gotables9.0.0.gotrieval.go
norm
width
128
vendor/github.com/gobuffalo/packd/file.go
generated
vendored
Normal file
128
vendor/github.com/gobuffalo/packd/file.go
generated
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
package packd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var _ File = &virtualFile{}
|
||||
var _ io.Reader = &virtualFile{}
|
||||
var _ io.Writer = &virtualFile{}
|
||||
var _ fmt.Stringer = &virtualFile{}
|
||||
|
||||
type virtualFile struct {
|
||||
io.Reader
|
||||
name string
|
||||
info fileInfo
|
||||
original []byte
|
||||
}
|
||||
|
||||
func (f virtualFile) Name() string {
|
||||
return f.name
|
||||
}
|
||||
|
||||
func (f *virtualFile) Seek(offset int64, whence int) (int64, error) {
|
||||
return f.Reader.(*bytes.Reader).Seek(offset, whence)
|
||||
}
|
||||
|
||||
func (f virtualFile) FileInfo() (os.FileInfo, error) {
|
||||
return f.info, nil
|
||||
}
|
||||
|
||||
func (f *virtualFile) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f virtualFile) Readdir(count int) ([]os.FileInfo, error) {
|
||||
return []os.FileInfo{f.info}, nil
|
||||
}
|
||||
|
||||
func (f virtualFile) Stat() (os.FileInfo, error) {
|
||||
return f.info, nil
|
||||
}
|
||||
|
||||
func (f virtualFile) String() string {
|
||||
return string(f.original)
|
||||
}
|
||||
|
||||
// Read reads the next len(p) bytes from the virtualFile and
|
||||
// rewind read offset to 0 when it met EOF.
|
||||
func (f *virtualFile) Read(p []byte) (int, error) {
|
||||
i, err := f.Reader.Read(p)
|
||||
|
||||
if i == 0 || err == io.EOF {
|
||||
f.Seek(0, io.SeekStart)
|
||||
}
|
||||
return i, err
|
||||
}
|
||||
|
||||
// Write copies byte slice p to content of virtualFile.
|
||||
func (f *virtualFile) Write(p []byte) (int, error) {
|
||||
return f.write(p)
|
||||
}
|
||||
|
||||
// write copies byte slice or data from io.Reader to content of the
|
||||
// virtualFile and update related information of the virtualFile.
|
||||
func (f *virtualFile) write(d interface{}) (c int, err error) {
|
||||
bb := &bytes.Buffer{}
|
||||
switch d.(type) {
|
||||
case []byte:
|
||||
c, err = bb.Write(d.([]byte))
|
||||
case io.Reader:
|
||||
if d != nil {
|
||||
i64, e := io.Copy(bb, d.(io.Reader))
|
||||
c = int(i64)
|
||||
err = e
|
||||
}
|
||||
default:
|
||||
err = errors.New("unknown type of argument")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return c, errors.WithStack(err)
|
||||
}
|
||||
|
||||
f.info.size = int64(c)
|
||||
f.info.modTime = time.Now()
|
||||
f.original = bb.Bytes()
|
||||
f.Reader = bytes.NewReader(f.original)
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// NewFile returns a new "virtual" file
|
||||
func NewFile(name string, r io.Reader) (File, error) {
|
||||
return buildFile(name, r)
|
||||
}
|
||||
|
||||
// NewDir returns a new "virtual" directory
|
||||
func NewDir(name string) (File, error) {
|
||||
v, err := buildFile(name, nil)
|
||||
if err != nil {
|
||||
return v, errors.WithStack(err)
|
||||
}
|
||||
v.info.isDir = true
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func buildFile(name string, r io.Reader) (*virtualFile, error) {
|
||||
vf := &virtualFile{
|
||||
name: name,
|
||||
info: fileInfo{
|
||||
Path: name,
|
||||
modTime: time.Now(),
|
||||
},
|
||||
}
|
||||
|
||||
var err error
|
||||
if r != nil {
|
||||
_, err = vf.write(r)
|
||||
} else {
|
||||
_, err = vf.write([]byte{}) // for safety
|
||||
}
|
||||
return vf, errors.Wrap(err, "could not make virtual file")
|
||||
}
|
Reference in New Issue
Block a user