mirror of
https://github.com/octoleo/syncthing.git
synced 2024-10-10 06:57:56 +00:00
* go mod init; rm -rf vendor * tweak proto files and generation * go mod vendor * clean up build.go * protobuf literals in tests * downgrade gogo/protobuf
This commit is contained in:
parent
3cc8918eb4
commit
944ddcf768
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,3 +23,4 @@ parts/
|
|||||||
stage/
|
stage/
|
||||||
*.snap
|
*.snap
|
||||||
*.bz2
|
*.bz2
|
||||||
|
/repos
|
||||||
|
160
build.go
160
build.go
@ -42,7 +42,6 @@ var (
|
|||||||
goVersion float64
|
goVersion float64
|
||||||
race bool
|
race bool
|
||||||
debug = os.Getenv("BUILDDEBUG") != ""
|
debug = os.Getenv("BUILDDEBUG") != ""
|
||||||
noBuildGopath bool
|
|
||||||
extraTags string
|
extraTags string
|
||||||
installSuffix string
|
installSuffix string
|
||||||
pkgdir string
|
pkgdir string
|
||||||
@ -188,6 +187,19 @@ var targets = map[string]target{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are repos we need to clone to run "go generate"
|
||||||
|
|
||||||
|
type dependencyRepo struct {
|
||||||
|
path string
|
||||||
|
repo string
|
||||||
|
commit string
|
||||||
|
}
|
||||||
|
|
||||||
|
var dependencyRepos = []dependencyRepo{
|
||||||
|
{path: "protobuf", repo: "https://github.com/gogo/protobuf.git", commit: "v1.0.0"},
|
||||||
|
{path: "xdr", repo: "https://github.com/calmh/xdr.git", commit: "08e072f9cb16"},
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// The "syncthing" target includes a few more files found in the "etc"
|
// The "syncthing" target includes a few more files found in the "etc"
|
||||||
// and "extra" dirs.
|
// and "extra" dirs.
|
||||||
@ -216,39 +228,6 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if gopath := gopath(); gopath == "" {
|
|
||||||
gopath, err := temporaryBuildDir()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
os.Setenv("GOPATH", gopath)
|
|
||||||
log.Println("GOPATH is", gopath)
|
|
||||||
if !noBuildGopath {
|
|
||||||
if err := buildGOPATH(gopath); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
lazyRebuildAssets()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
inside := false
|
|
||||||
wd, _ := os.Getwd()
|
|
||||||
wd, _ = filepath.EvalSymlinks(wd)
|
|
||||||
for _, p := range filepath.SplitList(gopath) {
|
|
||||||
p, _ = filepath.EvalSymlinks(p)
|
|
||||||
if filepath.Join(p, "src/github.com/syncthing/syncthing") == wd {
|
|
||||||
inside = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !inside {
|
|
||||||
fmt.Println("You seem to have GOPATH set but the Syncthing source not placed correctly within it, which may cause problems.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set path to $GOPATH/bin:$PATH so that we can for sure find tools we
|
|
||||||
// might have installed during "build.go setup".
|
|
||||||
os.Setenv("PATH", fmt.Sprintf("%s%cbin%c%s", os.Getenv("GOPATH"), os.PathSeparator, os.PathListSeparator, os.Getenv("PATH")))
|
|
||||||
|
|
||||||
// Invoking build.go with no parameters at all builds everything (incrementally),
|
// Invoking build.go with no parameters at all builds everything (incrementally),
|
||||||
// which is what you want for maximum error checking during development.
|
// which is what you want for maximum error checking during development.
|
||||||
if flag.NArg() == 0 {
|
if flag.NArg() == 0 {
|
||||||
@ -322,9 +301,6 @@ func runCommand(cmd string, target target) {
|
|||||||
case "snap":
|
case "snap":
|
||||||
buildSnap(target)
|
buildSnap(target)
|
||||||
|
|
||||||
case "clean":
|
|
||||||
clean()
|
|
||||||
|
|
||||||
case "vet":
|
case "vet":
|
||||||
metalintShort()
|
metalintShort()
|
||||||
|
|
||||||
@ -337,13 +313,6 @@ func runCommand(cmd string, target target) {
|
|||||||
case "version":
|
case "version":
|
||||||
fmt.Println(getVersion())
|
fmt.Println(getVersion())
|
||||||
|
|
||||||
case "gopath":
|
|
||||||
gopath, err := temporaryBuildDir()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fmt.Println(gopath)
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Unknown command %q", cmd)
|
log.Fatalf("Unknown command %q", cmd)
|
||||||
}
|
}
|
||||||
@ -355,7 +324,6 @@ func parseFlags() {
|
|||||||
flag.BoolVar(&noupgrade, "no-upgrade", noupgrade, "Disable upgrade functionality")
|
flag.BoolVar(&noupgrade, "no-upgrade", noupgrade, "Disable upgrade functionality")
|
||||||
flag.StringVar(&version, "version", getVersion(), "Set compiled in version string")
|
flag.StringVar(&version, "version", getVersion(), "Set compiled in version string")
|
||||||
flag.BoolVar(&race, "race", race, "Use race detector")
|
flag.BoolVar(&race, "race", race, "Use race detector")
|
||||||
flag.BoolVar(&noBuildGopath, "no-build-gopath", noBuildGopath, "Don't build GOPATH, assume it's OK")
|
|
||||||
flag.StringVar(&extraTags, "tags", extraTags, "Extra tags, space separated")
|
flag.StringVar(&extraTags, "tags", extraTags, "Extra tags, space separated")
|
||||||
flag.StringVar(&installSuffix, "installsuffix", installSuffix, "Install suffix, optional")
|
flag.StringVar(&installSuffix, "installsuffix", installSuffix, "Install suffix, optional")
|
||||||
flag.StringVar(&pkgdir, "pkgdir", "", "Set -pkgdir parameter for `go build`")
|
flag.StringVar(&pkgdir, "pkgdir", "", "Set -pkgdir parameter for `go build`")
|
||||||
@ -787,6 +755,14 @@ func shouldRebuildAssets(target, srcdir string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func proto() {
|
func proto() {
|
||||||
|
os.MkdirAll("repos", 0755)
|
||||||
|
for _, dep := range dependencyRepos {
|
||||||
|
path := filepath.Join("repos", dep.path)
|
||||||
|
if _, err := os.Stat(path); err != nil {
|
||||||
|
runPrintInDir("repos", "git", "clone", dep.repo, dep.path)
|
||||||
|
runPrintInDir(path, "git", "checkout", dep.commit)
|
||||||
|
}
|
||||||
|
}
|
||||||
runPrint("go", "generate", "github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/stdiscosrv")
|
runPrint("go", "generate", "github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/stdiscosrv")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -806,11 +782,6 @@ func transifex() {
|
|||||||
runPrint("go", "run", "../../../../script/transifexdl.go")
|
runPrint("go", "run", "../../../../script/transifexdl.go")
|
||||||
}
|
}
|
||||||
|
|
||||||
func clean() {
|
|
||||||
rmr("bin")
|
|
||||||
rmr(filepath.Join(os.Getenv("GOPATH"), fmt.Sprintf("pkg/%s_%s/github.com/syncthing", goos, goarch)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ldflags() string {
|
func ldflags() string {
|
||||||
sep := '='
|
sep := '='
|
||||||
if goVersion > 0 && goVersion < 1.5 {
|
if goVersion > 0 && goVersion < 1.5 {
|
||||||
@ -1005,6 +976,10 @@ func runError(cmd string, args ...string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runPrint(cmd string, args ...string) {
|
func runPrint(cmd string, args ...string) {
|
||||||
|
runPrintInDir(".", cmd, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runPrintInDir(dir string, cmd string, args ...string) {
|
||||||
if debug {
|
if debug {
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
log.Println("runPrint:", cmd, strings.Join(args, " "))
|
log.Println("runPrint:", cmd, strings.Join(args, " "))
|
||||||
@ -1015,6 +990,7 @@ func runPrint(cmd string, args ...string) {
|
|||||||
ecmd := exec.Command(cmd, args...)
|
ecmd := exec.Command(cmd, args...)
|
||||||
ecmd.Stdout = os.Stdout
|
ecmd.Stdout = os.Stdout
|
||||||
ecmd.Stderr = os.Stderr
|
ecmd.Stderr = os.Stderr
|
||||||
|
ecmd.Dir = dir
|
||||||
err := ecmd.Run()
|
err := ecmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -1268,90 +1244,6 @@ func temporaryBuildDir() (string, error) {
|
|||||||
return filepath.Join(tmpDir, base), nil
|
return filepath.Join(tmpDir, base), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildGOPATH(gopath string) error {
|
|
||||||
pkg := filepath.Join(gopath, "src/github.com/syncthing/syncthing")
|
|
||||||
dirs := []string{"cmd", "gui", "lib", "meta", "script", "test", "vendor"}
|
|
||||||
|
|
||||||
if debug {
|
|
||||||
t0 := time.Now()
|
|
||||||
log.Println("build temporary GOPATH in", gopath)
|
|
||||||
defer func() {
|
|
||||||
log.Println("... in", time.Since(t0))
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Walk the sources and copy the files into the temporary GOPATH.
|
|
||||||
// Remember which files are supposed to be present so we can clean
|
|
||||||
// out everything else in the next step. The copyFile() step will
|
|
||||||
// only actually copy the file if it doesn't exist or the contents
|
|
||||||
// differ.
|
|
||||||
|
|
||||||
exists := map[string]struct{}{}
|
|
||||||
for _, dir := range dirs {
|
|
||||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if info.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
dst := filepath.Join(pkg, path)
|
|
||||||
exists[dst] = struct{}{}
|
|
||||||
|
|
||||||
if err := copyFile(path, dst, info.Mode()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Walk the temporary GOPATH and remove any files that we wouldn't
|
|
||||||
// have copied there in the previous step.
|
|
||||||
|
|
||||||
filepath.Walk(pkg, func(path string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if info.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if _, ok := exists[path]; !ok {
|
|
||||||
os.Remove(path)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func gopath() string {
|
|
||||||
if gopath := os.Getenv("GOPATH"); gopath != "" {
|
|
||||||
// The env var is set, use that.
|
|
||||||
return gopath
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ask Go what it thinks.
|
|
||||||
bs, err := runError("go", "env", "GOPATH")
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// We got something. Check if we are in fact available in that location.
|
|
||||||
gopath := string(bs)
|
|
||||||
if _, err := os.Stat(filepath.Join(gopath, "src/github.com/syncthing/syncthing/build.go")); err == nil {
|
|
||||||
// That seems to be the gopath.
|
|
||||||
return gopath
|
|
||||||
}
|
|
||||||
|
|
||||||
// The gopath is not valid.
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t target) BinaryName() string {
|
func (t target) BinaryName() string {
|
||||||
if goos == "windows" {
|
if goos == "windows" {
|
||||||
return t.binaryName + ".exe"
|
return t.binaryName + ".exe"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
//go:generate go run ../../script/protofmt.go database.proto
|
//go:generate go run ../../script/protofmt.go database.proto
|
||||||
//go:generate protoc -I ../../../../../ -I ../../vendor/ -I ../../vendor/github.com/gogo/protobuf/protobuf -I . --gogofast_out=. database.proto
|
//go:generate protoc -I ../../ -I . --gogofast_out=. database.proto
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -751,22 +751,22 @@ var (
|
|||||||
func init() { proto.RegisterFile("database.proto", fileDescriptorDatabase) }
|
func init() { proto.RegisterFile("database.proto", fileDescriptorDatabase) }
|
||||||
|
|
||||||
var fileDescriptorDatabase = []byte{
|
var fileDescriptorDatabase = []byte{
|
||||||
// 264 bytes of a gzipped FileDescriptorProto
|
// 258 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0x49, 0x2c, 0x49,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0x49, 0x2c, 0x49,
|
||||||
0x4c, 0x4a, 0x2c, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc,
|
0x4c, 0x4a, 0x2c, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc,
|
||||||
0x93, 0xd2, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f,
|
0x93, 0x52, 0x2e, 0x4a, 0x2d, 0xc8, 0x2f, 0xd6, 0x07, 0x0b, 0x25, 0x95, 0xa6, 0xe9, 0xa7, 0xe7,
|
||||||
0xcf, 0xd7, 0x07, 0x4b, 0x26, 0x95, 0xa6, 0x81, 0x79, 0x60, 0x0e, 0x98, 0x05, 0xd1, 0xa4, 0xd4,
|
0xa7, 0xe7, 0x83, 0x39, 0x60, 0x16, 0x44, 0xa9, 0x52, 0x3f, 0x23, 0x17, 0x9f, 0x0b, 0x54, 0x77,
|
||||||
0xcf, 0xc8, 0xc5, 0xe7, 0x02, 0x35, 0x27, 0x28, 0x35, 0x39, 0xbf, 0x28, 0x45, 0xc8, 0x92, 0x8b,
|
0x50, 0x6a, 0x72, 0x7e, 0x51, 0x8a, 0x90, 0x25, 0x17, 0x67, 0x62, 0x4a, 0x4a, 0x51, 0x6a, 0x71,
|
||||||
0x33, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x38, 0xb5, 0x58, 0x82, 0x51, 0x81, 0x59, 0x83, 0xdb,
|
0x71, 0x6a, 0xb1, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0xa8, 0x1e, 0xc8, 0x44, 0x3d, 0x98,
|
||||||
0x48, 0x54, 0x0f, 0x64, 0xb6, 0x1e, 0x4c, 0xa1, 0x23, 0x44, 0xda, 0x89, 0xe5, 0xc4, 0x3d, 0x79,
|
0x42, 0x47, 0x88, 0xb4, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x08, 0xd5, 0x42, 0x62, 0x5c,
|
||||||
0x86, 0x20, 0x84, 0x6a, 0x21, 0x31, 0x2e, 0xb6, 0xdc, 0x4c, 0xb0, 0x3e, 0x26, 0x05, 0x46, 0x0d,
|
0x6c, 0xb9, 0x99, 0x60, 0x7d, 0x4c, 0x0a, 0x8c, 0x1a, 0xac, 0x41, 0x50, 0x9e, 0x90, 0x10, 0x17,
|
||||||
0xd6, 0x20, 0x28, 0x4f, 0x48, 0x88, 0x8b, 0xa5, 0x38, 0x35, 0x35, 0x4f, 0x82, 0x59, 0x81, 0x51,
|
0x4b, 0x71, 0x6a, 0x6a, 0x9e, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x73, 0x10, 0x98, 0x0d, 0x57, 0x9b,
|
||||||
0x83, 0x39, 0x08, 0xcc, 0x86, 0xab, 0x4d, 0x91, 0x60, 0x01, 0x8b, 0x42, 0x79, 0x4a, 0x25, 0x5c,
|
0x22, 0xc1, 0x02, 0x16, 0x85, 0xf2, 0x94, 0x4a, 0xb8, 0x04, 0x83, 0x52, 0x0b, 0x72, 0x32, 0x93,
|
||||||
0x82, 0x41, 0xa9, 0x05, 0x39, 0x99, 0xc9, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x50, 0x37, 0x09, 0x70,
|
0x13, 0x4b, 0x32, 0xf3, 0xf3, 0xa0, 0x6e, 0x12, 0xe0, 0x62, 0xce, 0x4e, 0xad, 0x94, 0x60, 0x54,
|
||||||
0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0x98, 0xa8, 0xae, 0x64,
|
0x60, 0xd4, 0xe0, 0x0c, 0x02, 0x31, 0x51, 0x5d, 0xc9, 0x44, 0x92, 0x2b, 0xb1, 0xb8, 0x46, 0xc9,
|
||||||
0x22, 0xc9, 0x95, 0x58, 0x5c, 0xa3, 0xe4, 0xca, 0xc5, 0x8f, 0xa6, 0x4f, 0x48, 0x82, 0x8b, 0x1d,
|
0x95, 0x8b, 0x1f, 0x4d, 0x9f, 0x90, 0x04, 0x17, 0x3b, 0x54, 0x0f, 0xd4, 0x5e, 0x18, 0x17, 0x24,
|
||||||
0xaa, 0x07, 0x6a, 0x2f, 0x8c, 0x0b, 0x92, 0x49, 0xad, 0x28, 0xc8, 0x2c, 0x82, 0xfa, 0x93, 0x39,
|
0x93, 0x5a, 0x51, 0x90, 0x59, 0x04, 0xf5, 0x27, 0x73, 0x10, 0x8c, 0xeb, 0x24, 0x70, 0xe2, 0xa1,
|
||||||
0x08, 0xc6, 0x75, 0x12, 0x38, 0xf1, 0x50, 0x8e, 0xe1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4,
|
0x1c, 0xc3, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x98, 0xc4,
|
||||||
0x18, 0x1f, 0x3c, 0x92, 0x63, 0x4c, 0x62, 0x03, 0x87, 0xb3, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff,
|
0x06, 0x0e, 0x67, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x13, 0xba, 0x28, 0xc9, 0xa4, 0x01,
|
||||||
0x6a, 0x22, 0xa2, 0x85, 0xae, 0x01, 0x00, 0x00,
|
0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ syntax = "proto3";
|
|||||||
|
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
import "repos/protobuf/gogoproto/gogo.proto";
|
||||||
|
|
||||||
option (gogoproto.goproto_getters_all) = false;
|
option (gogoproto.goproto_getters_all) = false;
|
||||||
|
|
||||||
|
52
go.mod
Normal file
52
go.mod
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
module github.com/syncthing/syncthing
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/AudriusButkevicius/cli v0.0.0-20140727204646-7f561c78b5a4
|
||||||
|
github.com/AudriusButkevicius/go-nat-pmp v0.0.0-20160522074932-452c97607362
|
||||||
|
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a // indirect
|
||||||
|
github.com/bkaradzic/go-lz4 v0.0.0-20160924222819-7224d8d8f27e
|
||||||
|
github.com/calmh/du v1.0.1
|
||||||
|
github.com/calmh/xdr v1.1.0
|
||||||
|
github.com/chmduquesne/rollinghash v0.0.0-20180912150627-a60f8e7142b5
|
||||||
|
github.com/d4l3k/messagediff v1.2.1
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/gobwas/glob v0.0.0-20170212200151-51eb1ee00b6d
|
||||||
|
github.com/gogo/protobuf v1.0.0
|
||||||
|
github.com/golang/groupcache v0.0.0-20171101203131-84a468cf14b4
|
||||||
|
github.com/golang/protobuf v0.0.0-20171113180720-1e59b77b52bf // indirect
|
||||||
|
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 // indirect
|
||||||
|
github.com/jackpal/gateway v0.0.0-20161225004348-5795ac81146e
|
||||||
|
github.com/kballard/go-shellquote v0.0.0-20170619183022-cd60e84ee657
|
||||||
|
github.com/kr/pretty v0.1.0 // indirect
|
||||||
|
github.com/lib/pq v1.0.0
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||||
|
github.com/minio/sha256-simd v0.0.0-20171213220625-ad98a36ba0da
|
||||||
|
github.com/onsi/ginkgo v0.0.0-20171221013426-6c46eb8334b3 // indirect
|
||||||
|
github.com/onsi/gomega v0.0.0-20171227184521-ba3724c94e4d // indirect
|
||||||
|
github.com/oschwald/geoip2-golang v1.1.0
|
||||||
|
github.com/oschwald/maxminddb-golang v0.0.0-20170901134056-26fe5ace1c70 // indirect
|
||||||
|
github.com/petermattis/goid v0.0.0-20170816195418-3db12ebb2a59 // indirect
|
||||||
|
github.com/pkg/errors v0.0.0-20171216070316-e881fd58d78e
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/prometheus/client_golang v0.9.0
|
||||||
|
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5 // indirect
|
||||||
|
github.com/prometheus/common v0.0.0-20171117163051-2e54d0b93cba // indirect
|
||||||
|
github.com/prometheus/procfs v0.0.0-20171226183907-b15cd069a834 // indirect
|
||||||
|
github.com/rcrowley/go-metrics v0.0.0-20171128170426-e181e095bae9
|
||||||
|
github.com/sasha-s/go-deadlock v0.2.0
|
||||||
|
github.com/stretchr/testify v1.2.2 // indirect
|
||||||
|
github.com/syncthing/notify v0.0.0-20181107104724-4e389ea6c0d8
|
||||||
|
github.com/syndtr/goleveldb v0.0.0-20171214120811-34011bf325bc
|
||||||
|
github.com/thejerf/suture v0.0.0-20180907184608-bf6ee6a0b047
|
||||||
|
github.com/vitrun/qart v0.0.0-20160531060029-bf64b92db6b0
|
||||||
|
golang.org/x/crypto v0.0.0-20171231215028-0fcca4842a8d
|
||||||
|
golang.org/x/net v0.0.0-20171212005608-d866cfc389ce
|
||||||
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 // indirect
|
||||||
|
golang.org/x/text v0.0.0-20171227012246-e19ae1496984
|
||||||
|
golang.org/x/time v0.0.0-20170927054726-6dc17368e09b
|
||||||
|
gopkg.in/asn1-ber.v1 v1.0.0-20170511165959-379148ca0225 // indirect
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||||
|
gopkg.in/ldap.v2 v2.5.1
|
||||||
|
gopkg.in/yaml.v2 v2.0.0-20171116090243-287cf08546ab // indirect
|
||||||
|
)
|
100
go.sum
Normal file
100
go.sum
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
github.com/AudriusButkevicius/cli v0.0.0-20140727204646-7f561c78b5a4 h1:Cy4N5BdzSyWRnkNyzkIMKPSuzENT4AGxC+YFo0OOcCI=
|
||||||
|
github.com/AudriusButkevicius/cli v0.0.0-20140727204646-7f561c78b5a4/go.mod h1:mK5FQv1k6rd64lZeDQ+JgG5hSERyVEYeC3qXrbN+2nw=
|
||||||
|
github.com/AudriusButkevicius/go-nat-pmp v0.0.0-20160522074932-452c97607362 h1:l4qGIzSY0WhdXdR74XMYAtfc0Ri/RJVM4p6x/E/+WkA=
|
||||||
|
github.com/AudriusButkevicius/go-nat-pmp v0.0.0-20160522074932-452c97607362/go.mod h1:CEaBhA5lh1spxbPOELh5wNLKGsVQoahjUhVrJViVK8s=
|
||||||
|
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a h1:BtpsbiV638WQZwhA98cEZw2BsbnQJrbd0BI7tsy0W1c=
|
||||||
|
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||||
|
github.com/bkaradzic/go-lz4 v0.0.0-20160924222819-7224d8d8f27e h1:2augTYh6E+XoNrrivZJBadpThP/dsvYKj0nzqfQ8tM4=
|
||||||
|
github.com/bkaradzic/go-lz4 v0.0.0-20160924222819-7224d8d8f27e/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
|
||||||
|
github.com/calmh/du v1.0.1 h1:uDCrDbXVVPrzxSNRkpj6nqSfwrl5uRWH3zvrJgl7RRo=
|
||||||
|
github.com/calmh/du v1.0.1/go.mod h1:pHNccp4cXQeyDaiV3S7t5GN+eGOgynF0VSLxJjk9tLU=
|
||||||
|
github.com/calmh/xdr v1.1.0 h1:U/Dd4CXNLoo8EiQ4ulJUXkgO1/EyQLgDKLgpY1SOoJE=
|
||||||
|
github.com/calmh/xdr v1.1.0/go.mod h1:E8sz2ByAdXC8MbANf1LCRYzedSnnc+/sXXJs/PVqoeg=
|
||||||
|
github.com/chmduquesne/rollinghash v0.0.0-20180912150627-a60f8e7142b5 h1:Wg96Dh0MLTanEaPO0OkGtUIaa2jOnShAIOVUIzRHUxo=
|
||||||
|
github.com/chmduquesne/rollinghash v0.0.0-20180912150627-a60f8e7142b5/go.mod h1:Uc2I36RRfTAf7Dge82bi3RU0OQUmXT9iweIcPqvr8A0=
|
||||||
|
github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U=
|
||||||
|
github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
|
||||||
|
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/gobwas/glob v0.0.0-20170212200151-51eb1ee00b6d h1:IngNQgbqr5ZOU0exk395Szrvkzes9Ilk1fmJfkw7d+M=
|
||||||
|
github.com/gobwas/glob v0.0.0-20170212200151-51eb1ee00b6d/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||||
|
github.com/gogo/protobuf v1.0.0 h1:2jyBKDKU/8v3v2xVR2PtiWQviFUyiaGk2rpfyFT8rTM=
|
||||||
|
github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
|
github.com/golang/groupcache v0.0.0-20171101203131-84a468cf14b4 h1:6o8aP0LGMKzo3NzwhhX6EJsiJ3ejmj+9yA/3p8Fjjlw=
|
||||||
|
github.com/golang/groupcache v0.0.0-20171101203131-84a468cf14b4/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
|
github.com/golang/protobuf v0.0.0-20171113180720-1e59b77b52bf h1:pFr/u+m8QUBMW/itAczltF3guNRAL7XDs5tD3f6nSD0=
|
||||||
|
github.com/golang/protobuf v0.0.0-20171113180720-1e59b77b52bf/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk=
|
||||||
|
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/jackpal/gateway v0.0.0-20161225004348-5795ac81146e h1:lS8IitpqG4RkZbEDlZg5Z7FvBdWLVjSVfsPGOKafEkI=
|
||||||
|
github.com/jackpal/gateway v0.0.0-20161225004348-5795ac81146e/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
|
||||||
|
github.com/kballard/go-shellquote v0.0.0-20170619183022-cd60e84ee657 h1:vE7J1m7cCpiRVEIr1B5ccDxRpbPsWT5JU3if2Di5nE4=
|
||||||
|
github.com/kballard/go-shellquote v0.0.0-20170619183022-cd60e84ee657/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||||
|
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/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
|
||||||
|
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
|
github.com/minio/sha256-simd v0.0.0-20171213220625-ad98a36ba0da h1:tazA5y1hWYJO8VSYbU36yBhXeIvruLXMUKu6WBtcJck=
|
||||||
|
github.com/minio/sha256-simd v0.0.0-20171213220625-ad98a36ba0da/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
|
||||||
|
github.com/onsi/ginkgo v0.0.0-20171221013426-6c46eb8334b3 h1:ZN7kHmC0iunA+4UPmERwsuMQan4lUnntO6WX6H1jOO8=
|
||||||
|
github.com/onsi/ginkgo v0.0.0-20171221013426-6c46eb8334b3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
github.com/onsi/gomega v0.0.0-20171227184521-ba3724c94e4d h1:r351oUAFgdsydkt/g+XR/iJWRwyxVpy6nkNdEl/QdAs=
|
||||||
|
github.com/onsi/gomega v0.0.0-20171227184521-ba3724c94e4d/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||||
|
github.com/oschwald/geoip2-golang v1.1.0 h1:ACVPz5YqH4/jZkQdsp/PZc9shQVZmreCzAVNss5y3bo=
|
||||||
|
github.com/oschwald/geoip2-golang v1.1.0/go.mod h1:0LTTzix/Ao1uMvOhAV4iLU0Lz7eCrP94qZWBTDKf0iE=
|
||||||
|
github.com/oschwald/maxminddb-golang v0.0.0-20170901134056-26fe5ace1c70 h1:XGLYUmodtNzThosQ8GkMvj9TiIB/uWsP8NfxKSa3aDc=
|
||||||
|
github.com/oschwald/maxminddb-golang v0.0.0-20170901134056-26fe5ace1c70/go.mod h1:3jhIUymTJ5VREKyIhWm66LJiQt04F0UCDdodShpjWsY=
|
||||||
|
github.com/petermattis/goid v0.0.0-20170816195418-3db12ebb2a59 h1:2pHcLyJYXivxVvpoCc29uo3GDU1qFfJ1ggXKGYMrM0E=
|
||||||
|
github.com/petermattis/goid v0.0.0-20170816195418-3db12ebb2a59/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
|
||||||
|
github.com/pkg/errors v0.0.0-20171216070316-e881fd58d78e h1:+RHxT/gm0O3UF7nLJbdNzAmULvCFt4XfXHWzh3XI/zs=
|
||||||
|
github.com/pkg/errors v0.0.0-20171216070316-e881fd58d78e/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
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/prometheus/client_golang v0.9.0 h1:tXuTFVHC03mW0D+Ua1Q2d1EAVqLTuggX50V0VLICCzY=
|
||||||
|
github.com/prometheus/client_golang v0.9.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5 h1:cLL6NowurKLMfCeQy4tIeph12XNQWgANCNvdyrOYKV4=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
|
github.com/prometheus/common v0.0.0-20171117163051-2e54d0b93cba h1:/MUKoJbk4oXV3uxkpfHVkmVfL+wzWW6dttaW26s07Gg=
|
||||||
|
github.com/prometheus/common v0.0.0-20171117163051-2e54d0b93cba/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20171226183907-b15cd069a834 h1:HRxr4uZnx/S86wVQsfXcKhadpzdceXn2qCzCtagcI6w=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20171226183907-b15cd069a834/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
|
github.com/rcrowley/go-metrics v0.0.0-20171128170426-e181e095bae9 h1:jmLW6izPBVlIbk4d+XgK9+sChGbVKxxOPmd9eqRHCjw=
|
||||||
|
github.com/rcrowley/go-metrics v0.0.0-20171128170426-e181e095bae9/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||||
|
github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73DK8Y=
|
||||||
|
github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10=
|
||||||
|
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/syncthing/notify v0.0.0-20181107104724-4e389ea6c0d8 h1:ewsMW/a4xDpqHyIteoD29ayMn6GdkFZc2T0PX2K6PAg=
|
||||||
|
github.com/syncthing/notify v0.0.0-20181107104724-4e389ea6c0d8/go.mod h1:Sn4ChoS7e4FxjCN1XHPVBT43AgnRLbuaB8pEc1Zcdjg=
|
||||||
|
github.com/syndtr/goleveldb v0.0.0-20171214120811-34011bf325bc h1:yhWARKbbDg8UBRi/M5bVcVOBg2viFKcNJEAtHMYbRBo=
|
||||||
|
github.com/syndtr/goleveldb v0.0.0-20171214120811-34011bf325bc/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
|
||||||
|
github.com/thejerf/suture v0.0.0-20180907184608-bf6ee6a0b047 h1:TRlvuQjC13jRLqqJTp8rbb5SjRTYCP/8sCIYRdEaJrg=
|
||||||
|
github.com/thejerf/suture v0.0.0-20180907184608-bf6ee6a0b047/go.mod h1:ibKwrVj+Uzf3XZdAiNWUouPaAbSoemxOHLmJmwheEMc=
|
||||||
|
github.com/vitrun/qart v0.0.0-20160531060029-bf64b92db6b0 h1:okhMind4q9H1OxF44gNegWkiP4H/gsTFLalHFa4OOUI=
|
||||||
|
github.com/vitrun/qart v0.0.0-20160531060029-bf64b92db6b0/go.mod h1:TTbGUfE+cXXceWtbTHq6lqcTvYPBKLNejBEbnUsQJtU=
|
||||||
|
golang.org/x/crypto v0.0.0-20171231215028-0fcca4842a8d h1:GrqEEc3+MtHKTsZrdIGVoYDgLpbSRzW1EF+nLu0PcHE=
|
||||||
|
golang.org/x/crypto v0.0.0-20171231215028-0fcca4842a8d/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
|
golang.org/x/net v0.0.0-20171212005608-d866cfc389ce h1:4g3VPcb++AP2cNa6CQ0iACUoH7J/3Jxojq0mmJun9A4=
|
||||||
|
golang.org/x/net v0.0.0-20171212005608-d866cfc389ce/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
|
||||||
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 h1:0oC8rFnE+74kEmuHZ46F6KHsMr5Gx2gUQPuNz28iQZM=
|
||||||
|
golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/text v0.0.0-20171227012246-e19ae1496984 h1:ulYJn/BqO4fMRe1xAQzWjokgjsQLPpb21GltxXHI3fQ=
|
||||||
|
golang.org/x/text v0.0.0-20171227012246-e19ae1496984/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/time v0.0.0-20170927054726-6dc17368e09b h1:3X+R0qq1+64izd8es+EttB6qcY+JDlVmAhpRXl7gpzU=
|
||||||
|
golang.org/x/time v0.0.0-20170927054726-6dc17368e09b/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
gopkg.in/asn1-ber.v1 v1.0.0-20170511165959-379148ca0225 h1:JBwmEvLfCqgPcIq8MjVMQxsF3LVL4XG/HH0qiG0+IFY=
|
||||||
|
gopkg.in/asn1-ber.v1 v1.0.0-20170511165959-379148ca0225/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
|
||||||
|
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/ldap.v2 v2.5.1 h1:wiu0okdNfjlBzg6UWvd1Hn8Y+Ux17/u/4nlk4CQr6tU=
|
||||||
|
gopkg.in/ldap.v2 v2.5.1/go.mod h1:oI0cpe/D7HRtBQl8aTg+ZmzFUAvu4lsv3eLXMLGFxWk=
|
||||||
|
gopkg.in/yaml.v2 v2.0.0-20171116090243-287cf08546ab h1:yZ6iByf7GKeJ3gsd1Dr/xaj1DyJ//wxKX1Cdh8LhoAw=
|
||||||
|
gopkg.in/yaml.v2 v2.0.0-20171116090243-287cf08546ab/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
@ -29,7 +29,7 @@ func lazyInitBenchFileSet() {
|
|||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
files = append(files, protocol.FileInfo{
|
files = append(files, protocol.FileInfo{
|
||||||
Name: fmt.Sprintf("file%d", i),
|
Name: fmt.Sprintf("file%d", i),
|
||||||
Version: protocol.Vector{[]protocol.Counter{{ID: myID, Value: 1000}}},
|
Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}},
|
||||||
Blocks: genBlocks(i),
|
Blocks: genBlocks(i),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
//go:generate go run ../../script/protofmt.go structs.proto
|
//go:generate go run ../../script/protofmt.go structs.proto
|
||||||
//go:generate protoc -I ../../../../../ -I ../../vendor/ -I ../../vendor/github.com/gogo/protobuf/protobuf -I . --gogofast_out=. structs.proto
|
//go:generate protoc -I ../../ -I . --gogofast_out=Mlib/protocol/bep.proto=github.com/syncthing/syncthing/lib/protocol:. structs.proto
|
||||||
|
|
||||||
package db
|
package db
|
||||||
|
|
||||||
|
@ -1571,47 +1571,47 @@ var (
|
|||||||
func init() { proto.RegisterFile("structs.proto", fileDescriptorStructs) }
|
func init() { proto.RegisterFile("structs.proto", fileDescriptorStructs) }
|
||||||
|
|
||||||
var fileDescriptorStructs = []byte{
|
var fileDescriptorStructs = []byte{
|
||||||
// 671 bytes of a gzipped FileDescriptorProto
|
// 672 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x4d, 0x6b, 0xdb, 0x4c,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0x4d, 0x6f, 0xdb, 0x38,
|
||||||
0x10, 0xb6, 0x62, 0xf9, 0x6b, 0x6c, 0xe7, 0x4d, 0x96, 0x10, 0x84, 0xe1, 0xb5, 0x85, 0xa1, 0x20,
|
0x10, 0xb5, 0x62, 0xf9, 0x6b, 0x6c, 0x67, 0x13, 0x22, 0x08, 0x04, 0x03, 0x6b, 0x0b, 0x5e, 0x2c,
|
||||||
0x0a, 0xb5, 0xdb, 0x84, 0x5e, 0xda, 0x9b, 0x1a, 0x02, 0x86, 0xd2, 0x96, 0x75, 0xc8, 0xa9, 0x60,
|
0x20, 0xec, 0x41, 0xde, 0x26, 0xb7, 0xf6, 0xa6, 0x06, 0x01, 0x0c, 0x14, 0x6d, 0x41, 0x07, 0x39,
|
||||||
0xf4, 0xb1, 0x76, 0x96, 0xc8, 0x5a, 0x47, 0xbb, 0x4e, 0x50, 0x7e, 0x49, 0x8f, 0xf9, 0x39, 0x39,
|
0x15, 0x30, 0xf4, 0x41, 0x3b, 0x44, 0x64, 0xd1, 0x11, 0xe9, 0x04, 0xca, 0x2f, 0xe9, 0x31, 0x3f,
|
||||||
0xf6, 0xdc, 0x83, 0x49, 0xdd, 0x1e, 0xfa, 0x33, 0xca, 0xee, 0x4a, 0x8a, 0x9a, 0x53, 0x7b, 0x9b,
|
0x27, 0xc7, 0x9e, 0x7b, 0x30, 0x52, 0xb7, 0x87, 0xfe, 0x8c, 0x82, 0xa4, 0xa4, 0xa8, 0x39, 0xf5,
|
||||||
0x67, 0x3e, 0x76, 0x9e, 0x99, 0x79, 0x16, 0xba, 0x5c, 0x24, 0xeb, 0x40, 0xf0, 0xd1, 0x2a, 0x61,
|
0x36, 0xef, 0x71, 0xc8, 0x79, 0x33, 0xf3, 0x08, 0x7d, 0x2e, 0xd2, 0x4d, 0x28, 0xb8, 0xbb, 0x4e,
|
||||||
0x82, 0xa1, 0x9d, 0xd0, 0xef, 0xbd, 0x58, 0x50, 0x71, 0xb1, 0xf6, 0x47, 0x01, 0x5b, 0x8e, 0x17,
|
0x99, 0x60, 0x68, 0x2f, 0x0a, 0x06, 0xff, 0xa4, 0x64, 0xcd, 0xf8, 0x44, 0x11, 0xc1, 0x66, 0x31,
|
||||||
0x6c, 0xc1, 0xc6, 0x2a, 0xe4, 0xaf, 0xe7, 0x0a, 0x29, 0xa0, 0x2c, 0x5d, 0xd2, 0x7b, 0x5d, 0x4a,
|
0x59, 0xb2, 0x25, 0x53, 0x40, 0x45, 0x3a, 0x71, 0x70, 0x1c, 0xd3, 0x40, 0xa7, 0x84, 0x2c, 0x9e,
|
||||||
0xe7, 0x69, 0x1c, 0x88, 0x0b, 0x1a, 0x2f, 0x4a, 0x56, 0x44, 0x7d, 0xfd, 0x42, 0xc0, 0xa2, 0xb1,
|
0x04, 0x64, 0xad, 0xf9, 0xf1, 0x0d, 0x74, 0xcf, 0x69, 0x4c, 0x2e, 0x49, 0xca, 0x29, 0x4b, 0xd0,
|
||||||
0x4f, 0x56, 0xba, 0x6c, 0x78, 0x05, 0xed, 0x53, 0x1a, 0x91, 0x73, 0x92, 0x70, 0xca, 0x62, 0xf4,
|
0xff, 0xd0, 0xba, 0xd5, 0xa1, 0x65, 0xd8, 0x86, 0xd3, 0x3d, 0x39, 0x70, 0x8b, 0x4b, 0xee, 0x25,
|
||||||
0x12, 0x1a, 0xd7, 0xda, 0xb4, 0x0c, 0xdb, 0x70, 0xda, 0x47, 0x7b, 0xa3, 0xbc, 0x68, 0x74, 0x4e,
|
0x09, 0x05, 0x4b, 0x3d, 0xf3, 0x71, 0x3b, 0xaa, 0xe1, 0x22, 0x0d, 0x1d, 0x43, 0x33, 0x22, 0xb7,
|
||||||
0x02, 0xc1, 0x12, 0xd7, 0xbc, 0xdf, 0x0c, 0x2a, 0x38, 0x4f, 0x43, 0x87, 0x50, 0x0f, 0xc9, 0x35,
|
0x34, 0x24, 0xd6, 0x9e, 0x6d, 0x38, 0x3d, 0x9c, 0x23, 0x64, 0x41, 0x8b, 0x26, 0xb7, 0x7e, 0x4c,
|
||||||
0x0d, 0x88, 0xb5, 0x63, 0x1b, 0x4e, 0x07, 0x67, 0x08, 0x59, 0xd0, 0xa0, 0xf1, 0xb5, 0x17, 0xd1,
|
0x23, 0xab, 0x6e, 0x1b, 0x4e, 0x1b, 0x17, 0x70, 0x7c, 0x0e, 0xdd, 0xbc, 0xdc, 0x3b, 0xca, 0x05,
|
||||||
0xd0, 0xaa, 0xda, 0x86, 0xd3, 0xc4, 0x39, 0x1c, 0x9e, 0x42, 0x3b, 0x6b, 0xf7, 0x9e, 0x72, 0x81,
|
0x7a, 0x05, 0xed, 0xfc, 0x2d, 0x6e, 0x19, 0x76, 0xdd, 0xe9, 0x9e, 0xfc, 0xe5, 0x46, 0x81, 0x5b,
|
||||||
0x5e, 0x41, 0x33, 0x7b, 0x8b, 0x5b, 0x86, 0x5d, 0x75, 0xda, 0x47, 0xff, 0x8d, 0x42, 0x7f, 0x54,
|
0x51, 0x95, 0x97, 0x2c, 0xd3, 0x5e, 0x9b, 0x9f, 0x1f, 0x46, 0xb5, 0xf1, 0x93, 0x09, 0x87, 0x32,
|
||||||
0x62, 0x95, 0xb5, 0x2c, 0xd2, 0xde, 0x98, 0x5f, 0xee, 0x06, 0x95, 0xe1, 0x83, 0x09, 0xfb, 0x32,
|
0x6b, 0x9a, 0x2c, 0xd8, 0x45, 0xba, 0x49, 0x42, 0x5f, 0x90, 0x08, 0x21, 0x30, 0x13, 0x7f, 0x45,
|
||||||
0x6b, 0x12, 0xcf, 0xd9, 0x59, 0xb2, 0x8e, 0x03, 0x4f, 0x90, 0x10, 0x21, 0x30, 0x63, 0x6f, 0x49,
|
0x94, 0xfc, 0x0e, 0x56, 0x31, 0xfa, 0x0f, 0x4c, 0x91, 0xad, 0xb5, 0xc2, 0xfd, 0x93, 0xe3, 0xe7,
|
||||||
0x14, 0xfd, 0x16, 0x56, 0x36, 0x7a, 0x0e, 0xa6, 0x48, 0x57, 0x9a, 0xe1, 0xee, 0xd1, 0xe1, 0xe3,
|
0x96, 0xca, 0xeb, 0xd9, 0x9a, 0x60, 0x95, 0x23, 0xef, 0x73, 0x7a, 0x4f, 0x94, 0xe8, 0x3a, 0x56,
|
||||||
0x48, 0x45, 0x79, 0xba, 0x22, 0x58, 0xe5, 0xc8, 0x7a, 0x4e, 0x6f, 0x89, 0x22, 0x5d, 0xc5, 0xca,
|
0x31, 0xb2, 0xa1, 0xbb, 0x26, 0xe9, 0x8a, 0x72, 0xad, 0xd2, 0xb4, 0x0d, 0xa7, 0x8f, 0xab, 0x14,
|
||||||
0x46, 0x36, 0xb4, 0x57, 0x24, 0x59, 0x52, 0xae, 0x59, 0x9a, 0xb6, 0xe1, 0x74, 0x71, 0xd9, 0x85,
|
0xfa, 0x1b, 0x60, 0xc5, 0x22, 0xba, 0xa0, 0x24, 0x9a, 0x73, 0xab, 0xa1, 0xee, 0x76, 0x0a, 0x66,
|
||||||
0xfe, 0x07, 0x58, 0xb2, 0x90, 0xce, 0x29, 0x09, 0x67, 0xdc, 0xaa, 0xa9, 0xda, 0x56, 0xee, 0x99,
|
0x26, 0x87, 0x11, 0x91, 0x98, 0x08, 0x12, 0x59, 0x4d, 0x3d, 0x8c, 0x1c, 0x22, 0xe7, 0x79, 0x4c,
|
||||||
0xca, 0x65, 0x84, 0x24, 0x22, 0x82, 0x84, 0x56, 0x5d, 0x2f, 0x23, 0x83, 0xc8, 0x79, 0x5c, 0x53,
|
0x2d, 0x79, 0xe2, 0xed, 0xef, 0xb6, 0x23, 0xc0, 0xfe, 0xdd, 0x54, 0xb3, 0xe5, 0xd8, 0xd0, 0xbf,
|
||||||
0x43, 0x46, 0xdc, 0xdd, 0xed, 0x66, 0x00, 0xd8, 0xbb, 0x99, 0x68, 0x6f, 0xb1, 0x36, 0xf4, 0x0c,
|
0xb0, 0x9f, 0xb0, 0x79, 0x55, 0x47, 0x5b, 0x3d, 0xd5, 0x4f, 0xd8, 0xc7, 0x8a, 0x92, 0xca, 0x06,
|
||||||
0x76, 0x63, 0x36, 0x2b, 0xf3, 0x68, 0xaa, 0xa7, 0xba, 0x31, 0xfb, 0x54, 0x62, 0x52, 0xba, 0x60,
|
0x3b, 0x7f, 0xb6, 0xc1, 0x01, 0xb4, 0x39, 0xb9, 0xd9, 0x90, 0x24, 0x24, 0x16, 0x28, 0xe5, 0x25,
|
||||||
0xeb, 0xef, 0x2e, 0xd8, 0x83, 0x26, 0x27, 0x57, 0x6b, 0x12, 0x07, 0xc4, 0x02, 0xc5, 0xbc, 0xc0,
|
0x46, 0x23, 0xe8, 0x96, 0x7d, 0x25, 0xdc, 0xea, 0xda, 0x86, 0xd3, 0xc0, 0x65, 0xab, 0xef, 0x39,
|
||||||
0x68, 0x00, 0xed, 0x62, 0xae, 0x98, 0x5b, 0x6d, 0xdb, 0x70, 0x6a, 0xb8, 0x18, 0xf5, 0x03, 0x47,
|
0xfa, 0x54, 0x49, 0x08, 0x32, 0xab, 0x67, 0x1b, 0x8e, 0xe9, 0xbd, 0x91, 0x05, 0xbe, 0x6e, 0x47,
|
||||||
0x9f, 0x4b, 0x09, 0x7e, 0x6a, 0x75, 0x6c, 0xc3, 0x31, 0xdd, 0xb7, 0xb2, 0xc1, 0xb7, 0xcd, 0xe0,
|
0xa7, 0x4b, 0x2a, 0xae, 0x36, 0x81, 0x1b, 0xb2, 0xd5, 0x84, 0x67, 0x49, 0x28, 0xae, 0x68, 0xb2,
|
||||||
0xf8, 0x1f, 0x34, 0x39, 0x9a, 0x5e, 0xb0, 0x44, 0x4c, 0x4e, 0x1e, 0x5f, 0x77, 0x53, 0x34, 0x06,
|
0xac, 0x44, 0x55, 0x4f, 0xba, 0xb3, 0x2b, 0x96, 0x8a, 0xe9, 0xd9, 0xf3, 0xeb, 0x5e, 0x86, 0x26,
|
||||||
0xf0, 0x23, 0x16, 0x5c, 0xce, 0xd4, 0x49, 0xba, 0xb2, 0xbb, 0xbb, 0xb7, 0xdd, 0x0c, 0x3a, 0xd8,
|
0x00, 0x41, 0xcc, 0xc2, 0xeb, 0xb9, 0x5a, 0x49, 0x5f, 0x56, 0xf7, 0x0e, 0x76, 0xdb, 0x51, 0x0f,
|
||||||
0xbb, 0x71, 0x65, 0x60, 0x4a, 0x6f, 0x09, 0x6e, 0xf9, 0xb9, 0x29, 0x97, 0xc4, 0xd3, 0x65, 0x44,
|
0xfb, 0x77, 0x9e, 0x3c, 0x98, 0xd1, 0x7b, 0x82, 0x3b, 0x41, 0x11, 0xca, 0x21, 0xf1, 0x6c, 0x15,
|
||||||
0xe3, 0xcb, 0x99, 0xf0, 0x92, 0x05, 0x11, 0xd6, 0xbe, 0xd2, 0x41, 0x37, 0xf3, 0x9e, 0x29, 0xa7,
|
0xd3, 0xe4, 0x7a, 0x2e, 0xfc, 0x74, 0x49, 0x84, 0x75, 0xa8, 0x7c, 0xd0, 0xcf, 0xd9, 0x0b, 0x45,
|
||||||
0x3c, 0x68, 0xc4, 0x02, 0x2f, 0x9a, 0xcd, 0x23, 0x6f, 0xc1, 0xad, 0x5f, 0x0d, 0x75, 0x51, 0x50,
|
0xca, 0x85, 0xc6, 0x2c, 0xf4, 0xe3, 0xf9, 0x22, 0xf6, 0x97, 0xdc, 0xfa, 0xd9, 0x52, 0x1b, 0x05,
|
||||||
0xbe, 0x53, 0xe9, 0xca, 0x24, 0xf6, 0xd3, 0x80, 0xfa, 0x3b, 0xb6, 0x8e, 0x05, 0x47, 0x07, 0x50,
|
0xc5, 0x9d, 0x4b, 0x2a, 0xb7, 0xd8, 0x0f, 0x03, 0x9a, 0x6f, 0xd9, 0x26, 0x11, 0x1c, 0x1d, 0x41,
|
||||||
0x9b, 0xd3, 0x88, 0x70, 0x25, 0xac, 0x1a, 0xd6, 0x40, 0x3e, 0x14, 0xd2, 0x44, 0xad, 0x95, 0x12,
|
0x63, 0x41, 0x63, 0xc2, 0x95, 0xb1, 0x1a, 0x58, 0x03, 0xf9, 0x50, 0x44, 0x53, 0x35, 0x56, 0x4a,
|
||||||
0xae, 0x04, 0x56, 0xc3, 0x65, 0x97, 0xda, 0xae, 0xee, 0xcd, 0x95, 0xa6, 0x6a, 0xb8, 0xc0, 0x65,
|
0xb8, 0x32, 0x58, 0x03, 0x57, 0x29, 0x35, 0x5d, 0x5d, 0x9b, 0x2b, 0x4f, 0x35, 0x70, 0x89, 0xab,
|
||||||
0x59, 0x98, 0x2a, 0x54, 0xc8, 0xe2, 0x00, 0x6a, 0x7e, 0x2a, 0x48, 0x2e, 0x25, 0x0d, 0xfe, 0xb8,
|
0xb6, 0x30, 0xd5, 0x51, 0x69, 0x8b, 0x23, 0x68, 0x04, 0x99, 0x20, 0x85, 0x95, 0x34, 0xf8, 0x6d,
|
||||||
0x54, 0xfd, 0xc9, 0xa5, 0x7a, 0xd0, 0xd4, 0x3f, 0x6f, 0x72, 0xa2, 0x66, 0xee, 0xe0, 0x02, 0xa3,
|
0x53, 0xcd, 0x17, 0x9b, 0x1a, 0x40, 0x5b, 0xff, 0xbc, 0xe9, 0x99, 0xea, 0xb9, 0x87, 0x4b, 0x8c,
|
||||||
0x3e, 0x94, 0x46, 0xb3, 0xd0, 0xd3, 0x61, 0x87, 0x1f, 0xa1, 0xa5, 0xa7, 0x9c, 0x12, 0x81, 0x1c,
|
0x86, 0x50, 0x69, 0xcd, 0x42, 0x2f, 0x9b, 0x1d, 0x7f, 0x80, 0x8e, 0xee, 0x72, 0x46, 0x04, 0x72,
|
||||||
0xa8, 0x07, 0x0a, 0x64, 0xbf, 0x11, 0xe4, 0x6f, 0xd4, 0xe1, 0x4c, 0x39, 0x59, 0x5c, 0xd2, 0x0f,
|
0xa0, 0x19, 0x2a, 0x90, 0xff, 0x46, 0x90, 0xbf, 0x51, 0x1f, 0xe7, 0xce, 0xc9, 0xcf, 0xa5, 0xfc,
|
||||||
0x12, 0x22, 0x7f, 0x9d, 0x1a, 0xbc, 0x8a, 0x73, 0xe8, 0x1e, 0xdc, 0x7f, 0xef, 0x57, 0xee, 0xb7,
|
0x30, 0x25, 0xf2, 0xd7, 0xa9, 0xc6, 0xeb, 0xb8, 0x80, 0xde, 0xd1, 0xe3, 0xb7, 0x61, 0xed, 0x71,
|
||||||
0x7d, 0xe3, 0xeb, 0xb6, 0x6f, 0x3c, 0x6c, 0xfb, 0x95, 0xbb, 0x1f, 0x7d, 0xc3, 0xaf, 0xab, 0x5b,
|
0x37, 0x34, 0xbe, 0xec, 0x86, 0xc6, 0xd3, 0x6e, 0x58, 0x7b, 0xf8, 0x3e, 0x34, 0x82, 0xa6, 0xda,
|
||||||
0x1f, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xc4, 0x4d, 0xd7, 0x14, 0xed, 0x04, 0x00, 0x00,
|
0xf5, 0xe9, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x08, 0x8f, 0xd2, 0xdf, 0xc4, 0x04, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ syntax = "proto3";
|
|||||||
|
|
||||||
package db;
|
package db;
|
||||||
|
|
||||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
import "repos/protobuf/gogoproto/gogo.proto";
|
||||||
import "github.com/syncthing/syncthing/lib/protocol/bep.proto";
|
import "lib/protocol/bep.proto";
|
||||||
|
|
||||||
option (gogoproto.goproto_getters_all) = false;
|
option (gogoproto.goproto_getters_all) = false;
|
||||||
option (gogoproto.sizer_all) = false;
|
option (gogoproto.sizer_all) = false;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
//go:generate go run ../../script/protofmt.go local.proto
|
//go:generate go run ../../script/protofmt.go local.proto
|
||||||
//go:generate protoc -I ../../vendor/ -I ../../vendor/github.com/gogo/protobuf/protobuf -I . --gogofast_out=. local.proto
|
//go:generate protoc -I ../../ -I . --gogofast_out=. local.proto
|
||||||
|
|
||||||
package discover
|
package discover
|
||||||
|
|
||||||
|
@ -386,20 +386,20 @@ func init() { proto.RegisterFile("local.proto", fileDescriptorLocal) }
|
|||||||
|
|
||||||
var fileDescriptorLocal = []byte{
|
var fileDescriptorLocal = []byte{
|
||||||
// 241 bytes of a gzipped FileDescriptorProto
|
// 241 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x8e, 0x4f, 0x4e, 0x84, 0x30,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x8e, 0x31, 0x4e, 0x84, 0x40,
|
||||||
0x14, 0xc6, 0x29, 0x24, 0x66, 0xa6, 0x63, 0x5c, 0x10, 0x17, 0xc4, 0x98, 0x42, 0x5c, 0xb1, 0x11,
|
0x14, 0x86, 0x19, 0x48, 0xcc, 0xee, 0xac, 0xb1, 0x20, 0x16, 0xc4, 0x98, 0x81, 0x68, 0x43, 0x05,
|
||||||
0x16, 0x7a, 0x01, 0x09, 0x9b, 0x6e, 0xb9, 0x80, 0x81, 0xb6, 0x32, 0x2f, 0xc1, 0x3e, 0x43, 0x61,
|
0x85, 0x5e, 0x40, 0x42, 0x33, 0x2d, 0x17, 0x30, 0x30, 0xf3, 0x64, 0x5f, 0x82, 0xf3, 0x36, 0x0c,
|
||||||
0x12, 0x6f, 0xe3, 0x05, 0xbc, 0x07, 0x4b, 0xd7, 0x2e, 0x1a, 0xad, 0x17, 0x31, 0xe9, 0x68, 0x86,
|
0x6c, 0xe2, 0x6d, 0xbc, 0x80, 0xf7, 0xa0, 0xb4, 0xb6, 0x20, 0x3a, 0x5e, 0xc4, 0x04, 0x34, 0x6e,
|
||||||
0xdd, 0xf7, 0xfd, 0xf2, 0x7b, 0x7f, 0xe8, 0x6e, 0x40, 0xd1, 0x0e, 0xc5, 0xcb, 0x88, 0x13, 0xc6,
|
0xf7, 0xbd, 0x2f, 0x5f, 0xf2, 0x7e, 0xbe, 0xeb, 0x48, 0xd5, 0x5d, 0x76, 0xe8, 0x69, 0xa0, 0x70,
|
||||||
0x1b, 0x09, 0x46, 0xe0, 0x41, 0x8d, 0x57, 0xb7, 0x3d, 0x4c, 0xfb, 0xb9, 0x2b, 0x04, 0x3e, 0x97,
|
0xa3, 0xd1, 0x2a, 0x3a, 0x42, 0x7f, 0x75, 0xdb, 0xc3, 0x81, 0x6c, 0xbe, 0xe8, 0x66, 0x7c, 0xca,
|
||||||
0x3d, 0xf6, 0x58, 0x7a, 0xa1, 0x9b, 0x9f, 0x7c, 0xf3, 0xc5, 0xa7, 0xe3, 0xe0, 0xcd, 0x3b, 0xa1,
|
0x5b, 0x6a, 0x69, 0x39, 0x16, 0x5a, 0xf3, 0x9b, 0x37, 0xc6, 0x37, 0x0f, 0xc6, 0xd0, 0x68, 0x14,
|
||||||
0x9b, 0x07, 0xad, 0x71, 0xd6, 0x42, 0xc5, 0x0d, 0x0d, 0x41, 0x26, 0x24, 0x23, 0xf9, 0x79, 0x55,
|
0x84, 0x15, 0xf7, 0x51, 0x47, 0x2c, 0x61, 0xe9, 0x79, 0x51, 0x4c, 0x73, 0xec, 0x7d, 0xcc, 0xf1,
|
||||||
0x2d, 0x36, 0x0d, 0x3e, 0x6d, 0x7a, 0xbf, 0xda, 0x67, 0x5e, 0xb5, 0x98, 0xf6, 0xa0, 0xfb, 0x55,
|
0x7d, 0x8b, 0xc3, 0x7e, 0x6c, 0x32, 0x45, 0xcf, 0xb9, 0x7d, 0x31, 0x6a, 0xd8, 0xa3, 0x69, 0x4f,
|
||||||
0x1a, 0xa0, 0x3b, 0x9e, 0x10, 0x38, 0x14, 0xb5, 0x3a, 0x80, 0x50, 0xbc, 0x76, 0x36, 0x0d, 0x79,
|
0xa8, 0xc3, 0x66, 0x7d, 0xa1, 0xa8, 0xcb, 0x4a, 0x38, 0xa2, 0x02, 0x59, 0xba, 0x39, 0xf6, 0x65,
|
||||||
0xdd, 0x84, 0x20, 0xe3, 0x6b, 0xba, 0x6d, 0xa5, 0x1c, 0x95, 0x31, 0xca, 0x24, 0x61, 0x16, 0xe5,
|
0x59, 0xf9, 0xa8, 0xc3, 0x6b, 0xbe, 0xad, 0xb5, 0xee, 0xc1, 0x5a, 0xb0, 0x91, 0x9f, 0x04, 0xe9,
|
||||||
0xdb, 0xe6, 0x04, 0xe2, 0x92, 0xee, 0x40, 0x9b, 0xa9, 0xd5, 0x42, 0x3d, 0x82, 0x4c, 0xa2, 0x8c,
|
0xb6, 0xfa, 0x17, 0x61, 0xce, 0x77, 0x68, 0xec, 0x50, 0x1b, 0x05, 0x8f, 0xa8, 0xa3, 0x20, 0x61,
|
||||||
0xe4, 0x51, 0x75, 0xe1, 0x6c, 0x4a, 0xf9, 0x1f, 0xe6, 0x75, 0x43, 0xff, 0x15, 0x2e, 0xab, 0xcb,
|
0x69, 0x50, 0x5c, 0xb8, 0x39, 0xe6, 0xf2, 0x57, 0xcb, 0xb2, 0xe2, 0x7f, 0x89, 0xd4, 0xc5, 0xe5,
|
||||||
0xe5, 0x9b, 0x05, 0x8b, 0x63, 0xe4, 0xc3, 0x31, 0xf2, 0xe5, 0x58, 0xf0, 0xf6, 0xc3, 0x48, 0x77,
|
0xf4, 0x25, 0xbc, 0xc9, 0x09, 0xf6, 0xee, 0x04, 0xfb, 0x74, 0xc2, 0x7b, 0xfd, 0x16, 0xac, 0x39,
|
||||||
0xe6, 0x3f, 0xb8, 0xfb, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xa4, 0x46, 0x4f, 0x13, 0x14, 0x01, 0x00,
|
0x5b, 0x16, 0xdc, 0xfd, 0x04, 0x00, 0x00, 0xff, 0xff, 0x6f, 0x5a, 0xdf, 0xed, 0x0a, 0x01, 0x00,
|
||||||
0x00,
|
0x00,
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ syntax = "proto3";
|
|||||||
|
|
||||||
package discover;
|
package discover;
|
||||||
|
|
||||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
import "repos/protobuf/gogoproto/gogo.proto";
|
||||||
|
|
||||||
option (gogoproto.goproto_getters_all) = false;
|
option (gogoproto.goproto_getters_all) = false;
|
||||||
option (gogoproto.sizer_all) = false;
|
option (gogoproto.sizer_all) = false;
|
||||||
|
@ -4254,118 +4254,117 @@ var (
|
|||||||
func init() { proto.RegisterFile("bep.proto", fileDescriptorBep) }
|
func init() { proto.RegisterFile("bep.proto", fileDescriptorBep) }
|
||||||
|
|
||||||
var fileDescriptorBep = []byte{
|
var fileDescriptorBep = []byte{
|
||||||
// 1793 bytes of a gzipped FileDescriptorProto
|
// 1787 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x4f, 0x73, 0xdb, 0xc6,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x4f, 0x73, 0xdb, 0xc6,
|
||||||
0x15, 0x17, 0x48, 0xf0, 0xdf, 0x23, 0xa5, 0x40, 0x6b, 0x5b, 0x45, 0x11, 0x85, 0x84, 0x19, 0x3b,
|
0x15, 0x17, 0x48, 0x90, 0x04, 0x1f, 0x29, 0x05, 0xda, 0xd8, 0x2a, 0x8a, 0x28, 0x24, 0x4c, 0xdb,
|
||||||
0x56, 0x34, 0x89, 0xec, 0x26, 0x69, 0x3b, 0xed, 0xb4, 0x9d, 0xe1, 0x1f, 0x48, 0xe6, 0x54, 0x26,
|
0xb1, 0xa2, 0x49, 0x6d, 0x37, 0x49, 0xdb, 0x69, 0xa7, 0xed, 0x0c, 0xff, 0x40, 0x32, 0xa7, 0x32,
|
||||||
0xd9, 0x25, 0xe5, 0xd4, 0x39, 0x14, 0x03, 0x12, 0x4b, 0x0a, 0x63, 0x10, 0xcb, 0x02, 0xa0, 0x64,
|
0xa8, 0x2e, 0x29, 0xa7, 0xce, 0xa1, 0x18, 0x88, 0x58, 0x4a, 0x18, 0x83, 0x58, 0x16, 0x00, 0x25,
|
||||||
0xe6, 0x23, 0xf0, 0x13, 0xf4, 0xc2, 0x99, 0xcc, 0xf4, 0xd4, 0x6f, 0xe2, 0x63, 0xda, 0x43, 0x0f,
|
0x33, 0x1f, 0x81, 0x9f, 0xa0, 0x17, 0xce, 0x64, 0xa6, 0xa7, 0x7e, 0x13, 0x1f, 0xd3, 0x1e, 0x7a,
|
||||||
0x3d, 0x68, 0x1a, 0xf5, 0x92, 0x63, 0x3f, 0x41, 0xa7, 0xb3, 0xbb, 0x00, 0x09, 0x4a, 0x76, 0xc6,
|
0xe8, 0x41, 0xd3, 0xa8, 0x97, 0x1c, 0xfb, 0x09, 0x3a, 0x9d, 0xdd, 0x05, 0x48, 0x50, 0xb2, 0x33,
|
||||||
0x87, 0x9c, 0xb8, 0xfb, 0xde, 0x6f, 0xdf, 0xf2, 0xfd, 0xde, 0xef, 0xbd, 0x05, 0x14, 0x06, 0x64,
|
0x39, 0xf4, 0x84, 0xdd, 0xf7, 0x7e, 0xbb, 0x8b, 0xf7, 0x7b, 0xbf, 0xf7, 0x76, 0xa1, 0x7c, 0x4a,
|
||||||
0x7a, 0x34, 0xf5, 0x69, 0x48, 0x51, 0x9e, 0xff, 0x0c, 0xa9, 0xab, 0x7d, 0x3a, 0x76, 0xc2, 0xf3,
|
0x26, 0x8f, 0x27, 0x21, 0x8d, 0x29, 0x52, 0xf8, 0x67, 0x48, 0x7d, 0xfd, 0x7e, 0x48, 0x26, 0x34,
|
||||||
0xd9, 0xe0, 0x68, 0x48, 0x27, 0x8f, 0xc7, 0x74, 0x4c, 0x1f, 0x73, 0xcf, 0x60, 0x36, 0xe2, 0x3b,
|
0x7a, 0xc2, 0xe7, 0xa7, 0xd3, 0xd1, 0x93, 0x33, 0x7a, 0x46, 0xf9, 0x84, 0x8f, 0x04, 0xbc, 0x31,
|
||||||
0xbe, 0xe1, 0x2b, 0x71, 0xb0, 0x3a, 0x85, 0xcc, 0x53, 0xe2, 0xba, 0x14, 0x55, 0xa0, 0x68, 0x93,
|
0x81, 0xc2, 0x33, 0xe2, 0xfb, 0x14, 0xd5, 0xa1, 0xe2, 0x92, 0x0b, 0x6f, 0x48, 0xec, 0xc0, 0x19,
|
||||||
0x0b, 0x67, 0x48, 0x4c, 0xcf, 0x9a, 0x10, 0x55, 0xd2, 0xa5, 0x83, 0x02, 0x06, 0x61, 0x6a, 0x5b,
|
0x13, 0x4d, 0x32, 0xa4, 0xbd, 0x32, 0x06, 0x61, 0xb2, 0x9c, 0x31, 0x61, 0x80, 0xa1, 0xef, 0x91,
|
||||||
0x13, 0xc2, 0x00, 0x43, 0xd7, 0x21, 0x5e, 0x28, 0x00, 0x29, 0x01, 0x10, 0x26, 0x0e, 0x78, 0x08,
|
0x20, 0x16, 0x80, 0x9c, 0x00, 0x08, 0x13, 0x07, 0x3c, 0x84, 0xad, 0x04, 0x70, 0x41, 0xc2, 0xc8,
|
||||||
0x3b, 0x11, 0xe0, 0x82, 0xf8, 0x81, 0x43, 0x3d, 0x35, 0xcd, 0x31, 0xdb, 0xc2, 0xfa, 0x5c, 0x18,
|
0xa3, 0x81, 0x96, 0xe7, 0x98, 0x4d, 0x61, 0x7d, 0x21, 0x8c, 0x8d, 0x08, 0x8a, 0xcf, 0x88, 0xe3,
|
||||||
0xab, 0x01, 0x64, 0x9f, 0x12, 0xcb, 0x26, 0x3e, 0xfa, 0x18, 0xe4, 0x70, 0x3e, 0x15, 0x77, 0xed,
|
0x92, 0x10, 0x7d, 0x0c, 0x72, 0x3c, 0x9b, 0x88, 0xb3, 0xb6, 0x3e, 0xbd, 0xfb, 0x38, 0xfd, 0xf3,
|
||||||
0x7c, 0x76, 0xef, 0x28, 0xce, 0xe1, 0xe8, 0x19, 0x09, 0x02, 0x6b, 0x4c, 0xfa, 0xf3, 0x29, 0xc1,
|
0xc7, 0xcf, 0x49, 0x14, 0x39, 0x67, 0x64, 0x30, 0x9b, 0x10, 0xcc, 0x21, 0xe8, 0xb7, 0x50, 0x19,
|
||||||
0x1c, 0x82, 0x7e, 0x07, 0xc5, 0x21, 0x9d, 0x4c, 0x7d, 0x12, 0xf0, 0xc0, 0x29, 0x7e, 0x62, 0xff,
|
0xd2, 0xf1, 0x24, 0x24, 0x11, 0xdf, 0x38, 0xc7, 0x57, 0xec, 0xde, 0x5a, 0xd1, 0x5e, 0x61, 0x70,
|
||||||
0xd6, 0x89, 0xc6, 0x1a, 0x83, 0x93, 0x07, 0xaa, 0x35, 0xd8, 0x6e, 0xb8, 0xb3, 0x20, 0x24, 0x7e,
|
0x76, 0x41, 0xa3, 0x09, 0x9b, 0x6d, 0x7f, 0x1a, 0xc5, 0x24, 0x6c, 0xd3, 0x60, 0xe4, 0x9d, 0xa1,
|
||||||
0x83, 0x7a, 0x23, 0x67, 0x8c, 0x9e, 0x40, 0x6e, 0x44, 0x5d, 0x9b, 0xf8, 0x81, 0x2a, 0xe9, 0xe9,
|
0xa7, 0x50, 0x1a, 0x51, 0xdf, 0x25, 0x61, 0xa4, 0x49, 0x46, 0x7e, 0xaf, 0xf2, 0xa9, 0xba, 0xda,
|
||||||
0x83, 0xe2, 0x67, 0xca, 0x3a, 0xd8, 0x31, 0x77, 0xd4, 0xe5, 0xd7, 0x57, 0x95, 0x2d, 0x1c, 0xc3,
|
0xec, 0x80, 0x3b, 0x5a, 0xf2, 0x9b, 0xab, 0xfa, 0x06, 0x4e, 0x61, 0x8d, 0xbf, 0xe4, 0xa0, 0x28,
|
||||||
0xaa, 0x7f, 0x4d, 0x41, 0x56, 0x78, 0xd0, 0x1e, 0xa4, 0x1c, 0x5b, 0x50, 0x54, 0xcf, 0x5e, 0x5f,
|
0x3c, 0x68, 0x07, 0x72, 0x9e, 0x2b, 0x28, 0x6a, 0x15, 0xaf, 0xaf, 0xea, 0xb9, 0x6e, 0x07, 0xe7,
|
||||||
0x55, 0x52, 0xad, 0x26, 0x4e, 0x39, 0x36, 0xba, 0x0b, 0x19, 0xd7, 0x1a, 0x10, 0x37, 0x22, 0x47,
|
0x3c, 0x17, 0xdd, 0x81, 0x82, 0xef, 0x9c, 0x12, 0x3f, 0x21, 0x47, 0x4c, 0xd0, 0x07, 0x50, 0x0e,
|
||||||
0x6c, 0xd0, 0xfb, 0x50, 0xf0, 0x89, 0x65, 0x9b, 0xd4, 0x73, 0xe7, 0x9c, 0x92, 0x3c, 0xce, 0x33,
|
0x89, 0xe3, 0xda, 0x34, 0xf0, 0x67, 0x9c, 0x12, 0x05, 0x2b, 0xcc, 0xd0, 0x0b, 0xfc, 0x19, 0xfa,
|
||||||
0x43, 0xc7, 0x73, 0xe7, 0xe8, 0x53, 0x40, 0xce, 0xd8, 0xa3, 0x3e, 0x31, 0xa7, 0xc4, 0x9f, 0x38,
|
0x09, 0x20, 0xef, 0x2c, 0xa0, 0x21, 0xb1, 0x27, 0x24, 0x1c, 0x7b, 0xfc, 0x6f, 0x23, 0x4d, 0xe6,
|
||||||
0xfc, 0xdf, 0x06, 0xaa, 0xcc, 0x51, 0xbb, 0xc2, 0xd3, 0x5d, 0x3b, 0xd0, 0x87, 0xb0, 0x1d, 0xc1,
|
0xa8, 0x6d, 0xe1, 0x39, 0x5e, 0x39, 0xd0, 0x7d, 0xd8, 0x4c, 0xe0, 0x2e, 0xf1, 0x49, 0x4c, 0xb4,
|
||||||
0x6d, 0xe2, 0x92, 0x90, 0xa8, 0x19, 0x8e, 0x2c, 0x09, 0x63, 0x93, 0xdb, 0xd0, 0x13, 0xb8, 0x6b,
|
0x02, 0x47, 0x56, 0x85, 0xb1, 0xc3, 0x6d, 0xe8, 0x29, 0xdc, 0x71, 0xbd, 0xc8, 0x39, 0xf5, 0x89,
|
||||||
0x3b, 0x81, 0x35, 0x70, 0x89, 0x19, 0x92, 0xc9, 0xd4, 0x74, 0x3c, 0x9b, 0xbc, 0x22, 0x81, 0x9a,
|
0x1d, 0x93, 0xf1, 0xc4, 0xf6, 0x02, 0x97, 0xbc, 0x26, 0x91, 0x56, 0xe4, 0x58, 0x94, 0xf8, 0x06,
|
||||||
0xe5, 0x58, 0x14, 0xf9, 0xfa, 0x64, 0x32, 0x6d, 0x09, 0x0f, 0xda, 0x83, 0xec, 0xd4, 0x9a, 0x05,
|
0x64, 0x3c, 0xe9, 0x0a, 0x0f, 0xda, 0x81, 0xe2, 0xc4, 0x99, 0x46, 0xc4, 0xd5, 0x4a, 0x1c, 0x93,
|
||||||
0xc4, 0x56, 0x73, 0x1c, 0x13, 0xed, 0x18, 0x4b, 0x42, 0x01, 0x81, 0xaa, 0xdc, 0x64, 0xa9, 0xc9,
|
0xcc, 0x18, 0x4b, 0x42, 0x01, 0x91, 0xa6, 0xde, 0x64, 0xa9, 0xc3, 0x1d, 0x29, 0x4b, 0x09, 0xac,
|
||||||
0x1d, 0x31, 0x4b, 0x11, 0xac, 0xfa, 0xdf, 0x14, 0x64, 0x85, 0x07, 0x7d, 0xb4, 0x62, 0xa9, 0x54,
|
0xf1, 0x9f, 0x1c, 0x14, 0x85, 0x07, 0x7d, 0xb4, 0x64, 0xa9, 0xda, 0xda, 0x61, 0xa8, 0x7f, 0x5e,
|
||||||
0xdf, 0x63, 0xa8, 0x7f, 0x5d, 0x55, 0xf2, 0xc2, 0xd7, 0x6a, 0x26, 0x58, 0x43, 0x20, 0x27, 0x14,
|
0xd5, 0x15, 0xe1, 0xeb, 0x76, 0x32, 0xac, 0x21, 0x90, 0x33, 0x8a, 0xe2, 0x63, 0xb4, 0x0b, 0x65,
|
||||||
0xc5, 0xd7, 0x68, 0x1f, 0x0a, 0x96, 0x6d, 0xb3, 0xea, 0x91, 0x40, 0x4d, 0xeb, 0xe9, 0x83, 0x02,
|
0xc7, 0x75, 0x59, 0xf6, 0x48, 0xa4, 0xe5, 0x8d, 0xfc, 0x5e, 0x19, 0xaf, 0x0c, 0xe8, 0x17, 0xeb,
|
||||||
0x5e, 0x1b, 0xd0, 0x2f, 0x37, 0xd5, 0x20, 0xdf, 0xd4, 0xcf, 0xdb, 0x64, 0xc0, 0x4a, 0x31, 0x24,
|
0x6a, 0x90, 0x6f, 0xea, 0xe7, 0x5d, 0x32, 0x60, 0xa9, 0x18, 0x92, 0x30, 0x51, 0x70, 0x81, 0x9f,
|
||||||
0x7e, 0xa4, 0xe0, 0x0c, 0xbf, 0x2f, 0xcf, 0x0c, 0x5c, 0xbf, 0xf7, 0xa1, 0x34, 0xb1, 0x5e, 0x99,
|
0xa7, 0x30, 0x03, 0xd7, 0xef, 0x3d, 0xa8, 0x8e, 0x9d, 0xd7, 0x76, 0x44, 0xfe, 0x34, 0x25, 0xc1,
|
||||||
0x01, 0xf9, 0xf3, 0x8c, 0x78, 0x43, 0xc2, 0xe9, 0x4a, 0xe3, 0xe2, 0xc4, 0x7a, 0xd5, 0x8b, 0x4c,
|
0x90, 0x70, 0xba, 0xf2, 0xb8, 0x32, 0x76, 0x5e, 0xf7, 0x13, 0x13, 0xaa, 0x01, 0x78, 0x41, 0x1c,
|
||||||
0xa8, 0x0c, 0xe0, 0x78, 0xa1, 0x4f, 0xed, 0xd9, 0x90, 0xf8, 0x11, 0x57, 0x09, 0x0b, 0xfa, 0x39,
|
0x52, 0x77, 0x3a, 0x24, 0x61, 0xc2, 0x55, 0xc6, 0x82, 0x7e, 0x06, 0x0a, 0x27, 0xdb, 0xf6, 0x5c,
|
||||||
0xe4, 0x39, 0xd9, 0xa6, 0x63, 0xab, 0x79, 0x5d, 0x3a, 0x90, 0xeb, 0x5a, 0x94, 0x78, 0x8e, 0x53,
|
0x4d, 0x31, 0xa4, 0x3d, 0xb9, 0xa5, 0x27, 0x81, 0x97, 0x38, 0xd5, 0x3c, 0xee, 0x74, 0x88, 0x4b,
|
||||||
0xcd, 0xf3, 0x8e, 0x97, 0x38, 0xc7, 0xb1, 0x2d, 0x1b, 0xfd, 0x06, 0xb4, 0xe0, 0xa5, 0xc3, 0x0a,
|
0x1c, 0xdb, 0x75, 0xd1, 0xaf, 0x41, 0x8f, 0x5e, 0x79, 0x2c, 0x51, 0x62, 0xa7, 0xd8, 0xa3, 0x81,
|
||||||
0x25, 0x22, 0x85, 0x0e, 0xf5, 0x4c, 0x9f, 0x4c, 0xe8, 0x85, 0xe5, 0x06, 0x6a, 0x81, 0x5f, 0xa3,
|
0x1d, 0x92, 0x31, 0xbd, 0x70, 0xfc, 0x48, 0x2b, 0xf3, 0x63, 0x34, 0x86, 0xe8, 0x66, 0x00, 0x38,
|
||||||
0x32, 0x44, 0x2b, 0x01, 0xc0, 0x91, 0xbf, 0xda, 0x81, 0x0c, 0x8f, 0xc8, 0xaa, 0x28, 0xc4, 0x1a,
|
0xf1, 0x37, 0x7a, 0x50, 0xe0, 0x3b, 0xb2, 0x2c, 0x0a, 0xb1, 0x26, 0xd5, 0x9b, 0xcc, 0xd0, 0x63,
|
||||||
0x75, 0x6f, 0xb4, 0x43, 0x47, 0x90, 0x19, 0x39, 0x2e, 0x09, 0xd4, 0x14, 0xaf, 0x21, 0x4a, 0x28,
|
0x28, 0x8c, 0x3c, 0x9f, 0x44, 0x5a, 0x8e, 0xe7, 0x10, 0x65, 0x94, 0xee, 0xf9, 0xa4, 0x1b, 0x8c,
|
||||||
0xdd, 0x71, 0x49, 0xcb, 0x1b, 0xd1, 0xa8, 0x8a, 0x02, 0x56, 0x3d, 0x83, 0x22, 0x0f, 0x78, 0x36,
|
0x68, 0x92, 0x45, 0x01, 0x6b, 0x9c, 0x40, 0x85, 0x6f, 0x78, 0x32, 0x71, 0x9d, 0x98, 0xfc, 0xdf,
|
||||||
0xb5, 0xad, 0x90, 0xfc, 0x68, 0x61, 0xaf, 0x64, 0xc8, 0xc7, 0x9e, 0x55, 0xd1, 0xa5, 0x44, 0xd1,
|
0xb6, 0xbd, 0x92, 0x41, 0x49, 0x3d, 0xcb, 0xa4, 0x4b, 0x99, 0xa4, 0xef, 0x27, 0xfd, 0x40, 0x54,
|
||||||
0x0f, 0xa3, 0x79, 0x20, 0xba, 0x7b, 0xef, 0x76, 0xbc, 0xc4, 0x40, 0x40, 0x20, 0x07, 0xce, 0xd7,
|
0xf7, 0xce, 0xed, 0xfd, 0x32, 0x0d, 0x01, 0x81, 0x1c, 0x79, 0x5f, 0x11, 0x5e, 0x4f, 0x79, 0xcc,
|
||||||
0x84, 0xf7, 0x53, 0x1a, 0xf3, 0x35, 0xd2, 0xa1, 0x78, 0xb3, 0x89, 0xb6, 0x71, 0xd2, 0x84, 0x3e,
|
0xc7, 0xc8, 0x80, 0xca, 0xcd, 0x22, 0xda, 0xc4, 0x59, 0x13, 0xfa, 0x10, 0x60, 0x4c, 0x5d, 0x6f,
|
||||||
0x00, 0x98, 0x50, 0xdb, 0x19, 0x39, 0xc4, 0x36, 0x03, 0x2e, 0x80, 0x34, 0x2e, 0xc4, 0x96, 0x1e,
|
0xe4, 0x11, 0xd7, 0x8e, 0xb8, 0x00, 0xf2, 0xb8, 0x9c, 0x5a, 0xfa, 0x48, 0x63, 0x72, 0x67, 0x25,
|
||||||
0x52, 0x99, 0xdc, 0x59, 0x0b, 0xd9, 0x51, 0xaf, 0xc4, 0x5b, 0x74, 0x00, 0x39, 0xc7, 0xbb, 0xb0,
|
0xe4, 0x26, 0xb5, 0x92, 0x4e, 0xd1, 0x1e, 0x94, 0xbc, 0xe0, 0xc2, 0xf1, 0xbd, 0xa4, 0x42, 0x5a,
|
||||||
0x5c, 0x27, 0xea, 0x90, 0xfa, 0xce, 0xf5, 0x55, 0x05, 0xb0, 0x75, 0xd9, 0x12, 0x56, 0x1c, 0xbb,
|
0x5b, 0xd7, 0x57, 0x75, 0xc0, 0xce, 0x65, 0x57, 0x58, 0x71, 0xea, 0x66, 0x5d, 0x30, 0xa0, 0x6b,
|
||||||
0xd9, 0x14, 0xf4, 0xe8, 0x46, 0x33, 0xe7, 0x79, 0xa8, 0x6d, 0x8f, 0x26, 0x1b, 0xf9, 0x09, 0xe4,
|
0xc5, 0xac, 0xf0, 0xad, 0x36, 0x03, 0x9a, 0x2d, 0xe4, 0xa7, 0x50, 0x4a, 0xbb, 0x24, 0xcb, 0xef,
|
||||||
0xe2, 0x29, 0xc9, 0xea, 0xbb, 0xd1, 0x59, 0xcf, 0xc9, 0x30, 0xa4, 0xab, 0xf9, 0x13, 0xc1, 0x90,
|
0x5a, 0x65, 0xbd, 0x20, 0xc3, 0x98, 0x2e, 0xfb, 0x4f, 0x02, 0x43, 0x3a, 0x28, 0x4b, 0x69, 0x02,
|
||||||
0x06, 0xf9, 0x95, 0x34, 0x81, 0xff, 0xf3, 0xd5, 0x9e, 0xcd, 0xe6, 0x55, 0x5e, 0x5e, 0xa0, 0x16,
|
0xff, 0xf3, 0xe5, 0x9c, 0xf5, 0xe6, 0x65, 0x5c, 0x41, 0xa4, 0x55, 0x0c, 0x69, 0xaf, 0x80, 0x97,
|
||||||
0x75, 0xe9, 0x20, 0x83, 0x57, 0xa9, 0xb6, 0xd9, 0x75, 0x6b, 0xc0, 0x60, 0xae, 0x96, 0xb8, 0x36,
|
0xa1, 0x5a, 0xec, 0xb8, 0x15, 0xe0, 0x74, 0xa6, 0x55, 0xb9, 0x36, 0xdf, 0x4b, 0xb5, 0xd9, 0x3f,
|
||||||
0xdf, 0x8b, 0xb5, 0xd9, 0x3b, 0xa7, 0x7e, 0xd8, 0x6a, 0xae, 0x4f, 0xd4, 0xe7, 0xe8, 0x31, 0xc0,
|
0xa7, 0x61, 0xdc, 0xed, 0xac, 0x56, 0xb4, 0x66, 0xe8, 0x09, 0xc0, 0xa9, 0x4f, 0x87, 0xaf, 0x6c,
|
||||||
0xc0, 0xa5, 0xc3, 0x97, 0x26, 0xa7, 0x79, 0x9b, 0x45, 0xac, 0x2b, 0xd7, 0x57, 0x95, 0x12, 0xb6,
|
0x4e, 0xf3, 0x26, 0xdb, 0xb1, 0xa5, 0x5e, 0x5f, 0xd5, 0xab, 0xd8, 0xb9, 0x6c, 0x31, 0x47, 0xdf,
|
||||||
0x2e, 0xeb, 0xcc, 0xd1, 0x73, 0xbe, 0x26, 0xb8, 0x30, 0x88, 0x97, 0xe8, 0x67, 0x90, 0xe5, 0xf6,
|
0xfb, 0x8a, 0xe0, 0xf2, 0x69, 0x3a, 0x44, 0x3f, 0x85, 0x22, 0xb7, 0xa7, 0xad, 0xe2, 0xfd, 0x55,
|
||||||
0x78, 0x54, 0xdc, 0x59, 0x27, 0xc4, 0xed, 0x09, 0x41, 0x44, 0x40, 0xc6, 0x55, 0x30, 0x9f, 0xb8,
|
0x40, 0xdc, 0x9e, 0x11, 0x44, 0x02, 0x64, 0x5c, 0x45, 0xb3, 0xb1, 0xef, 0x05, 0xaf, 0xec, 0xd8,
|
||||||
0x8e, 0xf7, 0xd2, 0x0c, 0x2d, 0x7f, 0x4c, 0x42, 0x75, 0x57, 0xbc, 0x18, 0x91, 0xb5, 0xcf, 0x8d,
|
0x09, 0xcf, 0x48, 0xac, 0x6d, 0x8b, 0x1b, 0x23, 0xb1, 0x0e, 0xb8, 0x91, 0xe5, 0xd5, 0xa7, 0x43,
|
||||||
0xac, 0xae, 0x2e, 0x1d, 0x5a, 0xae, 0x39, 0x72, 0xad, 0x71, 0xa0, 0x7e, 0x9f, 0xe3, 0x85, 0x05,
|
0xc7, 0xb7, 0x47, 0xbe, 0x73, 0x16, 0x69, 0xdf, 0x95, 0x78, 0x62, 0x81, 0xdb, 0x0e, 0x98, 0xe9,
|
||||||
0x6e, 0x3b, 0x66, 0xa6, 0x5f, 0xcb, 0x7f, 0xf9, 0xa6, 0xb2, 0x55, 0xf5, 0xa0, 0xb0, 0xba, 0x89,
|
0x57, 0xf2, 0x9f, 0xbf, 0xae, 0x6f, 0x34, 0x02, 0x28, 0x2f, 0x4f, 0x62, 0xaa, 0xa5, 0xa3, 0x51,
|
||||||
0xa9, 0x96, 0x8e, 0x46, 0x01, 0x09, 0xb9, 0xc4, 0xd2, 0x38, 0xda, 0xad, 0x84, 0x93, 0xe2, 0x1c,
|
0x44, 0x62, 0x2e, 0xb1, 0x3c, 0x4e, 0x66, 0x4b, 0xe1, 0xe4, 0x38, 0x47, 0x42, 0x38, 0x08, 0xe4,
|
||||||
0x09, 0xe1, 0x20, 0x90, 0xcf, 0xad, 0xe0, 0x9c, 0x8b, 0xa9, 0x84, 0xf9, 0x9a, 0x8d, 0x8a, 0x4b,
|
0x73, 0x27, 0x3a, 0xe7, 0x62, 0xaa, 0x62, 0x3e, 0x66, 0xad, 0xe2, 0x92, 0x38, 0xaf, 0x6c, 0xee,
|
||||||
0x62, 0xbd, 0x34, 0xb9, 0x43, 0x48, 0x29, 0xcf, 0x0c, 0x4f, 0xad, 0xe0, 0x3c, 0xba, 0xef, 0xb7,
|
0x10, 0x52, 0x52, 0x98, 0xe1, 0x99, 0x13, 0x9d, 0x27, 0xe7, 0xfd, 0x06, 0x8a, 0x22, 0x55, 0xe8,
|
||||||
0x90, 0x15, 0xa5, 0x42, 0x9f, 0x43, 0x7e, 0x48, 0x67, 0x5e, 0xb8, 0x7e, 0x4e, 0x76, 0x93, 0xd3,
|
0x33, 0x50, 0x86, 0x74, 0x1a, 0xc4, 0xab, 0xeb, 0x64, 0x3b, 0xdb, 0x8d, 0xb8, 0x27, 0x89, 0x7d,
|
||||||
0x88, 0x7b, 0xa2, 0xdc, 0x57, 0xc0, 0xea, 0x31, 0xe4, 0x22, 0x17, 0x7a, 0xb8, 0x1a, 0x95, 0x72,
|
0x09, 0x6c, 0x1c, 0x40, 0x29, 0x71, 0xa1, 0x87, 0xcb, 0x56, 0x29, 0xb7, 0xee, 0xde, 0xc8, 0xca,
|
||||||
0xfd, 0xde, 0x8d, 0xaa, 0x6c, 0xbe, 0x2f, 0x17, 0x96, 0x3b, 0x13, 0x7f, 0x5e, 0xc6, 0x62, 0x53,
|
0xfa, 0xfd, 0x72, 0xe1, 0xf8, 0x53, 0xf1, 0xf3, 0x32, 0x16, 0x93, 0xc6, 0xdf, 0x24, 0x28, 0x61,
|
||||||
0xfd, 0xbb, 0x04, 0x39, 0xcc, 0x94, 0x10, 0x84, 0x89, 0x97, 0x29, 0xb3, 0xf1, 0x32, 0xad, 0x7b,
|
0xa6, 0x84, 0x28, 0xce, 0xdc, 0x4c, 0x85, 0xb5, 0x9b, 0x69, 0x55, 0xc3, 0xb9, 0xb5, 0x1a, 0x4e,
|
||||||
0x38, 0xb5, 0xd1, 0xc3, 0x71, 0x1b, 0xa6, 0x13, 0x6d, 0xb8, 0x66, 0x4e, 0x7e, 0x23, 0x73, 0x99,
|
0xcb, 0x30, 0x9f, 0x29, 0xc3, 0x15, 0x73, 0xf2, 0x5b, 0x99, 0x2b, 0xbc, 0x85, 0xb9, 0x62, 0x86,
|
||||||
0x37, 0x30, 0x97, 0x4d, 0x30, 0xf7, 0x10, 0x76, 0x46, 0x3e, 0x9d, 0xf0, 0xb7, 0x87, 0xfa, 0x96,
|
0xb9, 0x87, 0xb0, 0x35, 0x0a, 0xe9, 0x98, 0xdf, 0x3d, 0x34, 0x74, 0xc2, 0x59, 0xd2, 0x28, 0x37,
|
||||||
0x3f, 0x8f, 0x06, 0xe5, 0x36, 0xb3, 0xf6, 0x63, 0xe3, 0x26, 0xc1, 0xf9, 0x4d, 0x82, 0xab, 0x26,
|
0x99, 0x75, 0x90, 0x1a, 0xd7, 0x09, 0x56, 0xd6, 0x09, 0x6e, 0xd8, 0xa0, 0x60, 0x12, 0x4d, 0x68,
|
||||||
0xe4, 0x31, 0x09, 0xa6, 0xd4, 0x0b, 0xc8, 0x5b, 0x73, 0x42, 0x20, 0xdb, 0x56, 0x68, 0xf1, 0x8c,
|
0x10, 0x91, 0x77, 0xc6, 0x84, 0x40, 0x76, 0x9d, 0xd8, 0xe1, 0x11, 0x55, 0x31, 0x1f, 0xa3, 0x47,
|
||||||
0x4a, 0x98, 0xaf, 0xd1, 0x23, 0x90, 0x87, 0xd4, 0x16, 0xf9, 0xec, 0x24, 0x25, 0x68, 0xf8, 0x3e,
|
0x20, 0x0f, 0xa9, 0x2b, 0xe2, 0xd9, 0xca, 0x4a, 0xd0, 0x0c, 0x43, 0x1a, 0xb6, 0xa9, 0x4b, 0x30,
|
||||||
0xf5, 0x1b, 0xd4, 0x26, 0x98, 0x03, 0xaa, 0x53, 0x50, 0x9a, 0xf4, 0xd2, 0x73, 0xa9, 0x65, 0x77,
|
0x07, 0x34, 0x26, 0xa0, 0x76, 0xe8, 0x65, 0xe0, 0x53, 0xc7, 0x3d, 0x0e, 0xe9, 0x19, 0xbb, 0x20,
|
||||||
0x7d, 0x3a, 0x66, 0x0f, 0xc4, 0x5b, 0x07, 0x5d, 0x13, 0x72, 0x33, 0x3e, 0x0a, 0xe3, 0x51, 0xf7,
|
0xde, 0xd9, 0xe8, 0x3a, 0x50, 0x9a, 0xf2, 0x56, 0x98, 0xb6, 0xba, 0x07, 0xeb, 0xad, 0xe9, 0xe6,
|
||||||
0x60, 0x73, 0x34, 0xdd, 0x0c, 0x24, 0xe6, 0x66, 0xdc, 0xbf, 0xd1, 0xd1, 0xea, 0x3f, 0x25, 0xd0,
|
0x46, 0xa2, 0x6f, 0xa6, 0xf5, 0x9b, 0x2c, 0x6d, 0xfc, 0x43, 0x02, 0xfd, 0xdd, 0x68, 0xd4, 0x85,
|
||||||
0xde, 0x8e, 0x46, 0x2d, 0x28, 0x0a, 0xa4, 0x99, 0xf8, 0x26, 0x3a, 0x78, 0x97, 0x8b, 0xf8, 0x54,
|
0x8a, 0x40, 0xda, 0x99, 0x37, 0xd1, 0xde, 0x0f, 0x39, 0x88, 0x77, 0x45, 0x98, 0x2e, 0xc7, 0x6f,
|
||||||
0x84, 0xd9, 0x6a, 0xfd, 0xc6, 0x07, 0x35, 0x31, 0x6f, 0xd2, 0xef, 0x36, 0x6f, 0x1e, 0xc1, 0xb6,
|
0xbd, 0x50, 0x33, 0xfd, 0x26, 0xff, 0xc3, 0xfa, 0xcd, 0x23, 0xd8, 0x14, 0x0d, 0x20, 0x7d, 0x3e,
|
||||||
0x18, 0x00, 0xf1, 0xe7, 0x83, 0xac, 0xa7, 0x0f, 0x32, 0xf5, 0x94, 0xb2, 0x85, 0x4b, 0x03, 0xd1,
|
0xc8, 0x46, 0x7e, 0xaf, 0xd0, 0xca, 0xa9, 0x1b, 0xb8, 0x7a, 0x2a, 0xca, 0x8c, 0xdb, 0x1b, 0x45,
|
||||||
0x66, 0xdc, 0x5e, 0xcd, 0x82, 0xdc, 0x75, 0xbc, 0x71, 0xb5, 0x02, 0x99, 0x86, 0x4b, 0x79, 0xc1,
|
0x90, 0x8f, 0xbd, 0xe0, 0xac, 0x51, 0x87, 0x42, 0xdb, 0xa7, 0x3c, 0x61, 0xc5, 0x90, 0x38, 0x11,
|
||||||
0xb2, 0x3e, 0xb1, 0x02, 0xea, 0xc5, 0x3c, 0x8a, 0xdd, 0xe1, 0x3f, 0x52, 0x50, 0x4c, 0x7c, 0xda,
|
0x0d, 0x52, 0x1e, 0xc5, 0x6c, 0xff, 0xef, 0x39, 0xa8, 0x64, 0x9e, 0x76, 0xe8, 0x29, 0x6c, 0xb5,
|
||||||
0xa1, 0x27, 0xb0, 0xd3, 0x38, 0x3d, 0xeb, 0xf5, 0x0d, 0x6c, 0x36, 0x3a, 0xed, 0xe3, 0xd6, 0x89,
|
0x8f, 0x4e, 0xfa, 0x03, 0x13, 0xdb, 0xed, 0x9e, 0x75, 0xd0, 0x3d, 0x54, 0x37, 0xf4, 0xdd, 0xf9,
|
||||||
0xb2, 0xa5, 0xed, 0x2f, 0x96, 0xba, 0x3a, 0x59, 0x83, 0x36, 0xbf, 0xda, 0x2a, 0x90, 0x69, 0xb5,
|
0xc2, 0xd0, 0xc6, 0x2b, 0xd0, 0xfa, 0xab, 0xad, 0x0e, 0x85, 0xae, 0xd5, 0x31, 0xff, 0xa0, 0x4a,
|
||||||
0x9b, 0xc6, 0x1f, 0x15, 0x49, 0xbb, 0xbb, 0x58, 0xea, 0x4a, 0x02, 0x28, 0x9e, 0xc0, 0x4f, 0xa0,
|
0xfa, 0x9d, 0xf9, 0xc2, 0x50, 0x33, 0x40, 0x71, 0x05, 0x7e, 0x02, 0x55, 0x0e, 0xb0, 0x4f, 0x8e,
|
||||||
0xc4, 0x01, 0xe6, 0x59, 0xb7, 0x59, 0xeb, 0x1b, 0x4a, 0x4a, 0xd3, 0x16, 0x4b, 0x7d, 0xef, 0x26,
|
0x3b, 0xcd, 0x81, 0xa9, 0xe6, 0x74, 0x7d, 0xbe, 0x30, 0x76, 0x6e, 0xe2, 0x12, 0xce, 0xef, 0x43,
|
||||||
0x2e, 0xe2, 0xfc, 0x43, 0xc8, 0x61, 0xe3, 0x0f, 0x67, 0x46, 0xaf, 0xaf, 0xa4, 0xb5, 0xbd, 0xc5,
|
0x09, 0x9b, 0xbf, 0x3f, 0x31, 0xfb, 0x03, 0x35, 0xaf, 0xef, 0xcc, 0x17, 0x06, 0xca, 0x00, 0xd3,
|
||||||
0x52, 0x47, 0x09, 0x60, 0xdc, 0x52, 0x0f, 0x21, 0x8f, 0x8d, 0x5e, 0xb7, 0xd3, 0xee, 0x19, 0x8a,
|
0x92, 0x7a, 0x08, 0x0a, 0x36, 0xfb, 0xc7, 0x3d, 0xab, 0x6f, 0xaa, 0xb2, 0xfe, 0xa3, 0xf9, 0xc2,
|
||||||
0xac, 0xfd, 0x64, 0xb1, 0xd4, 0xef, 0x6c, 0xa0, 0x22, 0x95, 0xfe, 0x02, 0x76, 0x9b, 0x9d, 0x2f,
|
0x78, 0x7f, 0x0d, 0x95, 0xa8, 0xf4, 0xe7, 0xb0, 0xdd, 0xe9, 0x7d, 0x61, 0x1d, 0xf5, 0x9a, 0x1d,
|
||||||
0xdb, 0xa7, 0x9d, 0x5a, 0xd3, 0xec, 0xe2, 0xce, 0x09, 0x36, 0x7a, 0x3d, 0x25, 0xa3, 0x55, 0x16,
|
0xfb, 0x18, 0xf7, 0x0e, 0xb1, 0xd9, 0xef, 0xab, 0x05, 0xbd, 0x3e, 0x5f, 0x18, 0x1f, 0x64, 0xf0,
|
||||||
0x4b, 0xfd, 0xfd, 0x04, 0xfe, 0x96, 0xe8, 0x3e, 0x00, 0xb9, 0xdb, 0x6a, 0x9f, 0x28, 0x59, 0xed,
|
0xb7, 0x44, 0xf7, 0x21, 0xc8, 0xc7, 0x5d, 0xeb, 0x50, 0x2d, 0xea, 0xef, 0xcf, 0x17, 0xc6, 0x7b,
|
||||||
0xce, 0x62, 0xa9, 0xbf, 0x97, 0x80, 0x32, 0x52, 0x59, 0xc6, 0x8d, 0xd3, 0x4e, 0xcf, 0x50, 0x72,
|
0x19, 0x28, 0x23, 0x95, 0x45, 0xdc, 0x3e, 0xea, 0xf5, 0x4d, 0xb5, 0x74, 0x2b, 0x62, 0x4e, 0xf6,
|
||||||
0xb7, 0x32, 0xe6, 0x64, 0x1f, 0xfe, 0x09, 0xd0, 0xed, 0x8f, 0x5f, 0xf4, 0x00, 0xe4, 0x76, 0xa7,
|
0xfe, 0x1f, 0x01, 0xdd, 0x7e, 0xfc, 0xa2, 0x07, 0x20, 0x5b, 0x3d, 0xcb, 0x54, 0x37, 0x44, 0xfc,
|
||||||
0x6d, 0x28, 0x5b, 0x22, 0xff, 0xdb, 0x88, 0x36, 0xf5, 0x08, 0xaa, 0x42, 0xfa, 0xf4, 0xab, 0x2f,
|
0xb7, 0x11, 0x16, 0x0d, 0x08, 0x6a, 0x40, 0xfe, 0xe8, 0xcb, 0xcf, 0x55, 0x49, 0xff, 0xf1, 0x7c,
|
||||||
0x14, 0x49, 0xfb, 0xe9, 0x62, 0xa9, 0xdf, 0xbb, 0x0d, 0x3a, 0xfd, 0xea, 0x8b, 0x43, 0x0a, 0xc5,
|
0x61, 0xdc, 0xbd, 0x0d, 0x3a, 0xfa, 0xf2, 0xf3, 0x7d, 0x0a, 0x95, 0xec, 0xc6, 0x0d, 0x50, 0x9e,
|
||||||
0x64, 0xe0, 0x2a, 0xe4, 0x9f, 0x19, 0xfd, 0x5a, 0xb3, 0xd6, 0xaf, 0x29, 0x5b, 0xe2, 0x2f, 0xc5,
|
0x9b, 0x83, 0x66, 0xa7, 0x39, 0x68, 0xaa, 0x1b, 0xe2, 0x97, 0x52, 0xf7, 0x73, 0x12, 0x3b, 0xbc,
|
||||||
0xee, 0x67, 0x24, 0xb4, 0x78, 0x13, 0xee, 0x43, 0xa6, 0x6d, 0x3c, 0x37, 0xb0, 0x22, 0x69, 0xbb,
|
0x08, 0x77, 0xa1, 0x60, 0x99, 0x2f, 0x4c, 0xac, 0x4a, 0xfa, 0xf6, 0x7c, 0x61, 0x6c, 0xa6, 0x00,
|
||||||
0x8b, 0xa5, 0xbe, 0x1d, 0x03, 0xda, 0xe4, 0x82, 0xf8, 0xa8, 0x0c, 0xd9, 0xda, 0xe9, 0x97, 0xb5,
|
0x8b, 0x5c, 0x90, 0x10, 0xd5, 0xa0, 0xd8, 0x3c, 0xfa, 0xa2, 0xf9, 0xb2, 0xaf, 0xe6, 0x74, 0x34,
|
||||||
0x17, 0x3d, 0x25, 0xa5, 0xa1, 0xc5, 0x52, 0xdf, 0x89, 0xdd, 0x35, 0xf7, 0xd2, 0x9a, 0x07, 0x87,
|
0x5f, 0x18, 0x5b, 0xa9, 0xbb, 0xe9, 0x5f, 0x3a, 0xb3, 0x68, 0xff, 0xbf, 0x12, 0x54, 0xb3, 0x17,
|
||||||
0xff, 0x93, 0xa0, 0x94, 0x7c, 0xf0, 0x51, 0x19, 0xe4, 0xe3, 0xd6, 0xa9, 0x11, 0x5f, 0x97, 0xf4,
|
0x3e, 0xaa, 0x81, 0x7c, 0xd0, 0x3d, 0x32, 0xd3, 0xe3, 0xb2, 0x3e, 0x36, 0x46, 0x7b, 0x50, 0xee,
|
||||||
0xb1, 0x35, 0x3a, 0x80, 0x42, 0xb3, 0x85, 0x8d, 0x46, 0xbf, 0x83, 0x5f, 0xc4, 0xb9, 0x24, 0x41,
|
0x74, 0xb1, 0xd9, 0x1e, 0xf4, 0xf0, 0xcb, 0x34, 0x96, 0x2c, 0xa8, 0xe3, 0x85, 0x5c, 0xe0, 0x33,
|
||||||
0x4d, 0xc7, 0xe7, 0x02, 0x9f, 0xa3, 0x5f, 0x41, 0xa9, 0xf7, 0xe2, 0xd9, 0x69, 0xab, 0xfd, 0x7b,
|
0xf4, 0x4b, 0xa8, 0xf6, 0x5f, 0x3e, 0x3f, 0xea, 0x5a, 0xbf, 0xb3, 0xf9, 0x8e, 0x39, 0xfd, 0xd1,
|
||||||
0x93, 0x47, 0x4c, 0x69, 0x8f, 0x16, 0x4b, 0xfd, 0xfe, 0x06, 0x98, 0x4c, 0x7d, 0x32, 0xb4, 0x42,
|
0x7c, 0x61, 0xdc, 0x5b, 0x03, 0x93, 0x49, 0x48, 0x86, 0x4e, 0x4c, 0xdc, 0xbe, 0xb8, 0x83, 0x98,
|
||||||
0x62, 0xf7, 0xc4, 0x1b, 0xc4, 0x9c, 0x79, 0x09, 0x35, 0x60, 0x37, 0x3e, 0xba, 0xbe, 0x2c, 0xad,
|
0x53, 0x91, 0x50, 0x1b, 0xb6, 0xd3, 0xa5, 0xab, 0xc3, 0xf2, 0xfa, 0x27, 0xf3, 0x85, 0xf1, 0xd1,
|
||||||
0x7d, 0xb2, 0x58, 0xea, 0x1f, 0xfd, 0xe0, 0xf9, 0xd5, 0xed, 0x79, 0x09, 0x3d, 0x80, 0x5c, 0x14,
|
0xf7, 0xae, 0x5f, 0x9e, 0xae, 0x48, 0xe8, 0x01, 0x94, 0x92, 0x4d, 0x52, 0x25, 0x65, 0x97, 0x26,
|
||||||
0x24, 0x56, 0x52, 0xf2, 0x68, 0x74, 0xe0, 0xf0, 0x6f, 0x12, 0x14, 0x56, 0xe3, 0x8a, 0x11, 0xde,
|
0x0b, 0xf6, 0xff, 0x2a, 0x41, 0x79, 0xd9, 0xae, 0x18, 0xe1, 0x56, 0xcf, 0x36, 0x31, 0xee, 0xe1,
|
||||||
0xee, 0x98, 0x06, 0xc6, 0x1d, 0x1c, 0x33, 0xb0, 0x72, 0xb6, 0x29, 0x5f, 0xa2, 0xfb, 0x90, 0x3b,
|
0x94, 0x81, 0xa5, 0xd3, 0xa2, 0x7c, 0x88, 0xee, 0x41, 0xe9, 0xd0, 0xb4, 0x4c, 0xdc, 0x6d, 0xa7,
|
||||||
0x31, 0xda, 0x06, 0x6e, 0x35, 0xe2, 0xc6, 0x58, 0x41, 0x4e, 0x88, 0x47, 0x7c, 0x67, 0x88, 0x3e,
|
0x85, 0xb1, 0x84, 0x1c, 0x92, 0x80, 0x84, 0xde, 0x10, 0x7d, 0x0c, 0x55, 0xab, 0x67, 0xf7, 0x4f,
|
||||||
0x86, 0x52, 0xbb, 0x63, 0xf6, 0xce, 0x1a, 0x4f, 0xe3, 0xd4, 0xf9, 0xfd, 0x89, 0x50, 0xbd, 0xd9,
|
0xda, 0xcf, 0xd2, 0xd0, 0xf9, 0xf9, 0x99, 0xad, 0xfa, 0xd3, 0xe1, 0x39, 0xe7, 0x73, 0x9f, 0xd5,
|
||||||
0xf0, 0x9c, 0xf3, 0x79, 0xc8, 0x7a, 0xe8, 0x79, 0xed, 0xb4, 0xd5, 0x14, 0xd0, 0xb4, 0xa6, 0x2e,
|
0xd0, 0x8b, 0xe6, 0x51, 0xb7, 0x23, 0xa0, 0x79, 0x5d, 0x9b, 0x2f, 0x8c, 0x3b, 0x4b, 0x68, 0xf2,
|
||||||
0x96, 0xfa, 0xdd, 0x15, 0x34, 0xfa, 0xe4, 0x61, 0xd8, 0x43, 0x1b, 0xca, 0x3f, 0x3c, 0x98, 0x90,
|
0xe4, 0x61, 0xd8, 0x7d, 0x17, 0x6a, 0xdf, 0xdf, 0x98, 0x90, 0x01, 0xc5, 0xe6, 0xf1, 0xb1, 0x69,
|
||||||
0x0e, 0xd9, 0x5a, 0xb7, 0x6b, 0xb4, 0x9b, 0xf1, 0xbf, 0x5f, 0xfb, 0x6a, 0xd3, 0x29, 0xf1, 0x6c,
|
0x75, 0xd2, 0xbf, 0x5f, 0xf9, 0x9a, 0x93, 0x09, 0x09, 0x5c, 0x86, 0x38, 0xe8, 0xe1, 0x43, 0x73,
|
||||||
0x86, 0x38, 0xee, 0xe0, 0x13, 0xa3, 0x1f, 0xff, 0xf9, 0x35, 0xe2, 0x98, 0xb2, 0x0f, 0x80, 0xfa,
|
0x90, 0xfe, 0xfc, 0x0a, 0x71, 0x40, 0xd9, 0x03, 0xa0, 0xb5, 0xfb, 0xe6, 0xdb, 0xda, 0xc6, 0x37,
|
||||||
0xfe, 0xeb, 0xef, 0xca, 0x5b, 0xdf, 0x7e, 0x57, 0xde, 0x7a, 0x7d, 0x5d, 0x96, 0xbe, 0xbd, 0x2e,
|
0xdf, 0xd6, 0x36, 0xde, 0x5c, 0xd7, 0xa4, 0x6f, 0xae, 0x6b, 0xd2, 0xbf, 0xae, 0x6b, 0x1b, 0xdf,
|
||||||
0x4b, 0xff, 0xbe, 0x2e, 0x6f, 0x7d, 0x7f, 0x5d, 0x96, 0xbe, 0xf9, 0x4f, 0x59, 0x1a, 0x64, 0xf9,
|
0x5d, 0xd7, 0xa4, 0xaf, 0xff, 0x5d, 0x93, 0x4e, 0x8b, 0xbc, 0x91, 0x7d, 0xf6, 0xbf, 0x00, 0x00,
|
||||||
0x20, 0xfb, 0xfc, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x41, 0xd9, 0x3a, 0x0f, 0x0f, 0x00,
|
0x00, 0xff, 0xff, 0x66, 0x57, 0x60, 0x7e, 0x05, 0x0f, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ syntax = "proto3";
|
|||||||
|
|
||||||
package protocol;
|
package protocol;
|
||||||
|
|
||||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
import "repos/protobuf/gogoproto/gogo.proto";
|
||||||
|
|
||||||
option (gogoproto.goproto_getters_all) = false;
|
option (gogoproto.goproto_getters_all) = false;
|
||||||
option (gogoproto.sizer_all) = false;
|
option (gogoproto.sizer_all) = false;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2014 The Protocol Authors.
|
// Copyright (C) 2014 The Protocol Authors.
|
||||||
|
|
||||||
//go:generate go run ../../script/protofmt.go bep.proto
|
//go:generate go run ../../script/protofmt.go bep.proto
|
||||||
//go:generate protoc -I ../../vendor/ -I ../../vendor/github.com/gogo/protobuf/protobuf -I . --gogofast_out=. bep.proto
|
//go:generate protoc -I ../../ -I . --gogofast_out=. bep.proto
|
||||||
|
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ func TestWinsConflict(t *testing.T) {
|
|||||||
{{ModifiedS: 42}, {ModifiedS: 41}},
|
{{ModifiedS: 42}, {ModifiedS: 41}},
|
||||||
{{ModifiedS: 41}, {ModifiedS: 42, Deleted: true}},
|
{{ModifiedS: 41}, {ModifiedS: 42, Deleted: true}},
|
||||||
{{Deleted: true}, {ModifiedS: 10, RawInvalid: true}},
|
{{Deleted: true}, {ModifiedS: 10, RawInvalid: true}},
|
||||||
{{ModifiedS: 41, Version: Vector{[]Counter{{42, 2}, {43, 1}}}}, {ModifiedS: 41, Version: Vector{[]Counter{{42, 1}, {43, 2}}}}},
|
{{ModifiedS: 41, Version: Vector{Counters: []Counter{{ID: 42, Value: 2}, {ID: 43, Value: 1}}}}, {ModifiedS: 41, Version: Vector{Counters: []Counter{{ID: 42, Value: 1}, {ID: 43, Value: 2}}}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Copyright (C) 2014 The Protocol Authors.
|
// Copyright (C) 2014 The Protocol Authors.
|
||||||
|
|
||||||
//go:generate go run ../../script/protofmt.go deviceid_test.proto
|
//go:generate go run ../../script/protofmt.go deviceid_test.proto
|
||||||
//go:generate protoc -I ../../vendor/ -I ../../vendor/github.com/gogo/protobuf/protobuf -I . --gogofast_out=. deviceid_test.proto
|
//go:generate protoc -I ../../ -I . --gogofast_out=. deviceid_test.proto
|
||||||
|
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ func TestNewDeviceIDMarshalling(t *testing.T) {
|
|||||||
// Create a message with a device ID in old style bytes format
|
// Create a message with a device ID in old style bytes format
|
||||||
|
|
||||||
id0, _ := DeviceIDFromString(formatted)
|
id0, _ := DeviceIDFromString(formatted)
|
||||||
msg0 := TestOldDeviceID{id0[:]}
|
msg0 := TestOldDeviceID{Test: id0[:]}
|
||||||
|
|
||||||
// Marshal it
|
// Marshal it
|
||||||
|
|
||||||
|
@ -430,16 +430,16 @@ var (
|
|||||||
func init() { proto.RegisterFile("deviceid_test.proto", fileDescriptorDeviceidTest) }
|
func init() { proto.RegisterFile("deviceid_test.proto", fileDescriptorDeviceidTest) }
|
||||||
|
|
||||||
var fileDescriptorDeviceidTest = []byte{
|
var fileDescriptorDeviceidTest = []byte{
|
||||||
// 176 bytes of a gzipped FileDescriptorProto
|
// 169 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0x49, 0x2d, 0xcb,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0x49, 0x2d, 0xcb,
|
||||||
0x4c, 0x4e, 0xcd, 0x4c, 0x89, 0x2f, 0x49, 0x2d, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17,
|
0x4c, 0x4e, 0xcd, 0x4c, 0x89, 0x2f, 0x49, 0x2d, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17,
|
||||||
0xe2, 0x00, 0x53, 0xc9, 0xf9, 0x39, 0x52, 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9,
|
0xe2, 0x00, 0x53, 0xc9, 0xf9, 0x39, 0x52, 0xca, 0x45, 0xa9, 0x05, 0xf9, 0xc5, 0xfa, 0x60, 0x7e,
|
||||||
0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0xfa, 0x60, 0x99, 0xa4, 0xd2, 0x34, 0x30, 0x0f, 0xcc,
|
0x52, 0x69, 0x9a, 0x7e, 0x7a, 0x7e, 0x7a, 0x3e, 0x98, 0x03, 0x66, 0x41, 0x94, 0x2b, 0xa9, 0x72,
|
||||||
0x01, 0xb3, 0x20, 0x1a, 0x95, 0x54, 0xb9, 0xf8, 0x43, 0x52, 0x8b, 0x4b, 0xfc, 0x73, 0x52, 0x5c,
|
0xf1, 0x87, 0xa4, 0x16, 0x97, 0xf8, 0xe7, 0xa4, 0xb8, 0x80, 0x0d, 0xf3, 0x74, 0x11, 0x12, 0xe2,
|
||||||
0xc0, 0xc6, 0x7a, 0xba, 0x08, 0x09, 0x71, 0xb1, 0x80, 0x4c, 0x96, 0x60, 0x54, 0x60, 0xd4, 0xe0,
|
0x62, 0x01, 0x99, 0x27, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x13, 0x04, 0x66, 0x2b, 0x99, 0x43, 0x94,
|
||||||
0x09, 0x02, 0xb3, 0x95, 0xcc, 0x21, 0xca, 0xfc, 0x52, 0xcb, 0xe1, 0xca, 0x54, 0x90, 0x95, 0x39,
|
0xf9, 0xa5, 0x96, 0xc3, 0x95, 0xa9, 0x20, 0x2b, 0x73, 0x12, 0x38, 0x71, 0x4f, 0x9e, 0xe1, 0xd6,
|
||||||
0x09, 0x9c, 0xb8, 0x27, 0xcf, 0x70, 0xeb, 0x9e, 0x3c, 0x07, 0x4c, 0x1e, 0xa2, 0xd1, 0x49, 0xe6,
|
0x3d, 0x79, 0x0e, 0x98, 0x3c, 0x44, 0xa3, 0x93, 0xcc, 0x89, 0x87, 0x72, 0x0c, 0x17, 0x1e, 0xca,
|
||||||
0xc4, 0x43, 0x39, 0x86, 0x0b, 0x0f, 0xe5, 0x18, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e,
|
0x31, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x0c, 0x2f, 0x1e,
|
||||||
0xf1, 0xc1, 0x23, 0x39, 0x86, 0x17, 0x8f, 0xe4, 0x18, 0x16, 0x3c, 0x96, 0x63, 0x4c, 0x62, 0x03,
|
0xc9, 0x31, 0x2c, 0x78, 0x2c, 0xc7, 0x98, 0xc4, 0x06, 0x76, 0x84, 0x31, 0x20, 0x00, 0x00, 0xff,
|
||||||
0x3b, 0xc2, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x35, 0x9c, 0x00, 0x78, 0xd4, 0x00, 0x00, 0x00,
|
0xff, 0x82, 0x8f, 0xec, 0x3e, 0xca, 0x00, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ syntax = "proto3";
|
|||||||
|
|
||||||
package protocol;
|
package protocol;
|
||||||
|
|
||||||
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
|
import "repos/protobuf/gogoproto/gogo.proto";
|
||||||
|
|
||||||
option (gogoproto.goproto_getters_all) = false;
|
option (gogoproto.goproto_getters_all) = false;
|
||||||
option (gogoproto.sizer_all) = false;
|
option (gogoproto.sizer_all) = false;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Copyright (C) 2016 The Protocol Authors.
|
// Copyright (C) 2016 The Protocol Authors.
|
||||||
|
|
||||||
//go:generate -command genxdr go run ../../vendor/github.com/calmh/xdr/cmd/genxdr/main.go
|
//go:generate -command genxdr go run ../../repos/xdr/cmd/genxdr/main.go
|
||||||
//go:generate genxdr -o hello_v0.13_xdr.go hello_v0.13.go
|
//go:generate genxdr -o hello_v0.13_xdr.go hello_v0.13.go
|
||||||
|
|
||||||
package protocol
|
package protocol
|
||||||
|
@ -25,11 +25,11 @@ func (v Vector) Update(id ShortID) Vector {
|
|||||||
nv[i].ID = id
|
nv[i].ID = id
|
||||||
nv[i].Value = 1
|
nv[i].Value = 1
|
||||||
copy(nv[i+1:], v.Counters[i:])
|
copy(nv[i+1:], v.Counters[i:])
|
||||||
return Vector{nv}
|
return Vector{Counters: nv}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Append a new index
|
// Append a new index
|
||||||
return Vector{append(v.Counters, Counter{id, 1})}
|
return Vector{Counters: append(v.Counters, Counter{ID: id, Value: 1})}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge returns the vector containing the maximum indexes from v and b. If it
|
// Merge returns the vector containing the maximum indexes from v and b. If it
|
||||||
@ -40,7 +40,7 @@ func (v Vector) Merge(b Vector) Vector {
|
|||||||
for bi < len(b.Counters) {
|
for bi < len(b.Counters) {
|
||||||
if vi == len(v.Counters) {
|
if vi == len(v.Counters) {
|
||||||
// We've reach the end of v, all that remains are appends
|
// We've reach the end of v, all that remains are appends
|
||||||
return Vector{append(v.Counters, b.Counters[bi:]...)}
|
return Vector{Counters: append(v.Counters, b.Counters[bi:]...)}
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Counters[vi].ID > b.Counters[bi].ID {
|
if v.Counters[vi].ID > b.Counters[bi].ID {
|
||||||
@ -71,7 +71,7 @@ func (v Vector) Merge(b Vector) Vector {
|
|||||||
func (v Vector) Copy() Vector {
|
func (v Vector) Copy() Vector {
|
||||||
nv := make([]Counter, len(v.Counters))
|
nv := make([]Counter, len(v.Counters))
|
||||||
copy(nv, v.Counters)
|
copy(nv, v.Counters)
|
||||||
return Vector{nv}
|
return Vector{Counters: nv}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal returns true when the two vectors are equivalent.
|
// Equal returns true when the two vectors are equivalent.
|
||||||
|
@ -13,7 +13,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
// Append
|
// Append
|
||||||
|
|
||||||
v = v.Update(42)
|
v = v.Update(42)
|
||||||
expected := Vector{[]Counter{{42, 1}}}
|
expected := Vector{Counters: []Counter{{ID: 42, Value: 1}}}
|
||||||
|
|
||||||
if v.Compare(expected) != Equal {
|
if v.Compare(expected) != Equal {
|
||||||
t.Errorf("Update error, %+v != %+v", v, expected)
|
t.Errorf("Update error, %+v != %+v", v, expected)
|
||||||
@ -22,7 +22,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
// Insert at front
|
// Insert at front
|
||||||
|
|
||||||
v = v.Update(36)
|
v = v.Update(36)
|
||||||
expected = Vector{[]Counter{{36, 1}, {42, 1}}}
|
expected = Vector{Counters: []Counter{{ID: 36, Value: 1}, {ID: 42, Value: 1}}}
|
||||||
|
|
||||||
if v.Compare(expected) != Equal {
|
if v.Compare(expected) != Equal {
|
||||||
t.Errorf("Update error, %+v != %+v", v, expected)
|
t.Errorf("Update error, %+v != %+v", v, expected)
|
||||||
@ -31,7 +31,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
// Insert in moddle
|
// Insert in moddle
|
||||||
|
|
||||||
v = v.Update(37)
|
v = v.Update(37)
|
||||||
expected = Vector{[]Counter{{36, 1}, {37, 1}, {42, 1}}}
|
expected = Vector{Counters: []Counter{{ID: 36, Value: 1}, {ID: 37, Value: 1}, {ID: 42, Value: 1}}}
|
||||||
|
|
||||||
if v.Compare(expected) != Equal {
|
if v.Compare(expected) != Equal {
|
||||||
t.Errorf("Update error, %+v != %+v", v, expected)
|
t.Errorf("Update error, %+v != %+v", v, expected)
|
||||||
@ -40,7 +40,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
// Update existing
|
// Update existing
|
||||||
|
|
||||||
v = v.Update(37)
|
v = v.Update(37)
|
||||||
expected = Vector{[]Counter{{36, 1}, {37, 2}, {42, 1}}}
|
expected = Vector{Counters: []Counter{{ID: 36, Value: 1}, {ID: 37, Value: 2}, {ID: 42, Value: 1}}}
|
||||||
|
|
||||||
if v.Compare(expected) != Equal {
|
if v.Compare(expected) != Equal {
|
||||||
t.Errorf("Update error, %+v != %+v", v, expected)
|
t.Errorf("Update error, %+v != %+v", v, expected)
|
||||||
@ -48,7 +48,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCopy(t *testing.T) {
|
func TestCopy(t *testing.T) {
|
||||||
v0 := Vector{[]Counter{{42, 1}}}
|
v0 := Vector{Counters: []Counter{{ID: 42, Value: 1}}}
|
||||||
v1 := v0.Copy()
|
v1 := v0.Copy()
|
||||||
v1.Update(42)
|
v1.Update(42)
|
||||||
if v0.Compare(v1) != Lesser {
|
if v0.Compare(v1) != Lesser {
|
||||||
@ -67,52 +67,52 @@ func TestMerge(t *testing.T) {
|
|||||||
Vector{},
|
Vector{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Appends
|
// Appends
|
||||||
{
|
{
|
||||||
Vector{},
|
Vector{},
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}}},
|
||||||
Vector{[]Counter{{42, 1}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Insert
|
// Insert
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}, {23, 2}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 23, Value: 2}, {ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}, {23, 2}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 23, Value: 2}, {ID: 42, Value: 1}}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 1}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 1}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 1}, {42, 2}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 1}, {ID: 42, Value: 2}}},
|
||||||
Vector{[]Counter{{22, 2}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 2}, {ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 2}, {42, 2}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 2}, {ID: 42, Value: 2}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
// All of the above
|
// All of the above
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{10, 1}, {20, 2}, {30, 1}}},
|
Vector{Counters: []Counter{{ID: 10, Value: 1}, {ID: 20, Value: 2}, {ID: 30, Value: 1}}},
|
||||||
Vector{[]Counter{{5, 1}, {10, 2}, {15, 1}, {20, 1}, {25, 1}, {35, 1}}},
|
Vector{Counters: []Counter{{ID: 5, Value: 1}, {ID: 10, Value: 2}, {ID: 15, Value: 1}, {ID: 20, Value: 1}, {ID: 25, Value: 1}, {ID: 35, Value: 1}}},
|
||||||
Vector{[]Counter{{5, 1}, {10, 2}, {15, 1}, {20, 2}, {25, 1}, {30, 1}, {35, 1}}},
|
Vector{Counters: []Counter{{ID: 5, Value: 1}, {ID: 10, Value: 2}, {ID: 15, Value: 1}, {ID: 20, Value: 2}, {ID: 25, Value: 1}, {ID: 30, Value: 1}, {ID: 35, Value: 1}}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ func TestMerge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCounterValue(t *testing.T) {
|
func TestCounterValue(t *testing.T) {
|
||||||
v0 := Vector{[]Counter{{42, 1}, {64, 5}}}
|
v0 := Vector{Counters: []Counter{{ID: 42, Value: 1}, {ID: 64, Value: 5}}}
|
||||||
if v0.Counter(42) != 1 {
|
if v0.Counter(42) != 1 {
|
||||||
t.Errorf("Counter error, %d != %d", v0.Counter(42), 1)
|
t.Errorf("Counter error, %d != %d", v0.Counter(42), 1)
|
||||||
}
|
}
|
||||||
@ -143,162 +143,162 @@ func TestCompare(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
// Empty vectors are identical
|
// Empty vectors are identical
|
||||||
{Vector{}, Vector{}, Equal},
|
{Vector{}, Vector{}, Equal},
|
||||||
{Vector{}, Vector{[]Counter{{42, 0}}}, Equal},
|
{Vector{}, Vector{Counters: []Counter{{ID: 42, Value: 0}}}, Equal},
|
||||||
{Vector{[]Counter{{42, 0}}}, Vector{}, Equal},
|
{Vector{Counters: []Counter{{ID: 42, Value: 0}}}, Vector{}, Equal},
|
||||||
|
|
||||||
// Zero is the implied value for a missing Counter
|
// Zero is the implied value for a missing Counter
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 0}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 0}}},
|
||||||
Vector{[]Counter{{77, 0}}},
|
Vector{Counters: []Counter{{ID: 77, Value: 0}}},
|
||||||
Equal,
|
Equal,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Equal vectors are equal
|
// Equal vectors are equal
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 33}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 33}}},
|
||||||
Vector{[]Counter{{42, 33}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 33}}},
|
||||||
Equal,
|
Equal,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 33}, {77, 24}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 33}, {ID: 77, Value: 24}}},
|
||||||
Vector{[]Counter{{42, 33}, {77, 24}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 33}, {ID: 77, Value: 24}}},
|
||||||
Equal,
|
Equal,
|
||||||
},
|
},
|
||||||
|
|
||||||
// These a-vectors are all greater than the b-vector
|
// These a-vectors are all greater than the b-vector
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 1}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 1}}},
|
||||||
Vector{},
|
Vector{},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{0, 1}}},
|
Vector{Counters: []Counter{{ID: 0, Value: 1}}},
|
||||||
Vector{[]Counter{{0, 0}}},
|
Vector{Counters: []Counter{{ID: 0, Value: 0}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 1}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{42, 0}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 0}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{math.MaxUint64, 1}}},
|
Vector{Counters: []Counter{{ID: math.MaxUint64, Value: 1}}},
|
||||||
Vector{[]Counter{{math.MaxUint64, 0}}},
|
Vector{Counters: []Counter{{ID: math.MaxUint64, Value: 0}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{0, math.MaxUint64}}},
|
Vector{Counters: []Counter{{ID: 0, Value: math.MaxUint64}}},
|
||||||
Vector{[]Counter{{0, 0}}},
|
Vector{Counters: []Counter{{ID: 0, Value: 0}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, math.MaxUint64}}},
|
Vector{Counters: []Counter{{ID: 42, Value: math.MaxUint64}}},
|
||||||
Vector{[]Counter{{42, 0}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 0}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{math.MaxUint64, math.MaxUint64}}},
|
Vector{Counters: []Counter{{ID: math.MaxUint64, Value: math.MaxUint64}}},
|
||||||
Vector{[]Counter{{math.MaxUint64, 0}}},
|
Vector{Counters: []Counter{{ID: math.MaxUint64, Value: 0}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{0, math.MaxUint64}}},
|
Vector{Counters: []Counter{{ID: 0, Value: math.MaxUint64}}},
|
||||||
Vector{[]Counter{{0, math.MaxUint64 - 1}}},
|
Vector{Counters: []Counter{{ID: 0, Value: math.MaxUint64 - 1}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, math.MaxUint64}}},
|
Vector{Counters: []Counter{{ID: 42, Value: math.MaxUint64}}},
|
||||||
Vector{[]Counter{{42, math.MaxUint64 - 1}}},
|
Vector{Counters: []Counter{{ID: 42, Value: math.MaxUint64 - 1}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{math.MaxUint64, math.MaxUint64}}},
|
Vector{Counters: []Counter{{ID: math.MaxUint64, Value: math.MaxUint64}}},
|
||||||
Vector{[]Counter{{math.MaxUint64, math.MaxUint64 - 1}}},
|
Vector{Counters: []Counter{{ID: math.MaxUint64, Value: math.MaxUint64 - 1}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 2}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 2}}},
|
||||||
Vector{[]Counter{{42, 1}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 1}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 22}, {42, 2}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 2}}},
|
||||||
Vector{[]Counter{{22, 22}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 1}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 2}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 2}, {ID: 77, Value: 3}}},
|
||||||
Vector{[]Counter{{42, 1}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 1}, {ID: 77, Value: 3}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 22}, {42, 2}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 2}, {ID: 77, Value: 3}}},
|
||||||
Vector{[]Counter{{22, 22}, {42, 1}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 1}, {ID: 77, Value: 3}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 23}, {42, 2}, {77, 4}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 23}, {ID: 42, Value: 2}, {ID: 77, Value: 4}}},
|
||||||
Vector{[]Counter{{22, 22}, {42, 1}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 1}, {ID: 77, Value: 3}}},
|
||||||
Greater,
|
Greater,
|
||||||
},
|
},
|
||||||
|
|
||||||
// These a-vectors are all lesser than the b-vector
|
// These a-vectors are all lesser than the b-vector
|
||||||
{Vector{}, Vector{[]Counter{{42, 1}}}, Lesser},
|
{Vector{}, Vector{Counters: []Counter{{ID: 42, Value: 1}}}, Lesser},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 0}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 0}}},
|
||||||
Vector{[]Counter{{42, 1}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 1}}},
|
||||||
Lesser,
|
Lesser,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 1}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{42, 2}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 2}}},
|
||||||
Lesser,
|
Lesser,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 22}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 22}, {42, 2}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 2}}},
|
||||||
Lesser,
|
Lesser,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 1}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 1}, {ID: 77, Value: 3}}},
|
||||||
Vector{[]Counter{{42, 2}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 2}, {ID: 77, Value: 3}}},
|
||||||
Lesser,
|
Lesser,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 22}, {42, 1}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 1}, {ID: 77, Value: 3}}},
|
||||||
Vector{[]Counter{{22, 22}, {42, 2}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 2}, {ID: 77, Value: 3}}},
|
||||||
Lesser,
|
Lesser,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 22}, {42, 1}, {77, 3}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 1}, {ID: 77, Value: 3}}},
|
||||||
Vector{[]Counter{{22, 23}, {42, 2}, {77, 4}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 23}, {ID: 42, Value: 2}, {ID: 77, Value: 4}}},
|
||||||
Lesser,
|
Lesser,
|
||||||
},
|
},
|
||||||
|
|
||||||
// These are all in conflict
|
// These are all in conflict
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{42, 2}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 2}}},
|
||||||
Vector{[]Counter{{43, 1}}},
|
Vector{Counters: []Counter{{ID: 43, Value: 1}}},
|
||||||
ConcurrentGreater,
|
ConcurrentGreater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{43, 1}}},
|
Vector{Counters: []Counter{{ID: 43, Value: 1}}},
|
||||||
Vector{[]Counter{{42, 2}}},
|
Vector{Counters: []Counter{{ID: 42, Value: 2}}},
|
||||||
ConcurrentLesser,
|
ConcurrentLesser,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 23}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 23}, {ID: 42, Value: 1}}},
|
||||||
Vector{[]Counter{{22, 22}, {42, 2}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 2}}},
|
||||||
ConcurrentGreater,
|
ConcurrentGreater,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 21}, {42, 2}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 21}, {ID: 42, Value: 2}}},
|
||||||
Vector{[]Counter{{22, 22}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 22}, {ID: 42, Value: 1}}},
|
||||||
ConcurrentLesser,
|
ConcurrentLesser,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Vector{[]Counter{{22, 21}, {42, 2}, {43, 1}}},
|
Vector{Counters: []Counter{{ID: 22, Value: 21}, {ID: 42, Value: 2}, {ID: 43, Value: 1}}},
|
||||||
Vector{[]Counter{{20, 1}, {22, 22}, {42, 1}}},
|
Vector{Counters: []Counter{{ID: 20, Value: 1}, {ID: 22, Value: 22}, {ID: 42, Value: 1}}},
|
||||||
ConcurrentLesser,
|
ConcurrentLesser,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Copyright (C) 2015 Audrius Butkevicius and Contributors (see the CONTRIBUTORS file).
|
// Copyright (C) 2015 Audrius Butkevicius and Contributors (see the CONTRIBUTORS file).
|
||||||
|
|
||||||
//go:generate -command genxdr go run ../../../vendor/github.com/calmh/xdr/cmd/genxdr/main.go
|
//go:generate -command genxdr go run ../../../repos/xdr/cmd/genxdr/main.go
|
||||||
//go:generate genxdr -o packets_xdr.go packets.go
|
//go:generate genxdr -o packets_xdr.go packets.go
|
||||||
|
|
||||||
package protocol
|
package protocol
|
||||||
|
201
vendor/code.cloudfoundry.org/bytefmt/LICENSE
generated
vendored
201
vendor/code.cloudfoundry.org/bytefmt/LICENSE
generated
vendored
@ -1,201 +0,0 @@
|
|||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
105
vendor/code.cloudfoundry.org/bytefmt/bytes.go
generated
vendored
105
vendor/code.cloudfoundry.org/bytefmt/bytes.go
generated
vendored
@ -1,105 +0,0 @@
|
|||||||
// Package bytefmt contains helper methods and constants for converting to and from a human-readable byte format.
|
|
||||||
//
|
|
||||||
// bytefmt.ByteSize(100.5*bytefmt.MEGABYTE) // "100.5M"
|
|
||||||
// bytefmt.ByteSize(uint64(1024)) // "1K"
|
|
||||||
//
|
|
||||||
package bytefmt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
BYTE = 1.0
|
|
||||||
KILOBYTE = 1024 * BYTE
|
|
||||||
MEGABYTE = 1024 * KILOBYTE
|
|
||||||
GIGABYTE = 1024 * MEGABYTE
|
|
||||||
TERABYTE = 1024 * GIGABYTE
|
|
||||||
)
|
|
||||||
|
|
||||||
var bytesPattern *regexp.Regexp = regexp.MustCompile(`(?i)^(-?\d+(?:\.\d+)?)([KMGT]i?B?|B)$`)
|
|
||||||
|
|
||||||
var invalidByteQuantityError = errors.New("Byte quantity must be a positive integer with a unit of measurement like M, MB, MiB, G, GiB, or GB")
|
|
||||||
|
|
||||||
// ByteSize returns a human-readable byte string of the form 10M, 12.5K, and so forth. The following units are available:
|
|
||||||
// T: Terabyte
|
|
||||||
// G: Gigabyte
|
|
||||||
// M: Megabyte
|
|
||||||
// K: Kilobyte
|
|
||||||
// B: Byte
|
|
||||||
// The unit that results in the smallest number greater than or equal to 1 is always chosen.
|
|
||||||
func ByteSize(bytes uint64) string {
|
|
||||||
unit := ""
|
|
||||||
value := float32(bytes)
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case bytes >= TERABYTE:
|
|
||||||
unit = "T"
|
|
||||||
value = value / TERABYTE
|
|
||||||
case bytes >= GIGABYTE:
|
|
||||||
unit = "G"
|
|
||||||
value = value / GIGABYTE
|
|
||||||
case bytes >= MEGABYTE:
|
|
||||||
unit = "M"
|
|
||||||
value = value / MEGABYTE
|
|
||||||
case bytes >= KILOBYTE:
|
|
||||||
unit = "K"
|
|
||||||
value = value / KILOBYTE
|
|
||||||
case bytes >= BYTE:
|
|
||||||
unit = "B"
|
|
||||||
case bytes == 0:
|
|
||||||
return "0"
|
|
||||||
}
|
|
||||||
|
|
||||||
stringValue := fmt.Sprintf("%.1f", value)
|
|
||||||
stringValue = strings.TrimSuffix(stringValue, ".0")
|
|
||||||
return fmt.Sprintf("%s%s", stringValue, unit)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToMegabytes parses a string formatted by ByteSize as megabytes.
|
|
||||||
func ToMegabytes(s string) (uint64, error) {
|
|
||||||
bytes, err := ToBytes(s)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytes / MEGABYTE, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToBytes parses a string formatted by ByteSize as bytes. Note binary-prefixed and SI prefixed units both mean a base-2 units
|
|
||||||
// KB = K = KiB = 1024
|
|
||||||
// MB = M = MiB = 1024 * K
|
|
||||||
// GB = G = GiB = 1024 * M
|
|
||||||
// TB = T = TiB = 1024 * G
|
|
||||||
func ToBytes(s string) (uint64, error) {
|
|
||||||
parts := bytesPattern.FindStringSubmatch(strings.TrimSpace(s))
|
|
||||||
if len(parts) < 3 {
|
|
||||||
return 0, invalidByteQuantityError
|
|
||||||
}
|
|
||||||
|
|
||||||
value, err := strconv.ParseFloat(parts[1], 64)
|
|
||||||
if err != nil || value <= 0 {
|
|
||||||
return 0, invalidByteQuantityError
|
|
||||||
}
|
|
||||||
|
|
||||||
var bytes uint64
|
|
||||||
unit := strings.ToUpper(parts[2])
|
|
||||||
switch unit[:1] {
|
|
||||||
case "T":
|
|
||||||
bytes = uint64(value * TERABYTE)
|
|
||||||
case "G":
|
|
||||||
bytes = uint64(value * GIGABYTE)
|
|
||||||
case "M":
|
|
||||||
bytes = uint64(value * MEGABYTE)
|
|
||||||
case "K":
|
|
||||||
bytes = uint64(value * KILOBYTE)
|
|
||||||
case "B":
|
|
||||||
bytes = uint64(value * BYTE)
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytes, nil
|
|
||||||
}
|
|
1
vendor/code.cloudfoundry.org/bytefmt/package.go
generated
vendored
1
vendor/code.cloudfoundry.org/bytefmt/package.go
generated
vendored
@ -1 +0,0 @@
|
|||||||
package bytefmt // import "code.cloudfoundry.org/bytefmt"
|
|
6
vendor/github.com/AudriusButkevicius/cli/.travis.yml
generated
vendored
Normal file
6
vendor/github.com/AudriusButkevicius/cli/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
language: go
|
||||||
|
go: 1.1
|
||||||
|
|
||||||
|
script:
|
||||||
|
- go vet ./...
|
||||||
|
- go test -v ./...
|
280
vendor/github.com/AudriusButkevicius/cli/README.md
generated
vendored
Normal file
280
vendor/github.com/AudriusButkevicius/cli/README.md
generated
vendored
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
[![Build Status](https://travis-ci.org/codegangsta/cli.png?branch=master)](https://travis-ci.org/codegangsta/cli)
|
||||||
|
|
||||||
|
# cli.go
|
||||||
|
cli.go is simple, fast, and fun package for building command line apps in Go. The goal is to enable developers to write fast and distributable command line applications in an expressive way.
|
||||||
|
|
||||||
|
You can view the API docs here:
|
||||||
|
http://godoc.org/github.com/codegangsta/cli
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
Command line apps are usually so tiny that there is absolutely no reason why your code should *not* be self-documenting. Things like generating help text and parsing command flags/options should not hinder productivity when writing a command line app.
|
||||||
|
|
||||||
|
This is where cli.go comes into play. cli.go makes command line programming fun, organized, and expressive!
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
Make sure you have a working Go environment (go 1.1 is *required*). [See the install instructions](http://golang.org/doc/install.html).
|
||||||
|
|
||||||
|
To install cli.go, simply run:
|
||||||
|
```
|
||||||
|
$ go get github.com/codegangsta/cli
|
||||||
|
```
|
||||||
|
|
||||||
|
Make sure your PATH includes to the `$GOPATH/bin` directory so your commands can be easily used:
|
||||||
|
```
|
||||||
|
export PATH=$PATH:$GOPATH/bin
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
One of the philosophies behind cli.go is that an API should be playful and full of discovery. So a cli.go app can be as little as one line of code in `main()`.
|
||||||
|
|
||||||
|
``` go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cli.NewApp().Run(os.Args)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This app will run and show help text, but is not very useful. Let's give an action to execute and some help documentation:
|
||||||
|
|
||||||
|
``` go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "boom"
|
||||||
|
app.Usage = "make an explosive entrance"
|
||||||
|
app.Action = func(c *cli.Context) {
|
||||||
|
println("boom! I say!")
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run(os.Args)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Running this already gives you a ton of functionality, plus support for things like subcommands and flags, which are covered below.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Being a programmer can be a lonely job. Thankfully by the power of automation that is not the case! Let's create a greeter app to fend off our demons of loneliness!
|
||||||
|
|
||||||
|
``` go
|
||||||
|
/* greet.go */
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "greet"
|
||||||
|
app.Usage = "fight the loneliness!"
|
||||||
|
app.Action = func(c *cli.Context) {
|
||||||
|
println("Hello friend!")
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run(os.Args)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Install our command to the `$GOPATH/bin` directory:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ go install
|
||||||
|
```
|
||||||
|
|
||||||
|
Finally run our new command:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ greet
|
||||||
|
Hello friend!
|
||||||
|
```
|
||||||
|
|
||||||
|
cli.go also generates some bitchass help text:
|
||||||
|
```
|
||||||
|
$ greet help
|
||||||
|
NAME:
|
||||||
|
greet - fight the loneliness!
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
greet [global options] command [command options] [arguments...]
|
||||||
|
|
||||||
|
VERSION:
|
||||||
|
0.0.0
|
||||||
|
|
||||||
|
COMMANDS:
|
||||||
|
help, h Shows a list of commands or help for one command
|
||||||
|
|
||||||
|
GLOBAL OPTIONS
|
||||||
|
--version Shows version information
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arguments
|
||||||
|
You can lookup arguments by calling the `Args` function on cli.Context.
|
||||||
|
|
||||||
|
``` go
|
||||||
|
...
|
||||||
|
app.Action = func(c *cli.Context) {
|
||||||
|
println("Hello", c.Args()[0])
|
||||||
|
}
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Flags
|
||||||
|
Setting and querying flags is simple.
|
||||||
|
``` go
|
||||||
|
...
|
||||||
|
app.Flags = []cli.Flag {
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "lang",
|
||||||
|
Value: "english",
|
||||||
|
Usage: "language for the greeting",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app.Action = func(c *cli.Context) {
|
||||||
|
name := "someone"
|
||||||
|
if len(c.Args()) > 0 {
|
||||||
|
name = c.Args()[0]
|
||||||
|
}
|
||||||
|
if c.String("lang") == "spanish" {
|
||||||
|
println("Hola", name)
|
||||||
|
} else {
|
||||||
|
println("Hello", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Alternate Names
|
||||||
|
|
||||||
|
You can set alternate (or short) names for flags by providing a comma-delimited list for the Name. e.g.
|
||||||
|
|
||||||
|
``` go
|
||||||
|
app.Flags = []cli.Flag {
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "lang, l",
|
||||||
|
Value: "english",
|
||||||
|
Usage: "language for the greeting",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Values from the Environment
|
||||||
|
|
||||||
|
You can also have the default value set from the environment via EnvVar. e.g.
|
||||||
|
|
||||||
|
``` go
|
||||||
|
app.Flags = []cli.Flag {
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "lang, l",
|
||||||
|
Value: "english",
|
||||||
|
Usage: "language for the greeting",
|
||||||
|
EnvVar: "APP_LANG",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
That flag can then be set with `--lang spanish` or `-l spanish`. Note that giving two different forms of the same flag in the same command invocation is an error.
|
||||||
|
|
||||||
|
### Subcommands
|
||||||
|
|
||||||
|
Subcommands can be defined for a more git-like command line app.
|
||||||
|
```go
|
||||||
|
...
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "add",
|
||||||
|
ShortName: "a",
|
||||||
|
Usage: "add a task to the list",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("added task: ", c.Args().First())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "complete",
|
||||||
|
ShortName: "c",
|
||||||
|
Usage: "complete a task on the list",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("completed task: ", c.Args().First())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "template",
|
||||||
|
ShortName: "r",
|
||||||
|
Usage: "options for task templates",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "add",
|
||||||
|
Usage: "add a new template",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("new task template: ", c.Args().First())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "remove",
|
||||||
|
Usage: "remove an existing template",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("removed task template: ", c.Args().First())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Bash Completion
|
||||||
|
|
||||||
|
You can enable completion commands by setting the EnableBashCompletion
|
||||||
|
flag on the App object. By default, this setting will only auto-complete to
|
||||||
|
show an app's subcommands, but you can write your own completion methods for
|
||||||
|
the App or its subcommands.
|
||||||
|
```go
|
||||||
|
...
|
||||||
|
var tasks = []string{"cook", "clean", "laundry", "eat", "sleep", "code"}
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.EnableBashCompletion = true
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "complete",
|
||||||
|
ShortName: "c",
|
||||||
|
Usage: "complete a task on the list",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("completed task: ", c.Args().First())
|
||||||
|
},
|
||||||
|
BashComplete: func(c *cli.Context) {
|
||||||
|
// This will complete if no args are passed
|
||||||
|
if len(c.Args()) > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, t := range tasks {
|
||||||
|
println(t)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
#### To Enable
|
||||||
|
|
||||||
|
Source the autocomplete/bash_autocomplete file in your .bashrc file while
|
||||||
|
setting the PROG variable to the name of your program:
|
||||||
|
|
||||||
|
`PROG=myprogram source /.../cli/autocomplete/bash_autocomplete`
|
||||||
|
|
||||||
|
|
||||||
|
## About
|
||||||
|
cli.go is written by none other than the [Code Gangsta](http://codegangsta.io)
|
48
vendor/github.com/AudriusButkevicius/go-nat-pmp/README.md
generated
vendored
Normal file
48
vendor/github.com/AudriusButkevicius/go-nat-pmp/README.md
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
go-nat-pmp
|
||||||
|
==========
|
||||||
|
|
||||||
|
A Go language client for the NAT-PMP internet protocol for port mapping and discovering the external
|
||||||
|
IP address of a firewall.
|
||||||
|
|
||||||
|
NAT-PMP is supported by Apple brand routers and open source routers like Tomato and DD-WRT.
|
||||||
|
|
||||||
|
See http://tools.ietf.org/html/draft-cheshire-nat-pmp-03
|
||||||
|
|
||||||
|
Get the package
|
||||||
|
---------------
|
||||||
|
|
||||||
|
go get -u github.com/jackpal/go-nat-pmp
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
import natpmp "github.com/jackpal/go-nat-pmp"
|
||||||
|
|
||||||
|
client := natpmp.NewClient(gatewayIP)
|
||||||
|
response, err := client.GetExternalAddress()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
print("External IP address:", response.ExternalIPAddress)
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
There doesn't seem to be an easy way to programmatically determine the address of the default gateway.
|
||||||
|
(Linux and OSX have a "routes" kernel API that can be examined to get this information, but there is
|
||||||
|
no Go package for getting this information.)
|
||||||
|
|
||||||
|
Clients
|
||||||
|
-------
|
||||||
|
|
||||||
|
This library is used in the Taipei Torrent BitTorrent client http://github.com/jackpal/Taipei-Torrent
|
||||||
|
|
||||||
|
Complete documentation
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
http://godoc.org/github.com/jackpal/go-nat-pmp
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
This project is licensed under the Apache License 2.0.
|
21
vendor/github.com/AudriusButkevicius/pfilter/LICENSE
generated
vendored
21
vendor/github.com/AudriusButkevicius/pfilter/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2016 Audrius Butkevicius
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
97
vendor/github.com/AudriusButkevicius/pfilter/conn.go
generated
vendored
97
vendor/github.com/AudriusButkevicius/pfilter/conn.go
generated
vendored
@ -1,97 +0,0 @@
|
|||||||
package pfilter
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FilteredConn struct {
|
|
||||||
// Alignment
|
|
||||||
deadline atomic.Value
|
|
||||||
|
|
||||||
source *PacketFilter
|
|
||||||
priority int
|
|
||||||
|
|
||||||
recvBuffer chan packet
|
|
||||||
|
|
||||||
filter Filter
|
|
||||||
|
|
||||||
closed chan struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// LocalAddr returns the local address
|
|
||||||
func (r *FilteredConn) LocalAddr() net.Addr {
|
|
||||||
return r.source.LocalAddr()
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetReadDeadline sets a read deadline
|
|
||||||
func (r *FilteredConn) SetReadDeadline(t time.Time) error {
|
|
||||||
r.deadline.Store(t)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetWriteDeadline sets a write deadline
|
|
||||||
func (r *FilteredConn) SetWriteDeadline(t time.Time) error {
|
|
||||||
return r.source.SetWriteDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDeadline sets a read and a write deadline
|
|
||||||
func (r *FilteredConn) SetDeadline(t time.Time) error {
|
|
||||||
r.SetReadDeadline(t)
|
|
||||||
return r.SetWriteDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteTo writes bytes to the given address
|
|
||||||
func (r *FilteredConn) WriteTo(b []byte, addr net.Addr) (n int, err error) {
|
|
||||||
select {
|
|
||||||
case <-r.closed:
|
|
||||||
return 0, errClosed
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.filter != nil {
|
|
||||||
r.filter.Outgoing(b, addr)
|
|
||||||
}
|
|
||||||
return r.source.WriteTo(b, addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadFrom reads from the filtered connection
|
|
||||||
func (r *FilteredConn) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
|
|
||||||
select {
|
|
||||||
case <-r.closed:
|
|
||||||
return 0, nil, errClosed
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
var timeout <-chan time.Time
|
|
||||||
|
|
||||||
if deadline, ok := r.deadline.Load().(time.Time); ok && !deadline.IsZero() {
|
|
||||||
timer := time.NewTimer(deadline.Sub(time.Now()))
|
|
||||||
timeout = timer.C
|
|
||||||
defer timer.Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-timeout:
|
|
||||||
return 0, nil, errTimeout
|
|
||||||
case pkt := <-r.recvBuffer:
|
|
||||||
copy(b[:pkt.n], pkt.buf)
|
|
||||||
bufPool.Put(pkt.buf[:maxPacketSize])
|
|
||||||
return pkt.n, pkt.addr, pkt.err
|
|
||||||
case <-r.closed:
|
|
||||||
return 0, nil, errClosed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes the filtered connection, removing it's filters
|
|
||||||
func (r *FilteredConn) Close() error {
|
|
||||||
select {
|
|
||||||
case <-r.closed:
|
|
||||||
return errClosed
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
close(r.closed)
|
|
||||||
r.source.removeConn(r)
|
|
||||||
return nil
|
|
||||||
}
|
|
135
vendor/github.com/AudriusButkevicius/pfilter/filter.go
generated
vendored
135
vendor/github.com/AudriusButkevicius/pfilter/filter.go
generated
vendored
@ -1,135 +0,0 @@
|
|||||||
package pfilter
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"sort"
|
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Filter object receives all data sent out on the Outgoing callback,
|
|
||||||
// and is expected to decide if it wants to receive the packet or not via
|
|
||||||
// the Receive callback
|
|
||||||
type Filter interface {
|
|
||||||
Outgoing([]byte, net.Addr)
|
|
||||||
ClaimIncoming([]byte, net.Addr) bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPacketFilter creates a packet filter object wrapping the given packet
|
|
||||||
// connection.
|
|
||||||
func NewPacketFilter(conn net.PacketConn) *PacketFilter {
|
|
||||||
d := &PacketFilter{
|
|
||||||
PacketConn: conn,
|
|
||||||
}
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
// PacketFilter embeds a net.PacketConn to perform the filtering.
|
|
||||||
type PacketFilter struct {
|
|
||||||
// Alignment
|
|
||||||
dropped uint64
|
|
||||||
overflow uint64
|
|
||||||
|
|
||||||
net.PacketConn
|
|
||||||
|
|
||||||
conns []*FilteredConn
|
|
||||||
mut sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewConn returns a new net.PacketConn object which filters packets based
|
|
||||||
// on the provided filter. If filter is nil, the connection will receive all
|
|
||||||
// packets. Priority decides which connection gets the ability to claim the packet.
|
|
||||||
func (d *PacketFilter) NewConn(priority int, filter Filter) net.PacketConn {
|
|
||||||
conn := &FilteredConn{
|
|
||||||
priority: priority,
|
|
||||||
source: d,
|
|
||||||
recvBuffer: make(chan packet, 256),
|
|
||||||
filter: filter,
|
|
||||||
closed: make(chan struct{}),
|
|
||||||
}
|
|
||||||
d.mut.Lock()
|
|
||||||
d.conns = append(d.conns, conn)
|
|
||||||
sort.Sort(filteredConnList(d.conns))
|
|
||||||
d.mut.Unlock()
|
|
||||||
return conn
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *PacketFilter) removeConn(r *FilteredConn) {
|
|
||||||
d.mut.Lock()
|
|
||||||
for i, conn := range d.conns {
|
|
||||||
if conn == r {
|
|
||||||
copy(d.conns[i:], d.conns[i+1:])
|
|
||||||
d.conns[len(d.conns)-1] = nil
|
|
||||||
d.conns = d.conns[:len(d.conns)-1]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
d.mut.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NumberOfConns returns the number of currently active virtual connections
|
|
||||||
func (d *PacketFilter) NumberOfConns() int {
|
|
||||||
d.mut.Lock()
|
|
||||||
n := len(d.conns)
|
|
||||||
d.mut.Unlock()
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dropped returns number of packets dropped due to nobody claiming them.
|
|
||||||
func (d *PacketFilter) Dropped() uint64 {
|
|
||||||
return atomic.LoadUint64(&d.dropped)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Overflow returns number of packets were dropped due to receive buffers being
|
|
||||||
// full.
|
|
||||||
func (d *PacketFilter) Overflow() uint64 {
|
|
||||||
return atomic.LoadUint64(&d.overflow)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start starts the packet filter.
|
|
||||||
func (d *PacketFilter) Start() {
|
|
||||||
go d.loop()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *PacketFilter) loop() {
|
|
||||||
var buf []byte
|
|
||||||
next:
|
|
||||||
for {
|
|
||||||
buf = bufPool.Get().([]byte)
|
|
||||||
n, addr, err := d.ReadFrom(buf)
|
|
||||||
pkt := packet{
|
|
||||||
n: n,
|
|
||||||
addr: addr,
|
|
||||||
err: err,
|
|
||||||
buf: buf[:n],
|
|
||||||
}
|
|
||||||
|
|
||||||
d.mut.Lock()
|
|
||||||
conns := d.conns
|
|
||||||
d.mut.Unlock()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
for _, conn := range conns {
|
|
||||||
select {
|
|
||||||
case conn.recvBuffer <- pkt:
|
|
||||||
default:
|
|
||||||
atomic.AddUint64(&d.overflow, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, conn := range conns {
|
|
||||||
if conn.filter == nil || conn.filter.ClaimIncoming(pkt.buf, pkt.addr) {
|
|
||||||
select {
|
|
||||||
case conn.recvBuffer <- pkt:
|
|
||||||
default:
|
|
||||||
atomic.AddUint64(&d.overflow, 1)
|
|
||||||
}
|
|
||||||
goto next
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
atomic.AddUint64(&d.dropped, 1)
|
|
||||||
}
|
|
||||||
}
|
|
51
vendor/github.com/AudriusButkevicius/pfilter/misc.go
generated
vendored
51
vendor/github.com/AudriusButkevicius/pfilter/misc.go
generated
vendored
@ -1,51 +0,0 @@
|
|||||||
package pfilter
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
maxPacketSize = 1500
|
|
||||||
bufPool = sync.Pool{
|
|
||||||
New: func() interface{} {
|
|
||||||
return make([]byte, maxPacketSize)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
errTimeout = &netError{
|
|
||||||
msg: "i/o timeout",
|
|
||||||
timeout: true,
|
|
||||||
temporary: true,
|
|
||||||
}
|
|
||||||
errClosed = &netError{
|
|
||||||
msg: "use of closed network connection",
|
|
||||||
timeout: false,
|
|
||||||
temporary: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile time interface assertion.
|
|
||||||
_ net.Error = (*netError)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
type netError struct {
|
|
||||||
msg string
|
|
||||||
timeout bool
|
|
||||||
temporary bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *netError) Error() string { return e.msg }
|
|
||||||
func (e *netError) Timeout() bool { return e.timeout }
|
|
||||||
func (e *netError) Temporary() bool { return e.temporary }
|
|
||||||
|
|
||||||
type filteredConnList []*FilteredConn
|
|
||||||
|
|
||||||
func (r filteredConnList) Len() int { return len(r) }
|
|
||||||
func (r filteredConnList) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
|
|
||||||
func (r filteredConnList) Less(i, j int) bool { return r[i].priority < r[j].priority }
|
|
||||||
|
|
||||||
type packet struct {
|
|
||||||
n int
|
|
||||||
addr net.Addr
|
|
||||||
err error
|
|
||||||
buf []byte
|
|
||||||
}
|
|
21
vendor/github.com/BurntSushi/toml/COPYING
generated
vendored
21
vendor/github.com/BurntSushi/toml/COPYING
generated
vendored
@ -1,21 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2013 TOML authors
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
90
vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/main.go
generated
vendored
90
vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/main.go
generated
vendored
@ -1,90 +0,0 @@
|
|||||||
// Command toml-test-decoder satisfies the toml-test interface for testing
|
|
||||||
// TOML decoders. Namely, it accepts TOML on stdin and outputs JSON on stdout.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
log.SetFlags(0)
|
|
||||||
|
|
||||||
flag.Usage = usage
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func usage() {
|
|
||||||
log.Printf("Usage: %s < toml-file\n", path.Base(os.Args[0]))
|
|
||||||
flag.PrintDefaults()
|
|
||||||
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if flag.NArg() != 0 {
|
|
||||||
flag.Usage()
|
|
||||||
}
|
|
||||||
|
|
||||||
var tmp interface{}
|
|
||||||
if _, err := toml.DecodeReader(os.Stdin, &tmp); err != nil {
|
|
||||||
log.Fatalf("Error decoding TOML: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
typedTmp := translate(tmp)
|
|
||||||
if err := json.NewEncoder(os.Stdout).Encode(typedTmp); err != nil {
|
|
||||||
log.Fatalf("Error encoding JSON: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func translate(tomlData interface{}) interface{} {
|
|
||||||
switch orig := tomlData.(type) {
|
|
||||||
case map[string]interface{}:
|
|
||||||
typed := make(map[string]interface{}, len(orig))
|
|
||||||
for k, v := range orig {
|
|
||||||
typed[k] = translate(v)
|
|
||||||
}
|
|
||||||
return typed
|
|
||||||
case []map[string]interface{}:
|
|
||||||
typed := make([]map[string]interface{}, len(orig))
|
|
||||||
for i, v := range orig {
|
|
||||||
typed[i] = translate(v).(map[string]interface{})
|
|
||||||
}
|
|
||||||
return typed
|
|
||||||
case []interface{}:
|
|
||||||
typed := make([]interface{}, len(orig))
|
|
||||||
for i, v := range orig {
|
|
||||||
typed[i] = translate(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't really need to tag arrays, but let's be future proof.
|
|
||||||
// (If TOML ever supports tuples, we'll need this.)
|
|
||||||
return tag("array", typed)
|
|
||||||
case time.Time:
|
|
||||||
return tag("datetime", orig.Format("2006-01-02T15:04:05Z"))
|
|
||||||
case bool:
|
|
||||||
return tag("bool", fmt.Sprintf("%v", orig))
|
|
||||||
case int64:
|
|
||||||
return tag("integer", fmt.Sprintf("%d", orig))
|
|
||||||
case float64:
|
|
||||||
return tag("float", fmt.Sprintf("%v", orig))
|
|
||||||
case string:
|
|
||||||
return tag("string", orig)
|
|
||||||
}
|
|
||||||
|
|
||||||
panic(fmt.Sprintf("Unknown type: %T", tomlData))
|
|
||||||
}
|
|
||||||
|
|
||||||
func tag(typeName string, data interface{}) map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"type": typeName,
|
|
||||||
"value": data,
|
|
||||||
}
|
|
||||||
}
|
|
131
vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/main.go
generated
vendored
131
vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/main.go
generated
vendored
@ -1,131 +0,0 @@
|
|||||||
// Command toml-test-encoder satisfies the toml-test interface for testing
|
|
||||||
// TOML encoders. Namely, it accepts JSON on stdin and outputs TOML on stdout.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
log.SetFlags(0)
|
|
||||||
|
|
||||||
flag.Usage = usage
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func usage() {
|
|
||||||
log.Printf("Usage: %s < json-file\n", path.Base(os.Args[0]))
|
|
||||||
flag.PrintDefaults()
|
|
||||||
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if flag.NArg() != 0 {
|
|
||||||
flag.Usage()
|
|
||||||
}
|
|
||||||
|
|
||||||
var tmp interface{}
|
|
||||||
if err := json.NewDecoder(os.Stdin).Decode(&tmp); err != nil {
|
|
||||||
log.Fatalf("Error decoding JSON: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tomlData := translate(tmp)
|
|
||||||
if err := toml.NewEncoder(os.Stdout).Encode(tomlData); err != nil {
|
|
||||||
log.Fatalf("Error encoding TOML: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func translate(typedJson interface{}) interface{} {
|
|
||||||
switch v := typedJson.(type) {
|
|
||||||
case map[string]interface{}:
|
|
||||||
if len(v) == 2 && in("type", v) && in("value", v) {
|
|
||||||
return untag(v)
|
|
||||||
}
|
|
||||||
m := make(map[string]interface{}, len(v))
|
|
||||||
for k, v2 := range v {
|
|
||||||
m[k] = translate(v2)
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
case []interface{}:
|
|
||||||
tabArray := make([]map[string]interface{}, len(v))
|
|
||||||
for i := range v {
|
|
||||||
if m, ok := translate(v[i]).(map[string]interface{}); ok {
|
|
||||||
tabArray[i] = m
|
|
||||||
} else {
|
|
||||||
log.Fatalf("JSON arrays may only contain objects. This " +
|
|
||||||
"corresponds to only tables being allowed in " +
|
|
||||||
"TOML table arrays.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tabArray
|
|
||||||
}
|
|
||||||
log.Fatalf("Unrecognized JSON format '%T'.", typedJson)
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
func untag(typed map[string]interface{}) interface{} {
|
|
||||||
t := typed["type"].(string)
|
|
||||||
v := typed["value"]
|
|
||||||
switch t {
|
|
||||||
case "string":
|
|
||||||
return v.(string)
|
|
||||||
case "integer":
|
|
||||||
v := v.(string)
|
|
||||||
n, err := strconv.Atoi(v)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not parse '%s' as integer: %s", v, err)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
case "float":
|
|
||||||
v := v.(string)
|
|
||||||
f, err := strconv.ParseFloat(v, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not parse '%s' as float64: %s", v, err)
|
|
||||||
}
|
|
||||||
return f
|
|
||||||
case "datetime":
|
|
||||||
v := v.(string)
|
|
||||||
t, err := time.Parse("2006-01-02T15:04:05Z", v)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not parse '%s' as a datetime: %s", v, err)
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
case "bool":
|
|
||||||
v := v.(string)
|
|
||||||
switch v {
|
|
||||||
case "true":
|
|
||||||
return true
|
|
||||||
case "false":
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
log.Fatalf("Could not parse '%s' as a boolean.", v)
|
|
||||||
case "array":
|
|
||||||
v := v.([]interface{})
|
|
||||||
array := make([]interface{}, len(v))
|
|
||||||
for i := range v {
|
|
||||||
if m, ok := v[i].(map[string]interface{}); ok {
|
|
||||||
array[i] = untag(m)
|
|
||||||
} else {
|
|
||||||
log.Fatalf("Arrays may only contain other arrays or "+
|
|
||||||
"primitive values, but found a '%T'.", m)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array
|
|
||||||
}
|
|
||||||
log.Fatalf("Unrecognized tag type '%s'.", t)
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
func in(key string, m map[string]interface{}) bool {
|
|
||||||
_, ok := m[key]
|
|
||||||
return ok
|
|
||||||
}
|
|
61
vendor/github.com/BurntSushi/toml/cmd/tomlv/main.go
generated
vendored
61
vendor/github.com/BurntSushi/toml/cmd/tomlv/main.go
generated
vendored
@ -1,61 +0,0 @@
|
|||||||
// Command tomlv validates TOML documents and prints each key's type.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
"text/tabwriter"
|
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
flagTypes = false
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
log.SetFlags(0)
|
|
||||||
|
|
||||||
flag.BoolVar(&flagTypes, "types", flagTypes,
|
|
||||||
"When set, the types of every defined key will be shown.")
|
|
||||||
|
|
||||||
flag.Usage = usage
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func usage() {
|
|
||||||
log.Printf("Usage: %s toml-file [ toml-file ... ]\n",
|
|
||||||
path.Base(os.Args[0]))
|
|
||||||
flag.PrintDefaults()
|
|
||||||
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if flag.NArg() < 1 {
|
|
||||||
flag.Usage()
|
|
||||||
}
|
|
||||||
for _, f := range flag.Args() {
|
|
||||||
var tmp interface{}
|
|
||||||
md, err := toml.DecodeFile(f, &tmp)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error in '%s': %s", f, err)
|
|
||||||
}
|
|
||||||
if flagTypes {
|
|
||||||
printTypes(md)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func printTypes(md toml.MetaData) {
|
|
||||||
tabw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
|
||||||
for _, key := range md.Keys() {
|
|
||||||
fmt.Fprintf(tabw, "%s%s\t%s\n",
|
|
||||||
strings.Repeat(" ", len(key)-1), key, md.Type(key...))
|
|
||||||
}
|
|
||||||
tabw.Flush()
|
|
||||||
}
|
|
509
vendor/github.com/BurntSushi/toml/decode.go
generated
vendored
509
vendor/github.com/BurntSushi/toml/decode.go
generated
vendored
@ -1,509 +0,0 @@
|
|||||||
package toml
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func e(format string, args ...interface{}) error {
|
|
||||||
return fmt.Errorf("toml: "+format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshaler is the interface implemented by objects that can unmarshal a
|
|
||||||
// TOML description of themselves.
|
|
||||||
type Unmarshaler interface {
|
|
||||||
UnmarshalTOML(interface{}) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmarshal decodes the contents of `p` in TOML format into a pointer `v`.
|
|
||||||
func Unmarshal(p []byte, v interface{}) error {
|
|
||||||
_, err := Decode(string(p), v)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Primitive is a TOML value that hasn't been decoded into a Go value.
|
|
||||||
// When using the various `Decode*` functions, the type `Primitive` may
|
|
||||||
// be given to any value, and its decoding will be delayed.
|
|
||||||
//
|
|
||||||
// A `Primitive` value can be decoded using the `PrimitiveDecode` function.
|
|
||||||
//
|
|
||||||
// The underlying representation of a `Primitive` value is subject to change.
|
|
||||||
// Do not rely on it.
|
|
||||||
//
|
|
||||||
// N.B. Primitive values are still parsed, so using them will only avoid
|
|
||||||
// the overhead of reflection. They can be useful when you don't know the
|
|
||||||
// exact type of TOML data until run time.
|
|
||||||
type Primitive struct {
|
|
||||||
undecoded interface{}
|
|
||||||
context Key
|
|
||||||
}
|
|
||||||
|
|
||||||
// DEPRECATED!
|
|
||||||
//
|
|
||||||
// Use MetaData.PrimitiveDecode instead.
|
|
||||||
func PrimitiveDecode(primValue Primitive, v interface{}) error {
|
|
||||||
md := MetaData{decoded: make(map[string]bool)}
|
|
||||||
return md.unify(primValue.undecoded, rvalue(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrimitiveDecode is just like the other `Decode*` functions, except it
|
|
||||||
// decodes a TOML value that has already been parsed. Valid primitive values
|
|
||||||
// can *only* be obtained from values filled by the decoder functions,
|
|
||||||
// including this method. (i.e., `v` may contain more `Primitive`
|
|
||||||
// values.)
|
|
||||||
//
|
|
||||||
// Meta data for primitive values is included in the meta data returned by
|
|
||||||
// the `Decode*` functions with one exception: keys returned by the Undecoded
|
|
||||||
// method will only reflect keys that were decoded. Namely, any keys hidden
|
|
||||||
// behind a Primitive will be considered undecoded. Executing this method will
|
|
||||||
// update the undecoded keys in the meta data. (See the example.)
|
|
||||||
func (md *MetaData) PrimitiveDecode(primValue Primitive, v interface{}) error {
|
|
||||||
md.context = primValue.context
|
|
||||||
defer func() { md.context = nil }()
|
|
||||||
return md.unify(primValue.undecoded, rvalue(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode will decode the contents of `data` in TOML format into a pointer
|
|
||||||
// `v`.
|
|
||||||
//
|
|
||||||
// TOML hashes correspond to Go structs or maps. (Dealer's choice. They can be
|
|
||||||
// used interchangeably.)
|
|
||||||
//
|
|
||||||
// TOML arrays of tables correspond to either a slice of structs or a slice
|
|
||||||
// of maps.
|
|
||||||
//
|
|
||||||
// TOML datetimes correspond to Go `time.Time` values.
|
|
||||||
//
|
|
||||||
// All other TOML types (float, string, int, bool and array) correspond
|
|
||||||
// to the obvious Go types.
|
|
||||||
//
|
|
||||||
// An exception to the above rules is if a type implements the
|
|
||||||
// encoding.TextUnmarshaler interface. In this case, any primitive TOML value
|
|
||||||
// (floats, strings, integers, booleans and datetimes) will be converted to
|
|
||||||
// a byte string and given to the value's UnmarshalText method. See the
|
|
||||||
// Unmarshaler example for a demonstration with time duration strings.
|
|
||||||
//
|
|
||||||
// Key mapping
|
|
||||||
//
|
|
||||||
// TOML keys can map to either keys in a Go map or field names in a Go
|
|
||||||
// struct. The special `toml` struct tag may be used to map TOML keys to
|
|
||||||
// struct fields that don't match the key name exactly. (See the example.)
|
|
||||||
// A case insensitive match to struct names will be tried if an exact match
|
|
||||||
// can't be found.
|
|
||||||
//
|
|
||||||
// The mapping between TOML values and Go values is loose. That is, there
|
|
||||||
// may exist TOML values that cannot be placed into your representation, and
|
|
||||||
// there may be parts of your representation that do not correspond to
|
|
||||||
// TOML values. This loose mapping can be made stricter by using the IsDefined
|
|
||||||
// and/or Undecoded methods on the MetaData returned.
|
|
||||||
//
|
|
||||||
// This decoder will not handle cyclic types. If a cyclic type is passed,
|
|
||||||
// `Decode` will not terminate.
|
|
||||||
func Decode(data string, v interface{}) (MetaData, error) {
|
|
||||||
rv := reflect.ValueOf(v)
|
|
||||||
if rv.Kind() != reflect.Ptr {
|
|
||||||
return MetaData{}, e("Decode of non-pointer %s", reflect.TypeOf(v))
|
|
||||||
}
|
|
||||||
if rv.IsNil() {
|
|
||||||
return MetaData{}, e("Decode of nil %s", reflect.TypeOf(v))
|
|
||||||
}
|
|
||||||
p, err := parse(data)
|
|
||||||
if err != nil {
|
|
||||||
return MetaData{}, err
|
|
||||||
}
|
|
||||||
md := MetaData{
|
|
||||||
p.mapping, p.types, p.ordered,
|
|
||||||
make(map[string]bool, len(p.ordered)), nil,
|
|
||||||
}
|
|
||||||
return md, md.unify(p.mapping, indirect(rv))
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeFile is just like Decode, except it will automatically read the
|
|
||||||
// contents of the file at `fpath` and decode it for you.
|
|
||||||
func DecodeFile(fpath string, v interface{}) (MetaData, error) {
|
|
||||||
bs, err := ioutil.ReadFile(fpath)
|
|
||||||
if err != nil {
|
|
||||||
return MetaData{}, err
|
|
||||||
}
|
|
||||||
return Decode(string(bs), v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeReader is just like Decode, except it will consume all bytes
|
|
||||||
// from the reader and decode it for you.
|
|
||||||
func DecodeReader(r io.Reader, v interface{}) (MetaData, error) {
|
|
||||||
bs, err := ioutil.ReadAll(r)
|
|
||||||
if err != nil {
|
|
||||||
return MetaData{}, err
|
|
||||||
}
|
|
||||||
return Decode(string(bs), v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// unify performs a sort of type unification based on the structure of `rv`,
|
|
||||||
// which is the client representation.
|
|
||||||
//
|
|
||||||
// Any type mismatch produces an error. Finding a type that we don't know
|
|
||||||
// how to handle produces an unsupported type error.
|
|
||||||
func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
|
|
||||||
|
|
||||||
// Special case. Look for a `Primitive` value.
|
|
||||||
if rv.Type() == reflect.TypeOf((*Primitive)(nil)).Elem() {
|
|
||||||
// Save the undecoded data and the key context into the primitive
|
|
||||||
// value.
|
|
||||||
context := make(Key, len(md.context))
|
|
||||||
copy(context, md.context)
|
|
||||||
rv.Set(reflect.ValueOf(Primitive{
|
|
||||||
undecoded: data,
|
|
||||||
context: context,
|
|
||||||
}))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special case. Unmarshaler Interface support.
|
|
||||||
if rv.CanAddr() {
|
|
||||||
if v, ok := rv.Addr().Interface().(Unmarshaler); ok {
|
|
||||||
return v.UnmarshalTOML(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special case. Handle time.Time values specifically.
|
|
||||||
// TODO: Remove this code when we decide to drop support for Go 1.1.
|
|
||||||
// This isn't necessary in Go 1.2 because time.Time satisfies the encoding
|
|
||||||
// interfaces.
|
|
||||||
if rv.Type().AssignableTo(rvalue(time.Time{}).Type()) {
|
|
||||||
return md.unifyDatetime(data, rv)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special case. Look for a value satisfying the TextUnmarshaler interface.
|
|
||||||
if v, ok := rv.Interface().(TextUnmarshaler); ok {
|
|
||||||
return md.unifyText(data, v)
|
|
||||||
}
|
|
||||||
// BUG(burntsushi)
|
|
||||||
// The behavior here is incorrect whenever a Go type satisfies the
|
|
||||||
// encoding.TextUnmarshaler interface but also corresponds to a TOML
|
|
||||||
// hash or array. In particular, the unmarshaler should only be applied
|
|
||||||
// to primitive TOML values. But at this point, it will be applied to
|
|
||||||
// all kinds of values and produce an incorrect error whenever those values
|
|
||||||
// are hashes or arrays (including arrays of tables).
|
|
||||||
|
|
||||||
k := rv.Kind()
|
|
||||||
|
|
||||||
// laziness
|
|
||||||
if k >= reflect.Int && k <= reflect.Uint64 {
|
|
||||||
return md.unifyInt(data, rv)
|
|
||||||
}
|
|
||||||
switch k {
|
|
||||||
case reflect.Ptr:
|
|
||||||
elem := reflect.New(rv.Type().Elem())
|
|
||||||
err := md.unify(data, reflect.Indirect(elem))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
rv.Set(elem)
|
|
||||||
return nil
|
|
||||||
case reflect.Struct:
|
|
||||||
return md.unifyStruct(data, rv)
|
|
||||||
case reflect.Map:
|
|
||||||
return md.unifyMap(data, rv)
|
|
||||||
case reflect.Array:
|
|
||||||
return md.unifyArray(data, rv)
|
|
||||||
case reflect.Slice:
|
|
||||||
return md.unifySlice(data, rv)
|
|
||||||
case reflect.String:
|
|
||||||
return md.unifyString(data, rv)
|
|
||||||
case reflect.Bool:
|
|
||||||
return md.unifyBool(data, rv)
|
|
||||||
case reflect.Interface:
|
|
||||||
// we only support empty interfaces.
|
|
||||||
if rv.NumMethod() > 0 {
|
|
||||||
return e("unsupported type %s", rv.Type())
|
|
||||||
}
|
|
||||||
return md.unifyAnything(data, rv)
|
|
||||||
case reflect.Float32:
|
|
||||||
fallthrough
|
|
||||||
case reflect.Float64:
|
|
||||||
return md.unifyFloat64(data, rv)
|
|
||||||
}
|
|
||||||
return e("unsupported type %s", rv.Kind())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyStruct(mapping interface{}, rv reflect.Value) error {
|
|
||||||
tmap, ok := mapping.(map[string]interface{})
|
|
||||||
if !ok {
|
|
||||||
if mapping == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return e("type mismatch for %s: expected table but found %T",
|
|
||||||
rv.Type().String(), mapping)
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, datum := range tmap {
|
|
||||||
var f *field
|
|
||||||
fields := cachedTypeFields(rv.Type())
|
|
||||||
for i := range fields {
|
|
||||||
ff := &fields[i]
|
|
||||||
if ff.name == key {
|
|
||||||
f = ff
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if f == nil && strings.EqualFold(ff.name, key) {
|
|
||||||
f = ff
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if f != nil {
|
|
||||||
subv := rv
|
|
||||||
for _, i := range f.index {
|
|
||||||
subv = indirect(subv.Field(i))
|
|
||||||
}
|
|
||||||
if isUnifiable(subv) {
|
|
||||||
md.decoded[md.context.add(key).String()] = true
|
|
||||||
md.context = append(md.context, key)
|
|
||||||
if err := md.unify(datum, subv); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
md.context = md.context[0 : len(md.context)-1]
|
|
||||||
} else if f.name != "" {
|
|
||||||
// Bad user! No soup for you!
|
|
||||||
return e("cannot write unexported field %s.%s",
|
|
||||||
rv.Type().String(), f.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyMap(mapping interface{}, rv reflect.Value) error {
|
|
||||||
tmap, ok := mapping.(map[string]interface{})
|
|
||||||
if !ok {
|
|
||||||
if tmap == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return badtype("map", mapping)
|
|
||||||
}
|
|
||||||
if rv.IsNil() {
|
|
||||||
rv.Set(reflect.MakeMap(rv.Type()))
|
|
||||||
}
|
|
||||||
for k, v := range tmap {
|
|
||||||
md.decoded[md.context.add(k).String()] = true
|
|
||||||
md.context = append(md.context, k)
|
|
||||||
|
|
||||||
rvkey := indirect(reflect.New(rv.Type().Key()))
|
|
||||||
rvval := reflect.Indirect(reflect.New(rv.Type().Elem()))
|
|
||||||
if err := md.unify(v, rvval); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
md.context = md.context[0 : len(md.context)-1]
|
|
||||||
|
|
||||||
rvkey.SetString(k)
|
|
||||||
rv.SetMapIndex(rvkey, rvval)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyArray(data interface{}, rv reflect.Value) error {
|
|
||||||
datav := reflect.ValueOf(data)
|
|
||||||
if datav.Kind() != reflect.Slice {
|
|
||||||
if !datav.IsValid() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return badtype("slice", data)
|
|
||||||
}
|
|
||||||
sliceLen := datav.Len()
|
|
||||||
if sliceLen != rv.Len() {
|
|
||||||
return e("expected array length %d; got TOML array of length %d",
|
|
||||||
rv.Len(), sliceLen)
|
|
||||||
}
|
|
||||||
return md.unifySliceArray(datav, rv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifySlice(data interface{}, rv reflect.Value) error {
|
|
||||||
datav := reflect.ValueOf(data)
|
|
||||||
if datav.Kind() != reflect.Slice {
|
|
||||||
if !datav.IsValid() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return badtype("slice", data)
|
|
||||||
}
|
|
||||||
n := datav.Len()
|
|
||||||
if rv.IsNil() || rv.Cap() < n {
|
|
||||||
rv.Set(reflect.MakeSlice(rv.Type(), n, n))
|
|
||||||
}
|
|
||||||
rv.SetLen(n)
|
|
||||||
return md.unifySliceArray(datav, rv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifySliceArray(data, rv reflect.Value) error {
|
|
||||||
sliceLen := data.Len()
|
|
||||||
for i := 0; i < sliceLen; i++ {
|
|
||||||
v := data.Index(i).Interface()
|
|
||||||
sliceval := indirect(rv.Index(i))
|
|
||||||
if err := md.unify(v, sliceval); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyDatetime(data interface{}, rv reflect.Value) error {
|
|
||||||
if _, ok := data.(time.Time); ok {
|
|
||||||
rv.Set(reflect.ValueOf(data))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return badtype("time.Time", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyString(data interface{}, rv reflect.Value) error {
|
|
||||||
if s, ok := data.(string); ok {
|
|
||||||
rv.SetString(s)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return badtype("string", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyFloat64(data interface{}, rv reflect.Value) error {
|
|
||||||
if num, ok := data.(float64); ok {
|
|
||||||
switch rv.Kind() {
|
|
||||||
case reflect.Float32:
|
|
||||||
fallthrough
|
|
||||||
case reflect.Float64:
|
|
||||||
rv.SetFloat(num)
|
|
||||||
default:
|
|
||||||
panic("bug")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return badtype("float", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyInt(data interface{}, rv reflect.Value) error {
|
|
||||||
if num, ok := data.(int64); ok {
|
|
||||||
if rv.Kind() >= reflect.Int && rv.Kind() <= reflect.Int64 {
|
|
||||||
switch rv.Kind() {
|
|
||||||
case reflect.Int, reflect.Int64:
|
|
||||||
// No bounds checking necessary.
|
|
||||||
case reflect.Int8:
|
|
||||||
if num < math.MinInt8 || num > math.MaxInt8 {
|
|
||||||
return e("value %d is out of range for int8", num)
|
|
||||||
}
|
|
||||||
case reflect.Int16:
|
|
||||||
if num < math.MinInt16 || num > math.MaxInt16 {
|
|
||||||
return e("value %d is out of range for int16", num)
|
|
||||||
}
|
|
||||||
case reflect.Int32:
|
|
||||||
if num < math.MinInt32 || num > math.MaxInt32 {
|
|
||||||
return e("value %d is out of range for int32", num)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rv.SetInt(num)
|
|
||||||
} else if rv.Kind() >= reflect.Uint && rv.Kind() <= reflect.Uint64 {
|
|
||||||
unum := uint64(num)
|
|
||||||
switch rv.Kind() {
|
|
||||||
case reflect.Uint, reflect.Uint64:
|
|
||||||
// No bounds checking necessary.
|
|
||||||
case reflect.Uint8:
|
|
||||||
if num < 0 || unum > math.MaxUint8 {
|
|
||||||
return e("value %d is out of range for uint8", num)
|
|
||||||
}
|
|
||||||
case reflect.Uint16:
|
|
||||||
if num < 0 || unum > math.MaxUint16 {
|
|
||||||
return e("value %d is out of range for uint16", num)
|
|
||||||
}
|
|
||||||
case reflect.Uint32:
|
|
||||||
if num < 0 || unum > math.MaxUint32 {
|
|
||||||
return e("value %d is out of range for uint32", num)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rv.SetUint(unum)
|
|
||||||
} else {
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return badtype("integer", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyBool(data interface{}, rv reflect.Value) error {
|
|
||||||
if b, ok := data.(bool); ok {
|
|
||||||
rv.SetBool(b)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return badtype("boolean", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyAnything(data interface{}, rv reflect.Value) error {
|
|
||||||
rv.Set(reflect.ValueOf(data))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (md *MetaData) unifyText(data interface{}, v TextUnmarshaler) error {
|
|
||||||
var s string
|
|
||||||
switch sdata := data.(type) {
|
|
||||||
case TextMarshaler:
|
|
||||||
text, err := sdata.MarshalText()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
s = string(text)
|
|
||||||
case fmt.Stringer:
|
|
||||||
s = sdata.String()
|
|
||||||
case string:
|
|
||||||
s = sdata
|
|
||||||
case bool:
|
|
||||||
s = fmt.Sprintf("%v", sdata)
|
|
||||||
case int64:
|
|
||||||
s = fmt.Sprintf("%d", sdata)
|
|
||||||
case float64:
|
|
||||||
s = fmt.Sprintf("%f", sdata)
|
|
||||||
default:
|
|
||||||
return badtype("primitive (string-like)", data)
|
|
||||||
}
|
|
||||||
if err := v.UnmarshalText([]byte(s)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// rvalue returns a reflect.Value of `v`. All pointers are resolved.
|
|
||||||
func rvalue(v interface{}) reflect.Value {
|
|
||||||
return indirect(reflect.ValueOf(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
// indirect returns the value pointed to by a pointer.
|
|
||||||
// Pointers are followed until the value is not a pointer.
|
|
||||||
// New values are allocated for each nil pointer.
|
|
||||||
//
|
|
||||||
// An exception to this rule is if the value satisfies an interface of
|
|
||||||
// interest to us (like encoding.TextUnmarshaler).
|
|
||||||
func indirect(v reflect.Value) reflect.Value {
|
|
||||||
if v.Kind() != reflect.Ptr {
|
|
||||||
if v.CanSet() {
|
|
||||||
pv := v.Addr()
|
|
||||||
if _, ok := pv.Interface().(TextUnmarshaler); ok {
|
|
||||||
return pv
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
if v.IsNil() {
|
|
||||||
v.Set(reflect.New(v.Type().Elem()))
|
|
||||||
}
|
|
||||||
return indirect(reflect.Indirect(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
func isUnifiable(rv reflect.Value) bool {
|
|
||||||
if rv.CanSet() {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if _, ok := rv.Interface().(TextUnmarshaler); ok {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func badtype(expected string, data interface{}) error {
|
|
||||||
return e("cannot load TOML value of type %T into a Go %s", data, expected)
|
|
||||||
}
|
|
121
vendor/github.com/BurntSushi/toml/decode_meta.go
generated
vendored
121
vendor/github.com/BurntSushi/toml/decode_meta.go
generated
vendored
@ -1,121 +0,0 @@
|
|||||||
package toml
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
// MetaData allows access to meta information about TOML data that may not
|
|
||||||
// be inferrable via reflection. In particular, whether a key has been defined
|
|
||||||
// and the TOML type of a key.
|
|
||||||
type MetaData struct {
|
|
||||||
mapping map[string]interface{}
|
|
||||||
types map[string]tomlType
|
|
||||||
keys []Key
|
|
||||||
decoded map[string]bool
|
|
||||||
context Key // Used only during decoding.
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsDefined returns true if the key given exists in the TOML data. The key
|
|
||||||
// should be specified hierarchially. e.g.,
|
|
||||||
//
|
|
||||||
// // access the TOML key 'a.b.c'
|
|
||||||
// IsDefined("a", "b", "c")
|
|
||||||
//
|
|
||||||
// IsDefined will return false if an empty key given. Keys are case sensitive.
|
|
||||||
func (md *MetaData) IsDefined(key ...string) bool {
|
|
||||||
if len(key) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var hash map[string]interface{}
|
|
||||||
var ok bool
|
|
||||||
var hashOrVal interface{} = md.mapping
|
|
||||||
for _, k := range key {
|
|
||||||
if hash, ok = hashOrVal.(map[string]interface{}); !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if hashOrVal, ok = hash[k]; !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Type returns a string representation of the type of the key specified.
|
|
||||||
//
|
|
||||||
// Type will return the empty string if given an empty key or a key that
|
|
||||||
// does not exist. Keys are case sensitive.
|
|
||||||
func (md *MetaData) Type(key ...string) string {
|
|
||||||
fullkey := strings.Join(key, ".")
|
|
||||||
if typ, ok := md.types[fullkey]; ok {
|
|
||||||
return typ.typeString()
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Key is the type of any TOML key, including key groups. Use (MetaData).Keys
|
|
||||||
// to get values of this type.
|
|
||||||
type Key []string
|
|
||||||
|
|
||||||
func (k Key) String() string {
|
|
||||||
return strings.Join(k, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (k Key) maybeQuotedAll() string {
|
|
||||||
var ss []string
|
|
||||||
for i := range k {
|
|
||||||
ss = append(ss, k.maybeQuoted(i))
|
|
||||||
}
|
|
||||||
return strings.Join(ss, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (k Key) maybeQuoted(i int) string {
|
|
||||||
quote := false
|
|
||||||
for _, c := range k[i] {
|
|
||||||
if !isBareKeyChar(c) {
|
|
||||||
quote = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if quote {
|
|
||||||
return "\"" + strings.Replace(k[i], "\"", "\\\"", -1) + "\""
|
|
||||||
}
|
|
||||||
return k[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (k Key) add(piece string) Key {
|
|
||||||
newKey := make(Key, len(k)+1)
|
|
||||||
copy(newKey, k)
|
|
||||||
newKey[len(k)] = piece
|
|
||||||
return newKey
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keys returns a slice of every key in the TOML data, including key groups.
|
|
||||||
// Each key is itself a slice, where the first element is the top of the
|
|
||||||
// hierarchy and the last is the most specific.
|
|
||||||
//
|
|
||||||
// The list will have the same order as the keys appeared in the TOML data.
|
|
||||||
//
|
|
||||||
// All keys returned are non-empty.
|
|
||||||
func (md *MetaData) Keys() []Key {
|
|
||||||
return md.keys
|
|
||||||
}
|
|
||||||
|
|
||||||
// Undecoded returns all keys that have not been decoded in the order in which
|
|
||||||
// they appear in the original TOML document.
|
|
||||||
//
|
|
||||||
// This includes keys that haven't been decoded because of a Primitive value.
|
|
||||||
// Once the Primitive value is decoded, the keys will be considered decoded.
|
|
||||||
//
|
|
||||||
// Also note that decoding into an empty interface will result in no decoding,
|
|
||||||
// and so no keys will be considered decoded.
|
|
||||||
//
|
|
||||||
// In this sense, the Undecoded keys correspond to keys in the TOML document
|
|
||||||
// that do not have a concrete type in your representation.
|
|
||||||
func (md *MetaData) Undecoded() []Key {
|
|
||||||
undecoded := make([]Key, 0, len(md.keys))
|
|
||||||
for _, key := range md.keys {
|
|
||||||
if !md.decoded[key.String()] {
|
|
||||||
undecoded = append(undecoded, key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undecoded
|
|
||||||
}
|
|
27
vendor/github.com/BurntSushi/toml/doc.go
generated
vendored
27
vendor/github.com/BurntSushi/toml/doc.go
generated
vendored
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
Package toml provides facilities for decoding and encoding TOML configuration
|
|
||||||
files via reflection. There is also support for delaying decoding with
|
|
||||||
the Primitive type, and querying the set of keys in a TOML document with the
|
|
||||||
MetaData type.
|
|
||||||
|
|
||||||
The specification implemented: https://github.com/toml-lang/toml
|
|
||||||
|
|
||||||
The sub-command github.com/BurntSushi/toml/cmd/tomlv can be used to verify
|
|
||||||
whether a file is a valid TOML document. It can also be used to print the
|
|
||||||
type of each key in a TOML document.
|
|
||||||
|
|
||||||
Testing
|
|
||||||
|
|
||||||
There are two important types of tests used for this package. The first is
|
|
||||||
contained inside '*_test.go' files and uses the standard Go unit testing
|
|
||||||
framework. These tests are primarily devoted to holistically testing the
|
|
||||||
decoder and encoder.
|
|
||||||
|
|
||||||
The second type of testing is used to verify the implementation's adherence
|
|
||||||
to the TOML specification. These tests have been factored into their own
|
|
||||||
project: https://github.com/BurntSushi/toml-test
|
|
||||||
|
|
||||||
The reason the tests are in a separate project is so that they can be used by
|
|
||||||
any implementation of TOML. Namely, it is language agnostic.
|
|
||||||
*/
|
|
||||||
package toml
|
|
568
vendor/github.com/BurntSushi/toml/encode.go
generated
vendored
568
vendor/github.com/BurntSushi/toml/encode.go
generated
vendored
@ -1,568 +0,0 @@
|
|||||||
package toml
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"reflect"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type tomlEncodeError struct{ error }
|
|
||||||
|
|
||||||
var (
|
|
||||||
errArrayMixedElementTypes = errors.New(
|
|
||||||
"toml: cannot encode array with mixed element types")
|
|
||||||
errArrayNilElement = errors.New(
|
|
||||||
"toml: cannot encode array with nil element")
|
|
||||||
errNonString = errors.New(
|
|
||||||
"toml: cannot encode a map with non-string key type")
|
|
||||||
errAnonNonStruct = errors.New(
|
|
||||||
"toml: cannot encode an anonymous field that is not a struct")
|
|
||||||
errArrayNoTable = errors.New(
|
|
||||||
"toml: TOML array element cannot contain a table")
|
|
||||||
errNoKey = errors.New(
|
|
||||||
"toml: top-level values must be Go maps or structs")
|
|
||||||
errAnything = errors.New("") // used in testing
|
|
||||||
)
|
|
||||||
|
|
||||||
var quotedReplacer = strings.NewReplacer(
|
|
||||||
"\t", "\\t",
|
|
||||||
"\n", "\\n",
|
|
||||||
"\r", "\\r",
|
|
||||||
"\"", "\\\"",
|
|
||||||
"\\", "\\\\",
|
|
||||||
)
|
|
||||||
|
|
||||||
// Encoder controls the encoding of Go values to a TOML document to some
|
|
||||||
// io.Writer.
|
|
||||||
//
|
|
||||||
// The indentation level can be controlled with the Indent field.
|
|
||||||
type Encoder struct {
|
|
||||||
// A single indentation level. By default it is two spaces.
|
|
||||||
Indent string
|
|
||||||
|
|
||||||
// hasWritten is whether we have written any output to w yet.
|
|
||||||
hasWritten bool
|
|
||||||
w *bufio.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewEncoder returns a TOML encoder that encodes Go values to the io.Writer
|
|
||||||
// given. By default, a single indentation level is 2 spaces.
|
|
||||||
func NewEncoder(w io.Writer) *Encoder {
|
|
||||||
return &Encoder{
|
|
||||||
w: bufio.NewWriter(w),
|
|
||||||
Indent: " ",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode writes a TOML representation of the Go value to the underlying
|
|
||||||
// io.Writer. If the value given cannot be encoded to a valid TOML document,
|
|
||||||
// then an error is returned.
|
|
||||||
//
|
|
||||||
// The mapping between Go values and TOML values should be precisely the same
|
|
||||||
// as for the Decode* functions. Similarly, the TextMarshaler interface is
|
|
||||||
// supported by encoding the resulting bytes as strings. (If you want to write
|
|
||||||
// arbitrary binary data then you will need to use something like base64 since
|
|
||||||
// TOML does not have any binary types.)
|
|
||||||
//
|
|
||||||
// When encoding TOML hashes (i.e., Go maps or structs), keys without any
|
|
||||||
// sub-hashes are encoded first.
|
|
||||||
//
|
|
||||||
// If a Go map is encoded, then its keys are sorted alphabetically for
|
|
||||||
// deterministic output. More control over this behavior may be provided if
|
|
||||||
// there is demand for it.
|
|
||||||
//
|
|
||||||
// Encoding Go values without a corresponding TOML representation---like map
|
|
||||||
// types with non-string keys---will cause an error to be returned. Similarly
|
|
||||||
// for mixed arrays/slices, arrays/slices with nil elements, embedded
|
|
||||||
// non-struct types and nested slices containing maps or structs.
|
|
||||||
// (e.g., [][]map[string]string is not allowed but []map[string]string is OK
|
|
||||||
// and so is []map[string][]string.)
|
|
||||||
func (enc *Encoder) Encode(v interface{}) error {
|
|
||||||
rv := eindirect(reflect.ValueOf(v))
|
|
||||||
if err := enc.safeEncode(Key([]string{}), rv); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return enc.w.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) safeEncode(key Key, rv reflect.Value) (err error) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
if terr, ok := r.(tomlEncodeError); ok {
|
|
||||||
err = terr.error
|
|
||||||
return
|
|
||||||
}
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
enc.encode(key, rv)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) encode(key Key, rv reflect.Value) {
|
|
||||||
// Special case. Time needs to be in ISO8601 format.
|
|
||||||
// Special case. If we can marshal the type to text, then we used that.
|
|
||||||
// Basically, this prevents the encoder for handling these types as
|
|
||||||
// generic structs (or whatever the underlying type of a TextMarshaler is).
|
|
||||||
switch rv.Interface().(type) {
|
|
||||||
case time.Time, TextMarshaler:
|
|
||||||
enc.keyEqElement(key, rv)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
k := rv.Kind()
|
|
||||||
switch k {
|
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32,
|
|
||||||
reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32,
|
|
||||||
reflect.Uint64,
|
|
||||||
reflect.Float32, reflect.Float64, reflect.String, reflect.Bool:
|
|
||||||
enc.keyEqElement(key, rv)
|
|
||||||
case reflect.Array, reflect.Slice:
|
|
||||||
if typeEqual(tomlArrayHash, tomlTypeOfGo(rv)) {
|
|
||||||
enc.eArrayOfTables(key, rv)
|
|
||||||
} else {
|
|
||||||
enc.keyEqElement(key, rv)
|
|
||||||
}
|
|
||||||
case reflect.Interface:
|
|
||||||
if rv.IsNil() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
enc.encode(key, rv.Elem())
|
|
||||||
case reflect.Map:
|
|
||||||
if rv.IsNil() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
enc.eTable(key, rv)
|
|
||||||
case reflect.Ptr:
|
|
||||||
if rv.IsNil() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
enc.encode(key, rv.Elem())
|
|
||||||
case reflect.Struct:
|
|
||||||
enc.eTable(key, rv)
|
|
||||||
default:
|
|
||||||
panic(e("unsupported type for key '%s': %s", key, k))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// eElement encodes any value that can be an array element (primitives and
|
|
||||||
// arrays).
|
|
||||||
func (enc *Encoder) eElement(rv reflect.Value) {
|
|
||||||
switch v := rv.Interface().(type) {
|
|
||||||
case time.Time:
|
|
||||||
// Special case time.Time as a primitive. Has to come before
|
|
||||||
// TextMarshaler below because time.Time implements
|
|
||||||
// encoding.TextMarshaler, but we need to always use UTC.
|
|
||||||
enc.wf(v.UTC().Format("2006-01-02T15:04:05Z"))
|
|
||||||
return
|
|
||||||
case TextMarshaler:
|
|
||||||
// Special case. Use text marshaler if it's available for this value.
|
|
||||||
if s, err := v.MarshalText(); err != nil {
|
|
||||||
encPanic(err)
|
|
||||||
} else {
|
|
||||||
enc.writeQuoted(string(s))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
switch rv.Kind() {
|
|
||||||
case reflect.Bool:
|
|
||||||
enc.wf(strconv.FormatBool(rv.Bool()))
|
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32,
|
|
||||||
reflect.Int64:
|
|
||||||
enc.wf(strconv.FormatInt(rv.Int(), 10))
|
|
||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16,
|
|
||||||
reflect.Uint32, reflect.Uint64:
|
|
||||||
enc.wf(strconv.FormatUint(rv.Uint(), 10))
|
|
||||||
case reflect.Float32:
|
|
||||||
enc.wf(floatAddDecimal(strconv.FormatFloat(rv.Float(), 'f', -1, 32)))
|
|
||||||
case reflect.Float64:
|
|
||||||
enc.wf(floatAddDecimal(strconv.FormatFloat(rv.Float(), 'f', -1, 64)))
|
|
||||||
case reflect.Array, reflect.Slice:
|
|
||||||
enc.eArrayOrSliceElement(rv)
|
|
||||||
case reflect.Interface:
|
|
||||||
enc.eElement(rv.Elem())
|
|
||||||
case reflect.String:
|
|
||||||
enc.writeQuoted(rv.String())
|
|
||||||
default:
|
|
||||||
panic(e("unexpected primitive type: %s", rv.Kind()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// By the TOML spec, all floats must have a decimal with at least one
|
|
||||||
// number on either side.
|
|
||||||
func floatAddDecimal(fstr string) string {
|
|
||||||
if !strings.Contains(fstr, ".") {
|
|
||||||
return fstr + ".0"
|
|
||||||
}
|
|
||||||
return fstr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) writeQuoted(s string) {
|
|
||||||
enc.wf("\"%s\"", quotedReplacer.Replace(s))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) eArrayOrSliceElement(rv reflect.Value) {
|
|
||||||
length := rv.Len()
|
|
||||||
enc.wf("[")
|
|
||||||
for i := 0; i < length; i++ {
|
|
||||||
elem := rv.Index(i)
|
|
||||||
enc.eElement(elem)
|
|
||||||
if i != length-1 {
|
|
||||||
enc.wf(", ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
enc.wf("]")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) eArrayOfTables(key Key, rv reflect.Value) {
|
|
||||||
if len(key) == 0 {
|
|
||||||
encPanic(errNoKey)
|
|
||||||
}
|
|
||||||
for i := 0; i < rv.Len(); i++ {
|
|
||||||
trv := rv.Index(i)
|
|
||||||
if isNil(trv) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
panicIfInvalidKey(key)
|
|
||||||
enc.newline()
|
|
||||||
enc.wf("%s[[%s]]", enc.indentStr(key), key.maybeQuotedAll())
|
|
||||||
enc.newline()
|
|
||||||
enc.eMapOrStruct(key, trv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) eTable(key Key, rv reflect.Value) {
|
|
||||||
panicIfInvalidKey(key)
|
|
||||||
if len(key) == 1 {
|
|
||||||
// Output an extra newline between top-level tables.
|
|
||||||
// (The newline isn't written if nothing else has been written though.)
|
|
||||||
enc.newline()
|
|
||||||
}
|
|
||||||
if len(key) > 0 {
|
|
||||||
enc.wf("%s[%s]", enc.indentStr(key), key.maybeQuotedAll())
|
|
||||||
enc.newline()
|
|
||||||
}
|
|
||||||
enc.eMapOrStruct(key, rv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) eMapOrStruct(key Key, rv reflect.Value) {
|
|
||||||
switch rv := eindirect(rv); rv.Kind() {
|
|
||||||
case reflect.Map:
|
|
||||||
enc.eMap(key, rv)
|
|
||||||
case reflect.Struct:
|
|
||||||
enc.eStruct(key, rv)
|
|
||||||
default:
|
|
||||||
panic("eTable: unhandled reflect.Value Kind: " + rv.Kind().String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) eMap(key Key, rv reflect.Value) {
|
|
||||||
rt := rv.Type()
|
|
||||||
if rt.Key().Kind() != reflect.String {
|
|
||||||
encPanic(errNonString)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort keys so that we have deterministic output. And write keys directly
|
|
||||||
// underneath this key first, before writing sub-structs or sub-maps.
|
|
||||||
var mapKeysDirect, mapKeysSub []string
|
|
||||||
for _, mapKey := range rv.MapKeys() {
|
|
||||||
k := mapKey.String()
|
|
||||||
if typeIsHash(tomlTypeOfGo(rv.MapIndex(mapKey))) {
|
|
||||||
mapKeysSub = append(mapKeysSub, k)
|
|
||||||
} else {
|
|
||||||
mapKeysDirect = append(mapKeysDirect, k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var writeMapKeys = func(mapKeys []string) {
|
|
||||||
sort.Strings(mapKeys)
|
|
||||||
for _, mapKey := range mapKeys {
|
|
||||||
mrv := rv.MapIndex(reflect.ValueOf(mapKey))
|
|
||||||
if isNil(mrv) {
|
|
||||||
// Don't write anything for nil fields.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
enc.encode(key.add(mapKey), mrv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
writeMapKeys(mapKeysDirect)
|
|
||||||
writeMapKeys(mapKeysSub)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) eStruct(key Key, rv reflect.Value) {
|
|
||||||
// Write keys for fields directly under this key first, because if we write
|
|
||||||
// a field that creates a new table, then all keys under it will be in that
|
|
||||||
// table (not the one we're writing here).
|
|
||||||
rt := rv.Type()
|
|
||||||
var fieldsDirect, fieldsSub [][]int
|
|
||||||
var addFields func(rt reflect.Type, rv reflect.Value, start []int)
|
|
||||||
addFields = func(rt reflect.Type, rv reflect.Value, start []int) {
|
|
||||||
for i := 0; i < rt.NumField(); i++ {
|
|
||||||
f := rt.Field(i)
|
|
||||||
// skip unexported fields
|
|
||||||
if f.PkgPath != "" && !f.Anonymous {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
frv := rv.Field(i)
|
|
||||||
if f.Anonymous {
|
|
||||||
t := f.Type
|
|
||||||
switch t.Kind() {
|
|
||||||
case reflect.Struct:
|
|
||||||
// Treat anonymous struct fields with
|
|
||||||
// tag names as though they are not
|
|
||||||
// anonymous, like encoding/json does.
|
|
||||||
if getOptions(f.Tag).name == "" {
|
|
||||||
addFields(t, frv, f.Index)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
case reflect.Ptr:
|
|
||||||
if t.Elem().Kind() == reflect.Struct &&
|
|
||||||
getOptions(f.Tag).name == "" {
|
|
||||||
if !frv.IsNil() {
|
|
||||||
addFields(t.Elem(), frv.Elem(), f.Index)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Fall through to the normal field encoding logic below
|
|
||||||
// for non-struct anonymous fields.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if typeIsHash(tomlTypeOfGo(frv)) {
|
|
||||||
fieldsSub = append(fieldsSub, append(start, f.Index...))
|
|
||||||
} else {
|
|
||||||
fieldsDirect = append(fieldsDirect, append(start, f.Index...))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addFields(rt, rv, nil)
|
|
||||||
|
|
||||||
var writeFields = func(fields [][]int) {
|
|
||||||
for _, fieldIndex := range fields {
|
|
||||||
sft := rt.FieldByIndex(fieldIndex)
|
|
||||||
sf := rv.FieldByIndex(fieldIndex)
|
|
||||||
if isNil(sf) {
|
|
||||||
// Don't write anything for nil fields.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := getOptions(sft.Tag)
|
|
||||||
if opts.skip {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
keyName := sft.Name
|
|
||||||
if opts.name != "" {
|
|
||||||
keyName = opts.name
|
|
||||||
}
|
|
||||||
if opts.omitempty && isEmpty(sf) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if opts.omitzero && isZero(sf) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
enc.encode(key.add(keyName), sf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
writeFields(fieldsDirect)
|
|
||||||
writeFields(fieldsSub)
|
|
||||||
}
|
|
||||||
|
|
||||||
// tomlTypeName returns the TOML type name of the Go value's type. It is
|
|
||||||
// used to determine whether the types of array elements are mixed (which is
|
|
||||||
// forbidden). If the Go value is nil, then it is illegal for it to be an array
|
|
||||||
// element, and valueIsNil is returned as true.
|
|
||||||
|
|
||||||
// Returns the TOML type of a Go value. The type may be `nil`, which means
|
|
||||||
// no concrete TOML type could be found.
|
|
||||||
func tomlTypeOfGo(rv reflect.Value) tomlType {
|
|
||||||
if isNil(rv) || !rv.IsValid() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
switch rv.Kind() {
|
|
||||||
case reflect.Bool:
|
|
||||||
return tomlBool
|
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32,
|
|
||||||
reflect.Int64,
|
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32,
|
|
||||||
reflect.Uint64:
|
|
||||||
return tomlInteger
|
|
||||||
case reflect.Float32, reflect.Float64:
|
|
||||||
return tomlFloat
|
|
||||||
case reflect.Array, reflect.Slice:
|
|
||||||
if typeEqual(tomlHash, tomlArrayType(rv)) {
|
|
||||||
return tomlArrayHash
|
|
||||||
}
|
|
||||||
return tomlArray
|
|
||||||
case reflect.Ptr, reflect.Interface:
|
|
||||||
return tomlTypeOfGo(rv.Elem())
|
|
||||||
case reflect.String:
|
|
||||||
return tomlString
|
|
||||||
case reflect.Map:
|
|
||||||
return tomlHash
|
|
||||||
case reflect.Struct:
|
|
||||||
switch rv.Interface().(type) {
|
|
||||||
case time.Time:
|
|
||||||
return tomlDatetime
|
|
||||||
case TextMarshaler:
|
|
||||||
return tomlString
|
|
||||||
default:
|
|
||||||
return tomlHash
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
panic("unexpected reflect.Kind: " + rv.Kind().String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// tomlArrayType returns the element type of a TOML array. The type returned
|
|
||||||
// may be nil if it cannot be determined (e.g., a nil slice or a zero length
|
|
||||||
// slize). This function may also panic if it finds a type that cannot be
|
|
||||||
// expressed in TOML (such as nil elements, heterogeneous arrays or directly
|
|
||||||
// nested arrays of tables).
|
|
||||||
func tomlArrayType(rv reflect.Value) tomlType {
|
|
||||||
if isNil(rv) || !rv.IsValid() || rv.Len() == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
firstType := tomlTypeOfGo(rv.Index(0))
|
|
||||||
if firstType == nil {
|
|
||||||
encPanic(errArrayNilElement)
|
|
||||||
}
|
|
||||||
|
|
||||||
rvlen := rv.Len()
|
|
||||||
for i := 1; i < rvlen; i++ {
|
|
||||||
elem := rv.Index(i)
|
|
||||||
switch elemType := tomlTypeOfGo(elem); {
|
|
||||||
case elemType == nil:
|
|
||||||
encPanic(errArrayNilElement)
|
|
||||||
case !typeEqual(firstType, elemType):
|
|
||||||
encPanic(errArrayMixedElementTypes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If we have a nested array, then we must make sure that the nested
|
|
||||||
// array contains ONLY primitives.
|
|
||||||
// This checks arbitrarily nested arrays.
|
|
||||||
if typeEqual(firstType, tomlArray) || typeEqual(firstType, tomlArrayHash) {
|
|
||||||
nest := tomlArrayType(eindirect(rv.Index(0)))
|
|
||||||
if typeEqual(nest, tomlHash) || typeEqual(nest, tomlArrayHash) {
|
|
||||||
encPanic(errArrayNoTable)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return firstType
|
|
||||||
}
|
|
||||||
|
|
||||||
type tagOptions struct {
|
|
||||||
skip bool // "-"
|
|
||||||
name string
|
|
||||||
omitempty bool
|
|
||||||
omitzero bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func getOptions(tag reflect.StructTag) tagOptions {
|
|
||||||
t := tag.Get("toml")
|
|
||||||
if t == "-" {
|
|
||||||
return tagOptions{skip: true}
|
|
||||||
}
|
|
||||||
var opts tagOptions
|
|
||||||
parts := strings.Split(t, ",")
|
|
||||||
opts.name = parts[0]
|
|
||||||
for _, s := range parts[1:] {
|
|
||||||
switch s {
|
|
||||||
case "omitempty":
|
|
||||||
opts.omitempty = true
|
|
||||||
case "omitzero":
|
|
||||||
opts.omitzero = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return opts
|
|
||||||
}
|
|
||||||
|
|
||||||
func isZero(rv reflect.Value) bool {
|
|
||||||
switch rv.Kind() {
|
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
||||||
return rv.Int() == 0
|
|
||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
|
||||||
return rv.Uint() == 0
|
|
||||||
case reflect.Float32, reflect.Float64:
|
|
||||||
return rv.Float() == 0.0
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func isEmpty(rv reflect.Value) bool {
|
|
||||||
switch rv.Kind() {
|
|
||||||
case reflect.Array, reflect.Slice, reflect.Map, reflect.String:
|
|
||||||
return rv.Len() == 0
|
|
||||||
case reflect.Bool:
|
|
||||||
return !rv.Bool()
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) newline() {
|
|
||||||
if enc.hasWritten {
|
|
||||||
enc.wf("\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) keyEqElement(key Key, val reflect.Value) {
|
|
||||||
if len(key) == 0 {
|
|
||||||
encPanic(errNoKey)
|
|
||||||
}
|
|
||||||
panicIfInvalidKey(key)
|
|
||||||
enc.wf("%s%s = ", enc.indentStr(key), key.maybeQuoted(len(key)-1))
|
|
||||||
enc.eElement(val)
|
|
||||||
enc.newline()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) wf(format string, v ...interface{}) {
|
|
||||||
if _, err := fmt.Fprintf(enc.w, format, v...); err != nil {
|
|
||||||
encPanic(err)
|
|
||||||
}
|
|
||||||
enc.hasWritten = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (enc *Encoder) indentStr(key Key) string {
|
|
||||||
return strings.Repeat(enc.Indent, len(key)-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func encPanic(err error) {
|
|
||||||
panic(tomlEncodeError{err})
|
|
||||||
}
|
|
||||||
|
|
||||||
func eindirect(v reflect.Value) reflect.Value {
|
|
||||||
switch v.Kind() {
|
|
||||||
case reflect.Ptr, reflect.Interface:
|
|
||||||
return eindirect(v.Elem())
|
|
||||||
default:
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func isNil(rv reflect.Value) bool {
|
|
||||||
switch rv.Kind() {
|
|
||||||
case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
|
|
||||||
return rv.IsNil()
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func panicIfInvalidKey(key Key) {
|
|
||||||
for _, k := range key {
|
|
||||||
if len(k) == 0 {
|
|
||||||
encPanic(e("Key '%s' is not a valid table name. Key names "+
|
|
||||||
"cannot be empty.", key.maybeQuotedAll()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func isValidKeyName(s string) bool {
|
|
||||||
return len(s) != 0
|
|
||||||
}
|
|
19
vendor/github.com/BurntSushi/toml/encoding_types.go
generated
vendored
19
vendor/github.com/BurntSushi/toml/encoding_types.go
generated
vendored
@ -1,19 +0,0 @@
|
|||||||
// +build go1.2
|
|
||||||
|
|
||||||
package toml
|
|
||||||
|
|
||||||
// In order to support Go 1.1, we define our own TextMarshaler and
|
|
||||||
// TextUnmarshaler types. For Go 1.2+, we just alias them with the
|
|
||||||
// standard library interfaces.
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here
|
|
||||||
// so that Go 1.1 can be supported.
|
|
||||||
type TextMarshaler encoding.TextMarshaler
|
|
||||||
|
|
||||||
// TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined
|
|
||||||
// here so that Go 1.1 can be supported.
|
|
||||||
type TextUnmarshaler encoding.TextUnmarshaler
|
|
18
vendor/github.com/BurntSushi/toml/encoding_types_1.1.go
generated
vendored
18
vendor/github.com/BurntSushi/toml/encoding_types_1.1.go
generated
vendored
@ -1,18 +0,0 @@
|
|||||||
// +build !go1.2
|
|
||||||
|
|
||||||
package toml
|
|
||||||
|
|
||||||
// These interfaces were introduced in Go 1.2, so we add them manually when
|
|
||||||
// compiling for Go 1.1.
|
|
||||||
|
|
||||||
// TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here
|
|
||||||
// so that Go 1.1 can be supported.
|
|
||||||
type TextMarshaler interface {
|
|
||||||
MarshalText() (text []byte, err error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined
|
|
||||||
// here so that Go 1.1 can be supported.
|
|
||||||
type TextUnmarshaler interface {
|
|
||||||
UnmarshalText(text []byte) error
|
|
||||||
}
|
|
953
vendor/github.com/BurntSushi/toml/lex.go
generated
vendored
953
vendor/github.com/BurntSushi/toml/lex.go
generated
vendored
@ -1,953 +0,0 @@
|
|||||||
package toml
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"unicode"
|
|
||||||
"unicode/utf8"
|
|
||||||
)
|
|
||||||
|
|
||||||
type itemType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
itemError itemType = iota
|
|
||||||
itemNIL // used in the parser to indicate no type
|
|
||||||
itemEOF
|
|
||||||
itemText
|
|
||||||
itemString
|
|
||||||
itemRawString
|
|
||||||
itemMultilineString
|
|
||||||
itemRawMultilineString
|
|
||||||
itemBool
|
|
||||||
itemInteger
|
|
||||||
itemFloat
|
|
||||||
itemDatetime
|
|
||||||
itemArray // the start of an array
|
|
||||||
itemArrayEnd
|
|
||||||
itemTableStart
|
|
||||||
itemTableEnd
|
|
||||||
itemArrayTableStart
|
|
||||||
itemArrayTableEnd
|
|
||||||
itemKeyStart
|
|
||||||
itemCommentStart
|
|
||||||
itemInlineTableStart
|
|
||||||
itemInlineTableEnd
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
eof = 0
|
|
||||||
comma = ','
|
|
||||||
tableStart = '['
|
|
||||||
tableEnd = ']'
|
|
||||||
arrayTableStart = '['
|
|
||||||
arrayTableEnd = ']'
|
|
||||||
tableSep = '.'
|
|
||||||
keySep = '='
|
|
||||||
arrayStart = '['
|
|
||||||
arrayEnd = ']'
|
|
||||||
commentStart = '#'
|
|
||||||
stringStart = '"'
|
|
||||||
stringEnd = '"'
|
|
||||||
rawStringStart = '\''
|
|
||||||
rawStringEnd = '\''
|
|
||||||
inlineTableStart = '{'
|
|
||||||
inlineTableEnd = '}'
|
|
||||||
)
|
|
||||||
|
|
||||||
type stateFn func(lx *lexer) stateFn
|
|
||||||
|
|
||||||
type lexer struct {
|
|
||||||
input string
|
|
||||||
start int
|
|
||||||
pos int
|
|
||||||
line int
|
|
||||||
state stateFn
|
|
||||||
items chan item
|
|
||||||
|
|
||||||
// Allow for backing up up to three runes.
|
|
||||||
// This is necessary because TOML contains 3-rune tokens (""" and ''').
|
|
||||||
prevWidths [3]int
|
|
||||||
nprev int // how many of prevWidths are in use
|
|
||||||
// If we emit an eof, we can still back up, but it is not OK to call
|
|
||||||
// next again.
|
|
||||||
atEOF bool
|
|
||||||
|
|
||||||
// A stack of state functions used to maintain context.
|
|
||||||
// The idea is to reuse parts of the state machine in various places.
|
|
||||||
// For example, values can appear at the top level or within arbitrarily
|
|
||||||
// nested arrays. The last state on the stack is used after a value has
|
|
||||||
// been lexed. Similarly for comments.
|
|
||||||
stack []stateFn
|
|
||||||
}
|
|
||||||
|
|
||||||
type item struct {
|
|
||||||
typ itemType
|
|
||||||
val string
|
|
||||||
line int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lx *lexer) nextItem() item {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case item := <-lx.items:
|
|
||||||
return item
|
|
||||||
default:
|
|
||||||
lx.state = lx.state(lx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func lex(input string) *lexer {
|
|
||||||
lx := &lexer{
|
|
||||||
input: input,
|
|
||||||
state: lexTop,
|
|
||||||
line: 1,
|
|
||||||
items: make(chan item, 10),
|
|
||||||
stack: make([]stateFn, 0, 10),
|
|
||||||
}
|
|
||||||
return lx
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lx *lexer) push(state stateFn) {
|
|
||||||
lx.stack = append(lx.stack, state)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lx *lexer) pop() stateFn {
|
|
||||||
if len(lx.stack) == 0 {
|
|
||||||
return lx.errorf("BUG in lexer: no states to pop")
|
|
||||||
}
|
|
||||||
last := lx.stack[len(lx.stack)-1]
|
|
||||||
lx.stack = lx.stack[0 : len(lx.stack)-1]
|
|
||||||
return last
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lx *lexer) current() string {
|
|
||||||
return lx.input[lx.start:lx.pos]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lx *lexer) emit(typ itemType) {
|
|
||||||
lx.items <- item{typ, lx.current(), lx.line}
|
|
||||||
lx.start = lx.pos
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lx *lexer) emitTrim(typ itemType) {
|
|
||||||
lx.items <- item{typ, strings.TrimSpace(lx.current()), lx.line}
|
|
||||||
lx.start = lx.pos
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lx *lexer) next() (r rune) {
|
|
||||||
if lx.atEOF {
|
|
||||||
panic("next called after EOF")
|
|
||||||
}
|
|
||||||
if lx.pos >= len(lx.input) {
|
|
||||||
lx.atEOF = true
|
|
||||||
return eof
|
|
||||||
}
|
|
||||||
|
|
||||||
if lx.input[lx.pos] == '\n' {
|
|
||||||
lx.line++
|
|
||||||
}
|
|
||||||
lx.prevWidths[2] = lx.prevWidths[1]
|
|
||||||
lx.prevWidths[1] = lx.prevWidths[0]
|
|
||||||
if lx.nprev < 3 {
|
|
||||||
lx.nprev++
|
|
||||||
}
|
|
||||||
r, w := utf8.DecodeRuneInString(lx.input[lx.pos:])
|
|
||||||
lx.prevWidths[0] = w
|
|
||||||
lx.pos += w
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore skips over the pending input before this point.
|
|
||||||
func (lx *lexer) ignore() {
|
|
||||||
lx.start = lx.pos
|
|
||||||
}
|
|
||||||
|
|
||||||
// backup steps back one rune. Can be called only twice between calls to next.
|
|
||||||
func (lx *lexer) backup() {
|
|
||||||
if lx.atEOF {
|
|
||||||
lx.atEOF = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if lx.nprev < 1 {
|
|
||||||
panic("backed up too far")
|
|
||||||
}
|
|
||||||
w := lx.prevWidths[0]
|
|
||||||
lx.prevWidths[0] = lx.prevWidths[1]
|
|
||||||
lx.prevWidths[1] = lx.prevWidths[2]
|
|
||||||
lx.nprev--
|
|
||||||
lx.pos -= w
|
|
||||||
if lx.pos < len(lx.input) && lx.input[lx.pos] == '\n' {
|
|
||||||
lx.line--
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// accept consumes the next rune if it's equal to `valid`.
|
|
||||||
func (lx *lexer) accept(valid rune) bool {
|
|
||||||
if lx.next() == valid {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
lx.backup()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// peek returns but does not consume the next rune in the input.
|
|
||||||
func (lx *lexer) peek() rune {
|
|
||||||
r := lx.next()
|
|
||||||
lx.backup()
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip ignores all input that matches the given predicate.
|
|
||||||
func (lx *lexer) skip(pred func(rune) bool) {
|
|
||||||
for {
|
|
||||||
r := lx.next()
|
|
||||||
if pred(r) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
lx.backup()
|
|
||||||
lx.ignore()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// errorf stops all lexing by emitting an error and returning `nil`.
|
|
||||||
// Note that any value that is a character is escaped if it's a special
|
|
||||||
// character (newlines, tabs, etc.).
|
|
||||||
func (lx *lexer) errorf(format string, values ...interface{}) stateFn {
|
|
||||||
lx.items <- item{
|
|
||||||
itemError,
|
|
||||||
fmt.Sprintf(format, values...),
|
|
||||||
lx.line,
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexTop consumes elements at the top level of TOML data.
|
|
||||||
func lexTop(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
if isWhitespace(r) || isNL(r) {
|
|
||||||
return lexSkip(lx, lexTop)
|
|
||||||
}
|
|
||||||
switch r {
|
|
||||||
case commentStart:
|
|
||||||
lx.push(lexTop)
|
|
||||||
return lexCommentStart
|
|
||||||
case tableStart:
|
|
||||||
return lexTableStart
|
|
||||||
case eof:
|
|
||||||
if lx.pos > lx.start {
|
|
||||||
return lx.errorf("unexpected EOF")
|
|
||||||
}
|
|
||||||
lx.emit(itemEOF)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// At this point, the only valid item can be a key, so we back up
|
|
||||||
// and let the key lexer do the rest.
|
|
||||||
lx.backup()
|
|
||||||
lx.push(lexTopEnd)
|
|
||||||
return lexKeyStart
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexTopEnd is entered whenever a top-level item has been consumed. (A value
|
|
||||||
// or a table.) It must see only whitespace, and will turn back to lexTop
|
|
||||||
// upon a newline. If it sees EOF, it will quit the lexer successfully.
|
|
||||||
func lexTopEnd(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
switch {
|
|
||||||
case r == commentStart:
|
|
||||||
// a comment will read to a newline for us.
|
|
||||||
lx.push(lexTop)
|
|
||||||
return lexCommentStart
|
|
||||||
case isWhitespace(r):
|
|
||||||
return lexTopEnd
|
|
||||||
case isNL(r):
|
|
||||||
lx.ignore()
|
|
||||||
return lexTop
|
|
||||||
case r == eof:
|
|
||||||
lx.emit(itemEOF)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return lx.errorf("expected a top-level item to end with a newline, "+
|
|
||||||
"comment, or EOF, but got %q instead", r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexTable lexes the beginning of a table. Namely, it makes sure that
|
|
||||||
// it starts with a character other than '.' and ']'.
|
|
||||||
// It assumes that '[' has already been consumed.
|
|
||||||
// It also handles the case that this is an item in an array of tables.
|
|
||||||
// e.g., '[[name]]'.
|
|
||||||
func lexTableStart(lx *lexer) stateFn {
|
|
||||||
if lx.peek() == arrayTableStart {
|
|
||||||
lx.next()
|
|
||||||
lx.emit(itemArrayTableStart)
|
|
||||||
lx.push(lexArrayTableEnd)
|
|
||||||
} else {
|
|
||||||
lx.emit(itemTableStart)
|
|
||||||
lx.push(lexTableEnd)
|
|
||||||
}
|
|
||||||
return lexTableNameStart
|
|
||||||
}
|
|
||||||
|
|
||||||
func lexTableEnd(lx *lexer) stateFn {
|
|
||||||
lx.emit(itemTableEnd)
|
|
||||||
return lexTopEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
func lexArrayTableEnd(lx *lexer) stateFn {
|
|
||||||
if r := lx.next(); r != arrayTableEnd {
|
|
||||||
return lx.errorf("expected end of table array name delimiter %q, "+
|
|
||||||
"but got %q instead", arrayTableEnd, r)
|
|
||||||
}
|
|
||||||
lx.emit(itemArrayTableEnd)
|
|
||||||
return lexTopEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
func lexTableNameStart(lx *lexer) stateFn {
|
|
||||||
lx.skip(isWhitespace)
|
|
||||||
switch r := lx.peek(); {
|
|
||||||
case r == tableEnd || r == eof:
|
|
||||||
return lx.errorf("unexpected end of table name " +
|
|
||||||
"(table names cannot be empty)")
|
|
||||||
case r == tableSep:
|
|
||||||
return lx.errorf("unexpected table separator " +
|
|
||||||
"(table names cannot be empty)")
|
|
||||||
case r == stringStart || r == rawStringStart:
|
|
||||||
lx.ignore()
|
|
||||||
lx.push(lexTableNameEnd)
|
|
||||||
return lexValue // reuse string lexing
|
|
||||||
default:
|
|
||||||
return lexBareTableName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexBareTableName lexes the name of a table. It assumes that at least one
|
|
||||||
// valid character for the table has already been read.
|
|
||||||
func lexBareTableName(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
if isBareKeyChar(r) {
|
|
||||||
return lexBareTableName
|
|
||||||
}
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemText)
|
|
||||||
return lexTableNameEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexTableNameEnd reads the end of a piece of a table name, optionally
|
|
||||||
// consuming whitespace.
|
|
||||||
func lexTableNameEnd(lx *lexer) stateFn {
|
|
||||||
lx.skip(isWhitespace)
|
|
||||||
switch r := lx.next(); {
|
|
||||||
case isWhitespace(r):
|
|
||||||
return lexTableNameEnd
|
|
||||||
case r == tableSep:
|
|
||||||
lx.ignore()
|
|
||||||
return lexTableNameStart
|
|
||||||
case r == tableEnd:
|
|
||||||
return lx.pop()
|
|
||||||
default:
|
|
||||||
return lx.errorf("expected '.' or ']' to end table name, "+
|
|
||||||
"but got %q instead", r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexKeyStart consumes a key name up until the first non-whitespace character.
|
|
||||||
// lexKeyStart will ignore whitespace.
|
|
||||||
func lexKeyStart(lx *lexer) stateFn {
|
|
||||||
r := lx.peek()
|
|
||||||
switch {
|
|
||||||
case r == keySep:
|
|
||||||
return lx.errorf("unexpected key separator %q", keySep)
|
|
||||||
case isWhitespace(r) || isNL(r):
|
|
||||||
lx.next()
|
|
||||||
return lexSkip(lx, lexKeyStart)
|
|
||||||
case r == stringStart || r == rawStringStart:
|
|
||||||
lx.ignore()
|
|
||||||
lx.emit(itemKeyStart)
|
|
||||||
lx.push(lexKeyEnd)
|
|
||||||
return lexValue // reuse string lexing
|
|
||||||
default:
|
|
||||||
lx.ignore()
|
|
||||||
lx.emit(itemKeyStart)
|
|
||||||
return lexBareKey
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexBareKey consumes the text of a bare key. Assumes that the first character
|
|
||||||
// (which is not whitespace) has not yet been consumed.
|
|
||||||
func lexBareKey(lx *lexer) stateFn {
|
|
||||||
switch r := lx.next(); {
|
|
||||||
case isBareKeyChar(r):
|
|
||||||
return lexBareKey
|
|
||||||
case isWhitespace(r):
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemText)
|
|
||||||
return lexKeyEnd
|
|
||||||
case r == keySep:
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemText)
|
|
||||||
return lexKeyEnd
|
|
||||||
default:
|
|
||||||
return lx.errorf("bare keys cannot contain %q", r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexKeyEnd consumes the end of a key and trims whitespace (up to the key
|
|
||||||
// separator).
|
|
||||||
func lexKeyEnd(lx *lexer) stateFn {
|
|
||||||
switch r := lx.next(); {
|
|
||||||
case r == keySep:
|
|
||||||
return lexSkip(lx, lexValue)
|
|
||||||
case isWhitespace(r):
|
|
||||||
return lexSkip(lx, lexKeyEnd)
|
|
||||||
default:
|
|
||||||
return lx.errorf("expected key separator %q, but got %q instead",
|
|
||||||
keySep, r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexValue starts the consumption of a value anywhere a value is expected.
|
|
||||||
// lexValue will ignore whitespace.
|
|
||||||
// After a value is lexed, the last state on the next is popped and returned.
|
|
||||||
func lexValue(lx *lexer) stateFn {
|
|
||||||
// We allow whitespace to precede a value, but NOT newlines.
|
|
||||||
// In array syntax, the array states are responsible for ignoring newlines.
|
|
||||||
r := lx.next()
|
|
||||||
switch {
|
|
||||||
case isWhitespace(r):
|
|
||||||
return lexSkip(lx, lexValue)
|
|
||||||
case isDigit(r):
|
|
||||||
lx.backup() // avoid an extra state and use the same as above
|
|
||||||
return lexNumberOrDateStart
|
|
||||||
}
|
|
||||||
switch r {
|
|
||||||
case arrayStart:
|
|
||||||
lx.ignore()
|
|
||||||
lx.emit(itemArray)
|
|
||||||
return lexArrayValue
|
|
||||||
case inlineTableStart:
|
|
||||||
lx.ignore()
|
|
||||||
lx.emit(itemInlineTableStart)
|
|
||||||
return lexInlineTableValue
|
|
||||||
case stringStart:
|
|
||||||
if lx.accept(stringStart) {
|
|
||||||
if lx.accept(stringStart) {
|
|
||||||
lx.ignore() // Ignore """
|
|
||||||
return lexMultilineString
|
|
||||||
}
|
|
||||||
lx.backup()
|
|
||||||
}
|
|
||||||
lx.ignore() // ignore the '"'
|
|
||||||
return lexString
|
|
||||||
case rawStringStart:
|
|
||||||
if lx.accept(rawStringStart) {
|
|
||||||
if lx.accept(rawStringStart) {
|
|
||||||
lx.ignore() // Ignore """
|
|
||||||
return lexMultilineRawString
|
|
||||||
}
|
|
||||||
lx.backup()
|
|
||||||
}
|
|
||||||
lx.ignore() // ignore the "'"
|
|
||||||
return lexRawString
|
|
||||||
case '+', '-':
|
|
||||||
return lexNumberStart
|
|
||||||
case '.': // special error case, be kind to users
|
|
||||||
return lx.errorf("floats must start with a digit, not '.'")
|
|
||||||
}
|
|
||||||
if unicode.IsLetter(r) {
|
|
||||||
// Be permissive here; lexBool will give a nice error if the
|
|
||||||
// user wrote something like
|
|
||||||
// x = foo
|
|
||||||
// (i.e. not 'true' or 'false' but is something else word-like.)
|
|
||||||
lx.backup()
|
|
||||||
return lexBool
|
|
||||||
}
|
|
||||||
return lx.errorf("expected value but found %q instead", r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexArrayValue consumes one value in an array. It assumes that '[' or ','
|
|
||||||
// have already been consumed. All whitespace and newlines are ignored.
|
|
||||||
func lexArrayValue(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
switch {
|
|
||||||
case isWhitespace(r) || isNL(r):
|
|
||||||
return lexSkip(lx, lexArrayValue)
|
|
||||||
case r == commentStart:
|
|
||||||
lx.push(lexArrayValue)
|
|
||||||
return lexCommentStart
|
|
||||||
case r == comma:
|
|
||||||
return lx.errorf("unexpected comma")
|
|
||||||
case r == arrayEnd:
|
|
||||||
// NOTE(caleb): The spec isn't clear about whether you can have
|
|
||||||
// a trailing comma or not, so we'll allow it.
|
|
||||||
return lexArrayEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
lx.backup()
|
|
||||||
lx.push(lexArrayValueEnd)
|
|
||||||
return lexValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexArrayValueEnd consumes everything between the end of an array value and
|
|
||||||
// the next value (or the end of the array): it ignores whitespace and newlines
|
|
||||||
// and expects either a ',' or a ']'.
|
|
||||||
func lexArrayValueEnd(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
switch {
|
|
||||||
case isWhitespace(r) || isNL(r):
|
|
||||||
return lexSkip(lx, lexArrayValueEnd)
|
|
||||||
case r == commentStart:
|
|
||||||
lx.push(lexArrayValueEnd)
|
|
||||||
return lexCommentStart
|
|
||||||
case r == comma:
|
|
||||||
lx.ignore()
|
|
||||||
return lexArrayValue // move on to the next value
|
|
||||||
case r == arrayEnd:
|
|
||||||
return lexArrayEnd
|
|
||||||
}
|
|
||||||
return lx.errorf(
|
|
||||||
"expected a comma or array terminator %q, but got %q instead",
|
|
||||||
arrayEnd, r,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexArrayEnd finishes the lexing of an array.
|
|
||||||
// It assumes that a ']' has just been consumed.
|
|
||||||
func lexArrayEnd(lx *lexer) stateFn {
|
|
||||||
lx.ignore()
|
|
||||||
lx.emit(itemArrayEnd)
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexInlineTableValue consumes one key/value pair in an inline table.
|
|
||||||
// It assumes that '{' or ',' have already been consumed. Whitespace is ignored.
|
|
||||||
func lexInlineTableValue(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
switch {
|
|
||||||
case isWhitespace(r):
|
|
||||||
return lexSkip(lx, lexInlineTableValue)
|
|
||||||
case isNL(r):
|
|
||||||
return lx.errorf("newlines not allowed within inline tables")
|
|
||||||
case r == commentStart:
|
|
||||||
lx.push(lexInlineTableValue)
|
|
||||||
return lexCommentStart
|
|
||||||
case r == comma:
|
|
||||||
return lx.errorf("unexpected comma")
|
|
||||||
case r == inlineTableEnd:
|
|
||||||
return lexInlineTableEnd
|
|
||||||
}
|
|
||||||
lx.backup()
|
|
||||||
lx.push(lexInlineTableValueEnd)
|
|
||||||
return lexKeyStart
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexInlineTableValueEnd consumes everything between the end of an inline table
|
|
||||||
// key/value pair and the next pair (or the end of the table):
|
|
||||||
// it ignores whitespace and expects either a ',' or a '}'.
|
|
||||||
func lexInlineTableValueEnd(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
switch {
|
|
||||||
case isWhitespace(r):
|
|
||||||
return lexSkip(lx, lexInlineTableValueEnd)
|
|
||||||
case isNL(r):
|
|
||||||
return lx.errorf("newlines not allowed within inline tables")
|
|
||||||
case r == commentStart:
|
|
||||||
lx.push(lexInlineTableValueEnd)
|
|
||||||
return lexCommentStart
|
|
||||||
case r == comma:
|
|
||||||
lx.ignore()
|
|
||||||
return lexInlineTableValue
|
|
||||||
case r == inlineTableEnd:
|
|
||||||
return lexInlineTableEnd
|
|
||||||
}
|
|
||||||
return lx.errorf("expected a comma or an inline table terminator %q, "+
|
|
||||||
"but got %q instead", inlineTableEnd, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexInlineTableEnd finishes the lexing of an inline table.
|
|
||||||
// It assumes that a '}' has just been consumed.
|
|
||||||
func lexInlineTableEnd(lx *lexer) stateFn {
|
|
||||||
lx.ignore()
|
|
||||||
lx.emit(itemInlineTableEnd)
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexString consumes the inner contents of a string. It assumes that the
|
|
||||||
// beginning '"' has already been consumed and ignored.
|
|
||||||
func lexString(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
switch {
|
|
||||||
case r == eof:
|
|
||||||
return lx.errorf("unexpected EOF")
|
|
||||||
case isNL(r):
|
|
||||||
return lx.errorf("strings cannot contain newlines")
|
|
||||||
case r == '\\':
|
|
||||||
lx.push(lexString)
|
|
||||||
return lexStringEscape
|
|
||||||
case r == stringEnd:
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemString)
|
|
||||||
lx.next()
|
|
||||||
lx.ignore()
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
return lexString
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexMultilineString consumes the inner contents of a string. It assumes that
|
|
||||||
// the beginning '"""' has already been consumed and ignored.
|
|
||||||
func lexMultilineString(lx *lexer) stateFn {
|
|
||||||
switch lx.next() {
|
|
||||||
case eof:
|
|
||||||
return lx.errorf("unexpected EOF")
|
|
||||||
case '\\':
|
|
||||||
return lexMultilineStringEscape
|
|
||||||
case stringEnd:
|
|
||||||
if lx.accept(stringEnd) {
|
|
||||||
if lx.accept(stringEnd) {
|
|
||||||
lx.backup()
|
|
||||||
lx.backup()
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemMultilineString)
|
|
||||||
lx.next()
|
|
||||||
lx.next()
|
|
||||||
lx.next()
|
|
||||||
lx.ignore()
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
lx.backup()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lexMultilineString
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexRawString consumes a raw string. Nothing can be escaped in such a string.
|
|
||||||
// It assumes that the beginning "'" has already been consumed and ignored.
|
|
||||||
func lexRawString(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
switch {
|
|
||||||
case r == eof:
|
|
||||||
return lx.errorf("unexpected EOF")
|
|
||||||
case isNL(r):
|
|
||||||
return lx.errorf("strings cannot contain newlines")
|
|
||||||
case r == rawStringEnd:
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemRawString)
|
|
||||||
lx.next()
|
|
||||||
lx.ignore()
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
return lexRawString
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexMultilineRawString consumes a raw string. Nothing can be escaped in such
|
|
||||||
// a string. It assumes that the beginning "'''" has already been consumed and
|
|
||||||
// ignored.
|
|
||||||
func lexMultilineRawString(lx *lexer) stateFn {
|
|
||||||
switch lx.next() {
|
|
||||||
case eof:
|
|
||||||
return lx.errorf("unexpected EOF")
|
|
||||||
case rawStringEnd:
|
|
||||||
if lx.accept(rawStringEnd) {
|
|
||||||
if lx.accept(rawStringEnd) {
|
|
||||||
lx.backup()
|
|
||||||
lx.backup()
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemRawMultilineString)
|
|
||||||
lx.next()
|
|
||||||
lx.next()
|
|
||||||
lx.next()
|
|
||||||
lx.ignore()
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
lx.backup()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lexMultilineRawString
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexMultilineStringEscape consumes an escaped character. It assumes that the
|
|
||||||
// preceding '\\' has already been consumed.
|
|
||||||
func lexMultilineStringEscape(lx *lexer) stateFn {
|
|
||||||
// Handle the special case first:
|
|
||||||
if isNL(lx.next()) {
|
|
||||||
return lexMultilineString
|
|
||||||
}
|
|
||||||
lx.backup()
|
|
||||||
lx.push(lexMultilineString)
|
|
||||||
return lexStringEscape(lx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func lexStringEscape(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
switch r {
|
|
||||||
case 'b':
|
|
||||||
fallthrough
|
|
||||||
case 't':
|
|
||||||
fallthrough
|
|
||||||
case 'n':
|
|
||||||
fallthrough
|
|
||||||
case 'f':
|
|
||||||
fallthrough
|
|
||||||
case 'r':
|
|
||||||
fallthrough
|
|
||||||
case '"':
|
|
||||||
fallthrough
|
|
||||||
case '\\':
|
|
||||||
return lx.pop()
|
|
||||||
case 'u':
|
|
||||||
return lexShortUnicodeEscape
|
|
||||||
case 'U':
|
|
||||||
return lexLongUnicodeEscape
|
|
||||||
}
|
|
||||||
return lx.errorf("invalid escape character %q; only the following "+
|
|
||||||
"escape characters are allowed: "+
|
|
||||||
`\b, \t, \n, \f, \r, \", \\, \uXXXX, and \UXXXXXXXX`, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func lexShortUnicodeEscape(lx *lexer) stateFn {
|
|
||||||
var r rune
|
|
||||||
for i := 0; i < 4; i++ {
|
|
||||||
r = lx.next()
|
|
||||||
if !isHexadecimal(r) {
|
|
||||||
return lx.errorf(`expected four hexadecimal digits after '\u', `+
|
|
||||||
"but got %q instead", lx.current())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
func lexLongUnicodeEscape(lx *lexer) stateFn {
|
|
||||||
var r rune
|
|
||||||
for i := 0; i < 8; i++ {
|
|
||||||
r = lx.next()
|
|
||||||
if !isHexadecimal(r) {
|
|
||||||
return lx.errorf(`expected eight hexadecimal digits after '\U', `+
|
|
||||||
"but got %q instead", lx.current())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexNumberOrDateStart consumes either an integer, a float, or datetime.
|
|
||||||
func lexNumberOrDateStart(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
if isDigit(r) {
|
|
||||||
return lexNumberOrDate
|
|
||||||
}
|
|
||||||
switch r {
|
|
||||||
case '_':
|
|
||||||
return lexNumber
|
|
||||||
case 'e', 'E':
|
|
||||||
return lexFloat
|
|
||||||
case '.':
|
|
||||||
return lx.errorf("floats must start with a digit, not '.'")
|
|
||||||
}
|
|
||||||
return lx.errorf("expected a digit but got %q", r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexNumberOrDate consumes either an integer, float or datetime.
|
|
||||||
func lexNumberOrDate(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
if isDigit(r) {
|
|
||||||
return lexNumberOrDate
|
|
||||||
}
|
|
||||||
switch r {
|
|
||||||
case '-':
|
|
||||||
return lexDatetime
|
|
||||||
case '_':
|
|
||||||
return lexNumber
|
|
||||||
case '.', 'e', 'E':
|
|
||||||
return lexFloat
|
|
||||||
}
|
|
||||||
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemInteger)
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexDatetime consumes a Datetime, to a first approximation.
|
|
||||||
// The parser validates that it matches one of the accepted formats.
|
|
||||||
func lexDatetime(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
if isDigit(r) {
|
|
||||||
return lexDatetime
|
|
||||||
}
|
|
||||||
switch r {
|
|
||||||
case '-', 'T', ':', '.', 'Z', '+':
|
|
||||||
return lexDatetime
|
|
||||||
}
|
|
||||||
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemDatetime)
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexNumberStart consumes either an integer or a float. It assumes that a sign
|
|
||||||
// has already been read, but that *no* digits have been consumed.
|
|
||||||
// lexNumberStart will move to the appropriate integer or float states.
|
|
||||||
func lexNumberStart(lx *lexer) stateFn {
|
|
||||||
// We MUST see a digit. Even floats have to start with a digit.
|
|
||||||
r := lx.next()
|
|
||||||
if !isDigit(r) {
|
|
||||||
if r == '.' {
|
|
||||||
return lx.errorf("floats must start with a digit, not '.'")
|
|
||||||
}
|
|
||||||
return lx.errorf("expected a digit but got %q", r)
|
|
||||||
}
|
|
||||||
return lexNumber
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexNumber consumes an integer or a float after seeing the first digit.
|
|
||||||
func lexNumber(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
if isDigit(r) {
|
|
||||||
return lexNumber
|
|
||||||
}
|
|
||||||
switch r {
|
|
||||||
case '_':
|
|
||||||
return lexNumber
|
|
||||||
case '.', 'e', 'E':
|
|
||||||
return lexFloat
|
|
||||||
}
|
|
||||||
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemInteger)
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexFloat consumes the elements of a float. It allows any sequence of
|
|
||||||
// float-like characters, so floats emitted by the lexer are only a first
|
|
||||||
// approximation and must be validated by the parser.
|
|
||||||
func lexFloat(lx *lexer) stateFn {
|
|
||||||
r := lx.next()
|
|
||||||
if isDigit(r) {
|
|
||||||
return lexFloat
|
|
||||||
}
|
|
||||||
switch r {
|
|
||||||
case '_', '.', '-', '+', 'e', 'E':
|
|
||||||
return lexFloat
|
|
||||||
}
|
|
||||||
|
|
||||||
lx.backup()
|
|
||||||
lx.emit(itemFloat)
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexBool consumes a bool string: 'true' or 'false.
|
|
||||||
func lexBool(lx *lexer) stateFn {
|
|
||||||
var rs []rune
|
|
||||||
for {
|
|
||||||
r := lx.next()
|
|
||||||
if !unicode.IsLetter(r) {
|
|
||||||
lx.backup()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
rs = append(rs, r)
|
|
||||||
}
|
|
||||||
s := string(rs)
|
|
||||||
switch s {
|
|
||||||
case "true", "false":
|
|
||||||
lx.emit(itemBool)
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
return lx.errorf("expected value but found %q instead", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexCommentStart begins the lexing of a comment. It will emit
|
|
||||||
// itemCommentStart and consume no characters, passing control to lexComment.
|
|
||||||
func lexCommentStart(lx *lexer) stateFn {
|
|
||||||
lx.ignore()
|
|
||||||
lx.emit(itemCommentStart)
|
|
||||||
return lexComment
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexComment lexes an entire comment. It assumes that '#' has been consumed.
|
|
||||||
// It will consume *up to* the first newline character, and pass control
|
|
||||||
// back to the last state on the stack.
|
|
||||||
func lexComment(lx *lexer) stateFn {
|
|
||||||
r := lx.peek()
|
|
||||||
if isNL(r) || r == eof {
|
|
||||||
lx.emit(itemText)
|
|
||||||
return lx.pop()
|
|
||||||
}
|
|
||||||
lx.next()
|
|
||||||
return lexComment
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexSkip ignores all slurped input and moves on to the next state.
|
|
||||||
func lexSkip(lx *lexer, nextState stateFn) stateFn {
|
|
||||||
return func(lx *lexer) stateFn {
|
|
||||||
lx.ignore()
|
|
||||||
return nextState
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// isWhitespace returns true if `r` is a whitespace character according
|
|
||||||
// to the spec.
|
|
||||||
func isWhitespace(r rune) bool {
|
|
||||||
return r == '\t' || r == ' '
|
|
||||||
}
|
|
||||||
|
|
||||||
func isNL(r rune) bool {
|
|
||||||
return r == '\n' || r == '\r'
|
|
||||||
}
|
|
||||||
|
|
||||||
func isDigit(r rune) bool {
|
|
||||||
return r >= '0' && r <= '9'
|
|
||||||
}
|
|
||||||
|
|
||||||
func isHexadecimal(r rune) bool {
|
|
||||||
return (r >= '0' && r <= '9') ||
|
|
||||||
(r >= 'a' && r <= 'f') ||
|
|
||||||
(r >= 'A' && r <= 'F')
|
|
||||||
}
|
|
||||||
|
|
||||||
func isBareKeyChar(r rune) bool {
|
|
||||||
return (r >= 'A' && r <= 'Z') ||
|
|
||||||
(r >= 'a' && r <= 'z') ||
|
|
||||||
(r >= '0' && r <= '9') ||
|
|
||||||
r == '_' ||
|
|
||||||
r == '-'
|
|
||||||
}
|
|
||||||
|
|
||||||
func (itype itemType) String() string {
|
|
||||||
switch itype {
|
|
||||||
case itemError:
|
|
||||||
return "Error"
|
|
||||||
case itemNIL:
|
|
||||||
return "NIL"
|
|
||||||
case itemEOF:
|
|
||||||
return "EOF"
|
|
||||||
case itemText:
|
|
||||||
return "Text"
|
|
||||||
case itemString, itemRawString, itemMultilineString, itemRawMultilineString:
|
|
||||||
return "String"
|
|
||||||
case itemBool:
|
|
||||||
return "Bool"
|
|
||||||
case itemInteger:
|
|
||||||
return "Integer"
|
|
||||||
case itemFloat:
|
|
||||||
return "Float"
|
|
||||||
case itemDatetime:
|
|
||||||
return "DateTime"
|
|
||||||
case itemTableStart:
|
|
||||||
return "TableStart"
|
|
||||||
case itemTableEnd:
|
|
||||||
return "TableEnd"
|
|
||||||
case itemKeyStart:
|
|
||||||
return "KeyStart"
|
|
||||||
case itemArray:
|
|
||||||
return "Array"
|
|
||||||
case itemArrayEnd:
|
|
||||||
return "ArrayEnd"
|
|
||||||
case itemCommentStart:
|
|
||||||
return "CommentStart"
|
|
||||||
}
|
|
||||||
panic(fmt.Sprintf("BUG: Unknown type '%d'.", int(itype)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (item item) String() string {
|
|
||||||
return fmt.Sprintf("(%s, %s)", item.typ.String(), item.val)
|
|
||||||
}
|
|
592
vendor/github.com/BurntSushi/toml/parse.go
generated
vendored
592
vendor/github.com/BurntSushi/toml/parse.go
generated
vendored
@ -1,592 +0,0 @@
|
|||||||
package toml
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
"unicode"
|
|
||||||
"unicode/utf8"
|
|
||||||
)
|
|
||||||
|
|
||||||
type parser struct {
|
|
||||||
mapping map[string]interface{}
|
|
||||||
types map[string]tomlType
|
|
||||||
lx *lexer
|
|
||||||
|
|
||||||
// A list of keys in the order that they appear in the TOML data.
|
|
||||||
ordered []Key
|
|
||||||
|
|
||||||
// the full key for the current hash in scope
|
|
||||||
context Key
|
|
||||||
|
|
||||||
// the base key name for everything except hashes
|
|
||||||
currentKey string
|
|
||||||
|
|
||||||
// rough approximation of line number
|
|
||||||
approxLine int
|
|
||||||
|
|
||||||
// A map of 'key.group.names' to whether they were created implicitly.
|
|
||||||
implicits map[string]bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type parseError string
|
|
||||||
|
|
||||||
func (pe parseError) Error() string {
|
|
||||||
return string(pe)
|
|
||||||
}
|
|
||||||
|
|
||||||
func parse(data string) (p *parser, err error) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
var ok bool
|
|
||||||
if err, ok = r.(parseError); ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
p = &parser{
|
|
||||||
mapping: make(map[string]interface{}),
|
|
||||||
types: make(map[string]tomlType),
|
|
||||||
lx: lex(data),
|
|
||||||
ordered: make([]Key, 0),
|
|
||||||
implicits: make(map[string]bool),
|
|
||||||
}
|
|
||||||
for {
|
|
||||||
item := p.next()
|
|
||||||
if item.typ == itemEOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
p.topLevel(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
return p, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) panicf(format string, v ...interface{}) {
|
|
||||||
msg := fmt.Sprintf("Near line %d (last key parsed '%s'): %s",
|
|
||||||
p.approxLine, p.current(), fmt.Sprintf(format, v...))
|
|
||||||
panic(parseError(msg))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) next() item {
|
|
||||||
it := p.lx.nextItem()
|
|
||||||
if it.typ == itemError {
|
|
||||||
p.panicf("%s", it.val)
|
|
||||||
}
|
|
||||||
return it
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) bug(format string, v ...interface{}) {
|
|
||||||
panic(fmt.Sprintf("BUG: "+format+"\n\n", v...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) expect(typ itemType) item {
|
|
||||||
it := p.next()
|
|
||||||
p.assertEqual(typ, it.typ)
|
|
||||||
return it
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) assertEqual(expected, got itemType) {
|
|
||||||
if expected != got {
|
|
||||||
p.bug("Expected '%s' but got '%s'.", expected, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) topLevel(item item) {
|
|
||||||
switch item.typ {
|
|
||||||
case itemCommentStart:
|
|
||||||
p.approxLine = item.line
|
|
||||||
p.expect(itemText)
|
|
||||||
case itemTableStart:
|
|
||||||
kg := p.next()
|
|
||||||
p.approxLine = kg.line
|
|
||||||
|
|
||||||
var key Key
|
|
||||||
for ; kg.typ != itemTableEnd && kg.typ != itemEOF; kg = p.next() {
|
|
||||||
key = append(key, p.keyString(kg))
|
|
||||||
}
|
|
||||||
p.assertEqual(itemTableEnd, kg.typ)
|
|
||||||
|
|
||||||
p.establishContext(key, false)
|
|
||||||
p.setType("", tomlHash)
|
|
||||||
p.ordered = append(p.ordered, key)
|
|
||||||
case itemArrayTableStart:
|
|
||||||
kg := p.next()
|
|
||||||
p.approxLine = kg.line
|
|
||||||
|
|
||||||
var key Key
|
|
||||||
for ; kg.typ != itemArrayTableEnd && kg.typ != itemEOF; kg = p.next() {
|
|
||||||
key = append(key, p.keyString(kg))
|
|
||||||
}
|
|
||||||
p.assertEqual(itemArrayTableEnd, kg.typ)
|
|
||||||
|
|
||||||
p.establishContext(key, true)
|
|
||||||
p.setType("", tomlArrayHash)
|
|
||||||
p.ordered = append(p.ordered, key)
|
|
||||||
case itemKeyStart:
|
|
||||||
kname := p.next()
|
|
||||||
p.approxLine = kname.line
|
|
||||||
p.currentKey = p.keyString(kname)
|
|
||||||
|
|
||||||
val, typ := p.value(p.next())
|
|
||||||
p.setValue(p.currentKey, val)
|
|
||||||
p.setType(p.currentKey, typ)
|
|
||||||
p.ordered = append(p.ordered, p.context.add(p.currentKey))
|
|
||||||
p.currentKey = ""
|
|
||||||
default:
|
|
||||||
p.bug("Unexpected type at top level: %s", item.typ)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets a string for a key (or part of a key in a table name).
|
|
||||||
func (p *parser) keyString(it item) string {
|
|
||||||
switch it.typ {
|
|
||||||
case itemText:
|
|
||||||
return it.val
|
|
||||||
case itemString, itemMultilineString,
|
|
||||||
itemRawString, itemRawMultilineString:
|
|
||||||
s, _ := p.value(it)
|
|
||||||
return s.(string)
|
|
||||||
default:
|
|
||||||
p.bug("Unexpected key type: %s", it.typ)
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// value translates an expected value from the lexer into a Go value wrapped
|
|
||||||
// as an empty interface.
|
|
||||||
func (p *parser) value(it item) (interface{}, tomlType) {
|
|
||||||
switch it.typ {
|
|
||||||
case itemString:
|
|
||||||
return p.replaceEscapes(it.val), p.typeOfPrimitive(it)
|
|
||||||
case itemMultilineString:
|
|
||||||
trimmed := stripFirstNewline(stripEscapedWhitespace(it.val))
|
|
||||||
return p.replaceEscapes(trimmed), p.typeOfPrimitive(it)
|
|
||||||
case itemRawString:
|
|
||||||
return it.val, p.typeOfPrimitive(it)
|
|
||||||
case itemRawMultilineString:
|
|
||||||
return stripFirstNewline(it.val), p.typeOfPrimitive(it)
|
|
||||||
case itemBool:
|
|
||||||
switch it.val {
|
|
||||||
case "true":
|
|
||||||
return true, p.typeOfPrimitive(it)
|
|
||||||
case "false":
|
|
||||||
return false, p.typeOfPrimitive(it)
|
|
||||||
}
|
|
||||||
p.bug("Expected boolean value, but got '%s'.", it.val)
|
|
||||||
case itemInteger:
|
|
||||||
if !numUnderscoresOK(it.val) {
|
|
||||||
p.panicf("Invalid integer %q: underscores must be surrounded by digits",
|
|
||||||
it.val)
|
|
||||||
}
|
|
||||||
val := strings.Replace(it.val, "_", "", -1)
|
|
||||||
num, err := strconv.ParseInt(val, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
// Distinguish integer values. Normally, it'd be a bug if the lexer
|
|
||||||
// provides an invalid integer, but it's possible that the number is
|
|
||||||
// out of range of valid values (which the lexer cannot determine).
|
|
||||||
// So mark the former as a bug but the latter as a legitimate user
|
|
||||||
// error.
|
|
||||||
if e, ok := err.(*strconv.NumError); ok &&
|
|
||||||
e.Err == strconv.ErrRange {
|
|
||||||
|
|
||||||
p.panicf("Integer '%s' is out of the range of 64-bit "+
|
|
||||||
"signed integers.", it.val)
|
|
||||||
} else {
|
|
||||||
p.bug("Expected integer value, but got '%s'.", it.val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return num, p.typeOfPrimitive(it)
|
|
||||||
case itemFloat:
|
|
||||||
parts := strings.FieldsFunc(it.val, func(r rune) bool {
|
|
||||||
switch r {
|
|
||||||
case '.', 'e', 'E':
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
for _, part := range parts {
|
|
||||||
if !numUnderscoresOK(part) {
|
|
||||||
p.panicf("Invalid float %q: underscores must be "+
|
|
||||||
"surrounded by digits", it.val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !numPeriodsOK(it.val) {
|
|
||||||
// As a special case, numbers like '123.' or '1.e2',
|
|
||||||
// which are valid as far as Go/strconv are concerned,
|
|
||||||
// must be rejected because TOML says that a fractional
|
|
||||||
// part consists of '.' followed by 1+ digits.
|
|
||||||
p.panicf("Invalid float %q: '.' must be followed "+
|
|
||||||
"by one or more digits", it.val)
|
|
||||||
}
|
|
||||||
val := strings.Replace(it.val, "_", "", -1)
|
|
||||||
num, err := strconv.ParseFloat(val, 64)
|
|
||||||
if err != nil {
|
|
||||||
if e, ok := err.(*strconv.NumError); ok &&
|
|
||||||
e.Err == strconv.ErrRange {
|
|
||||||
|
|
||||||
p.panicf("Float '%s' is out of the range of 64-bit "+
|
|
||||||
"IEEE-754 floating-point numbers.", it.val)
|
|
||||||
} else {
|
|
||||||
p.panicf("Invalid float value: %q", it.val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return num, p.typeOfPrimitive(it)
|
|
||||||
case itemDatetime:
|
|
||||||
var t time.Time
|
|
||||||
var ok bool
|
|
||||||
var err error
|
|
||||||
for _, format := range []string{
|
|
||||||
"2006-01-02T15:04:05Z07:00",
|
|
||||||
"2006-01-02T15:04:05",
|
|
||||||
"2006-01-02",
|
|
||||||
} {
|
|
||||||
t, err = time.ParseInLocation(format, it.val, time.Local)
|
|
||||||
if err == nil {
|
|
||||||
ok = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
p.panicf("Invalid TOML Datetime: %q.", it.val)
|
|
||||||
}
|
|
||||||
return t, p.typeOfPrimitive(it)
|
|
||||||
case itemArray:
|
|
||||||
array := make([]interface{}, 0)
|
|
||||||
types := make([]tomlType, 0)
|
|
||||||
|
|
||||||
for it = p.next(); it.typ != itemArrayEnd; it = p.next() {
|
|
||||||
if it.typ == itemCommentStart {
|
|
||||||
p.expect(itemText)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
val, typ := p.value(it)
|
|
||||||
array = append(array, val)
|
|
||||||
types = append(types, typ)
|
|
||||||
}
|
|
||||||
return array, p.typeOfArray(types)
|
|
||||||
case itemInlineTableStart:
|
|
||||||
var (
|
|
||||||
hash = make(map[string]interface{})
|
|
||||||
outerContext = p.context
|
|
||||||
outerKey = p.currentKey
|
|
||||||
)
|
|
||||||
|
|
||||||
p.context = append(p.context, p.currentKey)
|
|
||||||
p.currentKey = ""
|
|
||||||
for it := p.next(); it.typ != itemInlineTableEnd; it = p.next() {
|
|
||||||
if it.typ != itemKeyStart {
|
|
||||||
p.bug("Expected key start but instead found %q, around line %d",
|
|
||||||
it.val, p.approxLine)
|
|
||||||
}
|
|
||||||
if it.typ == itemCommentStart {
|
|
||||||
p.expect(itemText)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// retrieve key
|
|
||||||
k := p.next()
|
|
||||||
p.approxLine = k.line
|
|
||||||
kname := p.keyString(k)
|
|
||||||
|
|
||||||
// retrieve value
|
|
||||||
p.currentKey = kname
|
|
||||||
val, typ := p.value(p.next())
|
|
||||||
// make sure we keep metadata up to date
|
|
||||||
p.setType(kname, typ)
|
|
||||||
p.ordered = append(p.ordered, p.context.add(p.currentKey))
|
|
||||||
hash[kname] = val
|
|
||||||
}
|
|
||||||
p.context = outerContext
|
|
||||||
p.currentKey = outerKey
|
|
||||||
return hash, tomlHash
|
|
||||||
}
|
|
||||||
p.bug("Unexpected value type: %s", it.typ)
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
// numUnderscoresOK checks whether each underscore in s is surrounded by
|
|
||||||
// characters that are not underscores.
|
|
||||||
func numUnderscoresOK(s string) bool {
|
|
||||||
accept := false
|
|
||||||
for _, r := range s {
|
|
||||||
if r == '_' {
|
|
||||||
if !accept {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
accept = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
accept = true
|
|
||||||
}
|
|
||||||
return accept
|
|
||||||
}
|
|
||||||
|
|
||||||
// numPeriodsOK checks whether every period in s is followed by a digit.
|
|
||||||
func numPeriodsOK(s string) bool {
|
|
||||||
period := false
|
|
||||||
for _, r := range s {
|
|
||||||
if period && !isDigit(r) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
period = r == '.'
|
|
||||||
}
|
|
||||||
return !period
|
|
||||||
}
|
|
||||||
|
|
||||||
// establishContext sets the current context of the parser,
|
|
||||||
// where the context is either a hash or an array of hashes. Which one is
|
|
||||||
// set depends on the value of the `array` parameter.
|
|
||||||
//
|
|
||||||
// Establishing the context also makes sure that the key isn't a duplicate, and
|
|
||||||
// will create implicit hashes automatically.
|
|
||||||
func (p *parser) establishContext(key Key, array bool) {
|
|
||||||
var ok bool
|
|
||||||
|
|
||||||
// Always start at the top level and drill down for our context.
|
|
||||||
hashContext := p.mapping
|
|
||||||
keyContext := make(Key, 0)
|
|
||||||
|
|
||||||
// We only need implicit hashes for key[0:-1]
|
|
||||||
for _, k := range key[0 : len(key)-1] {
|
|
||||||
_, ok = hashContext[k]
|
|
||||||
keyContext = append(keyContext, k)
|
|
||||||
|
|
||||||
// No key? Make an implicit hash and move on.
|
|
||||||
if !ok {
|
|
||||||
p.addImplicit(keyContext)
|
|
||||||
hashContext[k] = make(map[string]interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the hash context is actually an array of tables, then set
|
|
||||||
// the hash context to the last element in that array.
|
|
||||||
//
|
|
||||||
// Otherwise, it better be a table, since this MUST be a key group (by
|
|
||||||
// virtue of it not being the last element in a key).
|
|
||||||
switch t := hashContext[k].(type) {
|
|
||||||
case []map[string]interface{}:
|
|
||||||
hashContext = t[len(t)-1]
|
|
||||||
case map[string]interface{}:
|
|
||||||
hashContext = t
|
|
||||||
default:
|
|
||||||
p.panicf("Key '%s' was already created as a hash.", keyContext)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p.context = keyContext
|
|
||||||
if array {
|
|
||||||
// If this is the first element for this array, then allocate a new
|
|
||||||
// list of tables for it.
|
|
||||||
k := key[len(key)-1]
|
|
||||||
if _, ok := hashContext[k]; !ok {
|
|
||||||
hashContext[k] = make([]map[string]interface{}, 0, 5)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a new table. But make sure the key hasn't already been used
|
|
||||||
// for something else.
|
|
||||||
if hash, ok := hashContext[k].([]map[string]interface{}); ok {
|
|
||||||
hashContext[k] = append(hash, make(map[string]interface{}))
|
|
||||||
} else {
|
|
||||||
p.panicf("Key '%s' was already created and cannot be used as "+
|
|
||||||
"an array.", keyContext)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
p.setValue(key[len(key)-1], make(map[string]interface{}))
|
|
||||||
}
|
|
||||||
p.context = append(p.context, key[len(key)-1])
|
|
||||||
}
|
|
||||||
|
|
||||||
// setValue sets the given key to the given value in the current context.
|
|
||||||
// It will make sure that the key hasn't already been defined, account for
|
|
||||||
// implicit key groups.
|
|
||||||
func (p *parser) setValue(key string, value interface{}) {
|
|
||||||
var tmpHash interface{}
|
|
||||||
var ok bool
|
|
||||||
|
|
||||||
hash := p.mapping
|
|
||||||
keyContext := make(Key, 0)
|
|
||||||
for _, k := range p.context {
|
|
||||||
keyContext = append(keyContext, k)
|
|
||||||
if tmpHash, ok = hash[k]; !ok {
|
|
||||||
p.bug("Context for key '%s' has not been established.", keyContext)
|
|
||||||
}
|
|
||||||
switch t := tmpHash.(type) {
|
|
||||||
case []map[string]interface{}:
|
|
||||||
// The context is a table of hashes. Pick the most recent table
|
|
||||||
// defined as the current hash.
|
|
||||||
hash = t[len(t)-1]
|
|
||||||
case map[string]interface{}:
|
|
||||||
hash = t
|
|
||||||
default:
|
|
||||||
p.bug("Expected hash to have type 'map[string]interface{}', but "+
|
|
||||||
"it has '%T' instead.", tmpHash)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
keyContext = append(keyContext, key)
|
|
||||||
|
|
||||||
if _, ok := hash[key]; ok {
|
|
||||||
// Typically, if the given key has already been set, then we have
|
|
||||||
// to raise an error since duplicate keys are disallowed. However,
|
|
||||||
// it's possible that a key was previously defined implicitly. In this
|
|
||||||
// case, it is allowed to be redefined concretely. (See the
|
|
||||||
// `tests/valid/implicit-and-explicit-after.toml` test in `toml-test`.)
|
|
||||||
//
|
|
||||||
// But we have to make sure to stop marking it as an implicit. (So that
|
|
||||||
// another redefinition provokes an error.)
|
|
||||||
//
|
|
||||||
// Note that since it has already been defined (as a hash), we don't
|
|
||||||
// want to overwrite it. So our business is done.
|
|
||||||
if p.isImplicit(keyContext) {
|
|
||||||
p.removeImplicit(keyContext)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, we have a concrete key trying to override a previous
|
|
||||||
// key, which is *always* wrong.
|
|
||||||
p.panicf("Key '%s' has already been defined.", keyContext)
|
|
||||||
}
|
|
||||||
hash[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
// setType sets the type of a particular value at a given key.
|
|
||||||
// It should be called immediately AFTER setValue.
|
|
||||||
//
|
|
||||||
// Note that if `key` is empty, then the type given will be applied to the
|
|
||||||
// current context (which is either a table or an array of tables).
|
|
||||||
func (p *parser) setType(key string, typ tomlType) {
|
|
||||||
keyContext := make(Key, 0, len(p.context)+1)
|
|
||||||
for _, k := range p.context {
|
|
||||||
keyContext = append(keyContext, k)
|
|
||||||
}
|
|
||||||
if len(key) > 0 { // allow type setting for hashes
|
|
||||||
keyContext = append(keyContext, key)
|
|
||||||
}
|
|
||||||
p.types[keyContext.String()] = typ
|
|
||||||
}
|
|
||||||
|
|
||||||
// addImplicit sets the given Key as having been created implicitly.
|
|
||||||
func (p *parser) addImplicit(key Key) {
|
|
||||||
p.implicits[key.String()] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// removeImplicit stops tagging the given key as having been implicitly
|
|
||||||
// created.
|
|
||||||
func (p *parser) removeImplicit(key Key) {
|
|
||||||
p.implicits[key.String()] = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// isImplicit returns true if the key group pointed to by the key was created
|
|
||||||
// implicitly.
|
|
||||||
func (p *parser) isImplicit(key Key) bool {
|
|
||||||
return p.implicits[key.String()]
|
|
||||||
}
|
|
||||||
|
|
||||||
// current returns the full key name of the current context.
|
|
||||||
func (p *parser) current() string {
|
|
||||||
if len(p.currentKey) == 0 {
|
|
||||||
return p.context.String()
|
|
||||||
}
|
|
||||||
if len(p.context) == 0 {
|
|
||||||
return p.currentKey
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s.%s", p.context, p.currentKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func stripFirstNewline(s string) string {
|
|
||||||
if len(s) == 0 || s[0] != '\n' {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return s[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
func stripEscapedWhitespace(s string) string {
|
|
||||||
esc := strings.Split(s, "\\\n")
|
|
||||||
if len(esc) > 1 {
|
|
||||||
for i := 1; i < len(esc); i++ {
|
|
||||||
esc[i] = strings.TrimLeftFunc(esc[i], unicode.IsSpace)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return strings.Join(esc, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) replaceEscapes(str string) string {
|
|
||||||
var replaced []rune
|
|
||||||
s := []byte(str)
|
|
||||||
r := 0
|
|
||||||
for r < len(s) {
|
|
||||||
if s[r] != '\\' {
|
|
||||||
c, size := utf8.DecodeRune(s[r:])
|
|
||||||
r += size
|
|
||||||
replaced = append(replaced, c)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
r += 1
|
|
||||||
if r >= len(s) {
|
|
||||||
p.bug("Escape sequence at end of string.")
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
switch s[r] {
|
|
||||||
default:
|
|
||||||
p.bug("Expected valid escape code after \\, but got %q.", s[r])
|
|
||||||
return ""
|
|
||||||
case 'b':
|
|
||||||
replaced = append(replaced, rune(0x0008))
|
|
||||||
r += 1
|
|
||||||
case 't':
|
|
||||||
replaced = append(replaced, rune(0x0009))
|
|
||||||
r += 1
|
|
||||||
case 'n':
|
|
||||||
replaced = append(replaced, rune(0x000A))
|
|
||||||
r += 1
|
|
||||||
case 'f':
|
|
||||||
replaced = append(replaced, rune(0x000C))
|
|
||||||
r += 1
|
|
||||||
case 'r':
|
|
||||||
replaced = append(replaced, rune(0x000D))
|
|
||||||
r += 1
|
|
||||||
case '"':
|
|
||||||
replaced = append(replaced, rune(0x0022))
|
|
||||||
r += 1
|
|
||||||
case '\\':
|
|
||||||
replaced = append(replaced, rune(0x005C))
|
|
||||||
r += 1
|
|
||||||
case 'u':
|
|
||||||
// At this point, we know we have a Unicode escape of the form
|
|
||||||
// `uXXXX` at [r, r+5). (Because the lexer guarantees this
|
|
||||||
// for us.)
|
|
||||||
escaped := p.asciiEscapeToUnicode(s[r+1 : r+5])
|
|
||||||
replaced = append(replaced, escaped)
|
|
||||||
r += 5
|
|
||||||
case 'U':
|
|
||||||
// At this point, we know we have a Unicode escape of the form
|
|
||||||
// `uXXXX` at [r, r+9). (Because the lexer guarantees this
|
|
||||||
// for us.)
|
|
||||||
escaped := p.asciiEscapeToUnicode(s[r+1 : r+9])
|
|
||||||
replaced = append(replaced, escaped)
|
|
||||||
r += 9
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string(replaced)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) asciiEscapeToUnicode(bs []byte) rune {
|
|
||||||
s := string(bs)
|
|
||||||
hex, err := strconv.ParseUint(strings.ToLower(s), 16, 32)
|
|
||||||
if err != nil {
|
|
||||||
p.bug("Could not parse '%s' as a hexadecimal number, but the "+
|
|
||||||
"lexer claims it's OK: %s", s, err)
|
|
||||||
}
|
|
||||||
if !utf8.ValidRune(rune(hex)) {
|
|
||||||
p.panicf("Escaped character '\\u%s' is not valid UTF-8.", s)
|
|
||||||
}
|
|
||||||
return rune(hex)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isStringType(ty itemType) bool {
|
|
||||||
return ty == itemString || ty == itemMultilineString ||
|
|
||||||
ty == itemRawString || ty == itemRawMultilineString
|
|
||||||
}
|
|
91
vendor/github.com/BurntSushi/toml/type_check.go
generated
vendored
91
vendor/github.com/BurntSushi/toml/type_check.go
generated
vendored
@ -1,91 +0,0 @@
|
|||||||
package toml
|
|
||||||
|
|
||||||
// tomlType represents any Go type that corresponds to a TOML type.
|
|
||||||
// While the first draft of the TOML spec has a simplistic type system that
|
|
||||||
// probably doesn't need this level of sophistication, we seem to be militating
|
|
||||||
// toward adding real composite types.
|
|
||||||
type tomlType interface {
|
|
||||||
typeString() string
|
|
||||||
}
|
|
||||||
|
|
||||||
// typeEqual accepts any two types and returns true if they are equal.
|
|
||||||
func typeEqual(t1, t2 tomlType) bool {
|
|
||||||
if t1 == nil || t2 == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return t1.typeString() == t2.typeString()
|
|
||||||
}
|
|
||||||
|
|
||||||
func typeIsHash(t tomlType) bool {
|
|
||||||
return typeEqual(t, tomlHash) || typeEqual(t, tomlArrayHash)
|
|
||||||
}
|
|
||||||
|
|
||||||
type tomlBaseType string
|
|
||||||
|
|
||||||
func (btype tomlBaseType) typeString() string {
|
|
||||||
return string(btype)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (btype tomlBaseType) String() string {
|
|
||||||
return btype.typeString()
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
tomlInteger tomlBaseType = "Integer"
|
|
||||||
tomlFloat tomlBaseType = "Float"
|
|
||||||
tomlDatetime tomlBaseType = "Datetime"
|
|
||||||
tomlString tomlBaseType = "String"
|
|
||||||
tomlBool tomlBaseType = "Bool"
|
|
||||||
tomlArray tomlBaseType = "Array"
|
|
||||||
tomlHash tomlBaseType = "Hash"
|
|
||||||
tomlArrayHash tomlBaseType = "ArrayHash"
|
|
||||||
)
|
|
||||||
|
|
||||||
// typeOfPrimitive returns a tomlType of any primitive value in TOML.
|
|
||||||
// Primitive values are: Integer, Float, Datetime, String and Bool.
|
|
||||||
//
|
|
||||||
// Passing a lexer item other than the following will cause a BUG message
|
|
||||||
// to occur: itemString, itemBool, itemInteger, itemFloat, itemDatetime.
|
|
||||||
func (p *parser) typeOfPrimitive(lexItem item) tomlType {
|
|
||||||
switch lexItem.typ {
|
|
||||||
case itemInteger:
|
|
||||||
return tomlInteger
|
|
||||||
case itemFloat:
|
|
||||||
return tomlFloat
|
|
||||||
case itemDatetime:
|
|
||||||
return tomlDatetime
|
|
||||||
case itemString:
|
|
||||||
return tomlString
|
|
||||||
case itemMultilineString:
|
|
||||||
return tomlString
|
|
||||||
case itemRawString:
|
|
||||||
return tomlString
|
|
||||||
case itemRawMultilineString:
|
|
||||||
return tomlString
|
|
||||||
case itemBool:
|
|
||||||
return tomlBool
|
|
||||||
}
|
|
||||||
p.bug("Cannot infer primitive type of lex item '%s'.", lexItem)
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
||||||
// typeOfArray returns a tomlType for an array given a list of types of its
|
|
||||||
// values.
|
|
||||||
//
|
|
||||||
// In the current spec, if an array is homogeneous, then its type is always
|
|
||||||
// "Array". If the array is not homogeneous, an error is generated.
|
|
||||||
func (p *parser) typeOfArray(types []tomlType) tomlType {
|
|
||||||
// Empty arrays are cool.
|
|
||||||
if len(types) == 0 {
|
|
||||||
return tomlArray
|
|
||||||
}
|
|
||||||
|
|
||||||
theType := types[0]
|
|
||||||
for _, t := range types[1:] {
|
|
||||||
if !typeEqual(theType, t) {
|
|
||||||
p.panicf("Array contains values of type '%s' and '%s', but "+
|
|
||||||
"arrays must be homogeneous.", theType, t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tomlArray
|
|
||||||
}
|
|
242
vendor/github.com/BurntSushi/toml/type_fields.go
generated
vendored
242
vendor/github.com/BurntSushi/toml/type_fields.go
generated
vendored
@ -1,242 +0,0 @@
|
|||||||
package toml
|
|
||||||
|
|
||||||
// Struct field handling is adapted from code in encoding/json:
|
|
||||||
//
|
|
||||||
// Copyright 2010 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the Go distribution.
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"sort"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A field represents a single field found in a struct.
|
|
||||||
type field struct {
|
|
||||||
name string // the name of the field (`toml` tag included)
|
|
||||||
tag bool // whether field has a `toml` tag
|
|
||||||
index []int // represents the depth of an anonymous field
|
|
||||||
typ reflect.Type // the type of the field
|
|
||||||
}
|
|
||||||
|
|
||||||
// byName sorts field by name, breaking ties with depth,
|
|
||||||
// then breaking ties with "name came from toml tag", then
|
|
||||||
// breaking ties with index sequence.
|
|
||||||
type byName []field
|
|
||||||
|
|
||||||
func (x byName) Len() int { return len(x) }
|
|
||||||
|
|
||||||
func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
|
||||||
|
|
||||||
func (x byName) Less(i, j int) bool {
|
|
||||||
if x[i].name != x[j].name {
|
|
||||||
return x[i].name < x[j].name
|
|
||||||
}
|
|
||||||
if len(x[i].index) != len(x[j].index) {
|
|
||||||
return len(x[i].index) < len(x[j].index)
|
|
||||||
}
|
|
||||||
if x[i].tag != x[j].tag {
|
|
||||||
return x[i].tag
|
|
||||||
}
|
|
||||||
return byIndex(x).Less(i, j)
|
|
||||||
}
|
|
||||||
|
|
||||||
// byIndex sorts field by index sequence.
|
|
||||||
type byIndex []field
|
|
||||||
|
|
||||||
func (x byIndex) Len() int { return len(x) }
|
|
||||||
|
|
||||||
func (x byIndex) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
|
||||||
|
|
||||||
func (x byIndex) Less(i, j int) bool {
|
|
||||||
for k, xik := range x[i].index {
|
|
||||||
if k >= len(x[j].index) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if xik != x[j].index[k] {
|
|
||||||
return xik < x[j].index[k]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return len(x[i].index) < len(x[j].index)
|
|
||||||
}
|
|
||||||
|
|
||||||
// typeFields returns a list of fields that TOML should recognize for the given
|
|
||||||
// type. The algorithm is breadth-first search over the set of structs to
|
|
||||||
// include - the top struct and then any reachable anonymous structs.
|
|
||||||
func typeFields(t reflect.Type) []field {
|
|
||||||
// Anonymous fields to explore at the current level and the next.
|
|
||||||
current := []field{}
|
|
||||||
next := []field{{typ: t}}
|
|
||||||
|
|
||||||
// Count of queued names for current level and the next.
|
|
||||||
count := map[reflect.Type]int{}
|
|
||||||
nextCount := map[reflect.Type]int{}
|
|
||||||
|
|
||||||
// Types already visited at an earlier level.
|
|
||||||
visited := map[reflect.Type]bool{}
|
|
||||||
|
|
||||||
// Fields found.
|
|
||||||
var fields []field
|
|
||||||
|
|
||||||
for len(next) > 0 {
|
|
||||||
current, next = next, current[:0]
|
|
||||||
count, nextCount = nextCount, map[reflect.Type]int{}
|
|
||||||
|
|
||||||
for _, f := range current {
|
|
||||||
if visited[f.typ] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
visited[f.typ] = true
|
|
||||||
|
|
||||||
// Scan f.typ for fields to include.
|
|
||||||
for i := 0; i < f.typ.NumField(); i++ {
|
|
||||||
sf := f.typ.Field(i)
|
|
||||||
if sf.PkgPath != "" && !sf.Anonymous { // unexported
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
opts := getOptions(sf.Tag)
|
|
||||||
if opts.skip {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
index := make([]int, len(f.index)+1)
|
|
||||||
copy(index, f.index)
|
|
||||||
index[len(f.index)] = i
|
|
||||||
|
|
||||||
ft := sf.Type
|
|
||||||
if ft.Name() == "" && ft.Kind() == reflect.Ptr {
|
|
||||||
// Follow pointer.
|
|
||||||
ft = ft.Elem()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Record found field and index sequence.
|
|
||||||
if opts.name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct {
|
|
||||||
tagged := opts.name != ""
|
|
||||||
name := opts.name
|
|
||||||
if name == "" {
|
|
||||||
name = sf.Name
|
|
||||||
}
|
|
||||||
fields = append(fields, field{name, tagged, index, ft})
|
|
||||||
if count[f.typ] > 1 {
|
|
||||||
// If there were multiple instances, add a second,
|
|
||||||
// so that the annihilation code will see a duplicate.
|
|
||||||
// It only cares about the distinction between 1 or 2,
|
|
||||||
// so don't bother generating any more copies.
|
|
||||||
fields = append(fields, fields[len(fields)-1])
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Record new anonymous struct to explore in next round.
|
|
||||||
nextCount[ft]++
|
|
||||||
if nextCount[ft] == 1 {
|
|
||||||
f := field{name: ft.Name(), index: index, typ: ft}
|
|
||||||
next = append(next, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Sort(byName(fields))
|
|
||||||
|
|
||||||
// Delete all fields that are hidden by the Go rules for embedded fields,
|
|
||||||
// except that fields with TOML tags are promoted.
|
|
||||||
|
|
||||||
// The fields are sorted in primary order of name, secondary order
|
|
||||||
// of field index length. Loop over names; for each name, delete
|
|
||||||
// hidden fields by choosing the one dominant field that survives.
|
|
||||||
out := fields[:0]
|
|
||||||
for advance, i := 0, 0; i < len(fields); i += advance {
|
|
||||||
// One iteration per name.
|
|
||||||
// Find the sequence of fields with the name of this first field.
|
|
||||||
fi := fields[i]
|
|
||||||
name := fi.name
|
|
||||||
for advance = 1; i+advance < len(fields); advance++ {
|
|
||||||
fj := fields[i+advance]
|
|
||||||
if fj.name != name {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if advance == 1 { // Only one field with this name
|
|
||||||
out = append(out, fi)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
dominant, ok := dominantField(fields[i : i+advance])
|
|
||||||
if ok {
|
|
||||||
out = append(out, dominant)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fields = out
|
|
||||||
sort.Sort(byIndex(fields))
|
|
||||||
|
|
||||||
return fields
|
|
||||||
}
|
|
||||||
|
|
||||||
// dominantField looks through the fields, all of which are known to
|
|
||||||
// have the same name, to find the single field that dominates the
|
|
||||||
// others using Go's embedding rules, modified by the presence of
|
|
||||||
// TOML tags. If there are multiple top-level fields, the boolean
|
|
||||||
// will be false: This condition is an error in Go and we skip all
|
|
||||||
// the fields.
|
|
||||||
func dominantField(fields []field) (field, bool) {
|
|
||||||
// The fields are sorted in increasing index-length order. The winner
|
|
||||||
// must therefore be one with the shortest index length. Drop all
|
|
||||||
// longer entries, which is easy: just truncate the slice.
|
|
||||||
length := len(fields[0].index)
|
|
||||||
tagged := -1 // Index of first tagged field.
|
|
||||||
for i, f := range fields {
|
|
||||||
if len(f.index) > length {
|
|
||||||
fields = fields[:i]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if f.tag {
|
|
||||||
if tagged >= 0 {
|
|
||||||
// Multiple tagged fields at the same level: conflict.
|
|
||||||
// Return no field.
|
|
||||||
return field{}, false
|
|
||||||
}
|
|
||||||
tagged = i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if tagged >= 0 {
|
|
||||||
return fields[tagged], true
|
|
||||||
}
|
|
||||||
// All remaining fields have the same length. If there's more than one,
|
|
||||||
// we have a conflict (two fields named "X" at the same level) and we
|
|
||||||
// return no field.
|
|
||||||
if len(fields) > 1 {
|
|
||||||
return field{}, false
|
|
||||||
}
|
|
||||||
return fields[0], true
|
|
||||||
}
|
|
||||||
|
|
||||||
var fieldCache struct {
|
|
||||||
sync.RWMutex
|
|
||||||
m map[reflect.Type][]field
|
|
||||||
}
|
|
||||||
|
|
||||||
// cachedTypeFields is like typeFields but uses a cache to avoid repeated work.
|
|
||||||
func cachedTypeFields(t reflect.Type) []field {
|
|
||||||
fieldCache.RLock()
|
|
||||||
f := fieldCache.m[t]
|
|
||||||
fieldCache.RUnlock()
|
|
||||||
if f != nil {
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compute fields without lock.
|
|
||||||
// Might duplicate effort but won't hold other computations back.
|
|
||||||
f = typeFields(t)
|
|
||||||
if f == nil {
|
|
||||||
f = []field{}
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldCache.Lock()
|
|
||||||
if fieldCache.m == nil {
|
|
||||||
fieldCache.m = map[reflect.Type][]field{}
|
|
||||||
}
|
|
||||||
fieldCache.m[t] = f
|
|
||||||
fieldCache.Unlock()
|
|
||||||
return f
|
|
||||||
}
|
|
9
vendor/github.com/a8m/mark/LICENSE
generated
vendored
9
vendor/github.com/a8m/mark/LICENSE
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
The MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2015 Ariel Mashraki
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
94
vendor/github.com/a8m/mark/cmd/mark/main.go
generated
vendored
94
vendor/github.com/a8m/mark/cmd/mark/main.go
generated
vendored
@ -1,94 +0,0 @@
|
|||||||
// mark command line tool. available at https://github.com/a8m/mark
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/a8m/mark"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
input = flag.String("i", "", "")
|
|
||||||
output = flag.String("o", "", "")
|
|
||||||
smarty = flag.Bool("smartypants", false, "")
|
|
||||||
fractions = flag.Bool("fractions", false, "")
|
|
||||||
)
|
|
||||||
|
|
||||||
var usage = `Usage: mark [options...] <input>
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-i Specify file input, otherwise use last argument as input file.
|
|
||||||
If no input file is specified, read from stdin.
|
|
||||||
-o Specify file output. If none is specified, write to stdout.
|
|
||||||
|
|
||||||
-smartypants Use "smart" typograhic punctuation for things like
|
|
||||||
quotes and dashes.
|
|
||||||
-fractions Traslate fraction like to suitable HTML elements
|
|
||||||
`
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Usage = func() {
|
|
||||||
fmt.Fprint(os.Stderr, fmt.Sprintf(usage))
|
|
||||||
}
|
|
||||||
flag.Parse()
|
|
||||||
// read
|
|
||||||
var reader *bufio.Reader
|
|
||||||
if *input != "" {
|
|
||||||
file, err := os.Open(*input)
|
|
||||||
if err != nil {
|
|
||||||
usageAndExit(fmt.Sprintf("Error to open file input: %s.", *input))
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
reader = bufio.NewReader(file)
|
|
||||||
} else {
|
|
||||||
stat, err := os.Stdin.Stat()
|
|
||||||
if err != nil || (stat.Mode()&os.ModeCharDevice) != 0 {
|
|
||||||
usageAndExit("")
|
|
||||||
}
|
|
||||||
reader = bufio.NewReader(os.Stdin)
|
|
||||||
}
|
|
||||||
// collect data
|
|
||||||
var data string
|
|
||||||
for {
|
|
||||||
line, err := reader.ReadString('\n')
|
|
||||||
if err != nil {
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
usageAndExit("failed to reading input.")
|
|
||||||
}
|
|
||||||
data += line
|
|
||||||
}
|
|
||||||
// write
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
file = os.Stdout
|
|
||||||
)
|
|
||||||
if *output != "" {
|
|
||||||
if file, err = os.Create(*output); err != nil {
|
|
||||||
usageAndExit("error to create the wanted output file.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// mark rendering
|
|
||||||
opts := mark.DefaultOptions()
|
|
||||||
opts.Smartypants = *smarty
|
|
||||||
opts.Fractions = *fractions
|
|
||||||
m := mark.New(data, opts)
|
|
||||||
if _, err := file.WriteString(m.Render()); err != nil {
|
|
||||||
usageAndExit(fmt.Sprintf("error writing output to: %s.", file.Name()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func usageAndExit(msg string) {
|
|
||||||
if msg != "" {
|
|
||||||
fmt.Fprintf(os.Stderr, msg)
|
|
||||||
fmt.Fprintf(os.Stderr, "\n\n")
|
|
||||||
}
|
|
||||||
flag.Usage()
|
|
||||||
fmt.Fprintf(os.Stderr, "\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
92
vendor/github.com/a8m/mark/grammar.go
generated
vendored
92
vendor/github.com/a8m/mark/grammar.go
generated
vendored
@ -1,92 +0,0 @@
|
|||||||
package mark
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"regexp"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Block Grammar
|
|
||||||
var (
|
|
||||||
reHr = regexp.MustCompile(`^(?:(?:\* *){3,}|(?:_ *){3,}|(?:- *){3,}) *(?:\n+|$)`)
|
|
||||||
reHeading = regexp.MustCompile(`^ *(#{1,6})(?: +#*| +([^\n]*?)|)(?: +#*|) *(?:\n|$)`)
|
|
||||||
reLHeading = regexp.MustCompile(`^([^\n]+?) *\n {0,3}(=|-){1,} *(?:\n+|$)`)
|
|
||||||
reBlockQuote = regexp.MustCompile(`^ *>[^\n]*(\n[^\n]+)*\n*`)
|
|
||||||
reDefLink = regexp.MustCompile(`(?s)^ *\[([^\]]+)\]: *\n? *<?([^\s>]+)>?(?: *\n? *["'(](.+?)['")])? *(?:\n+|$)`)
|
|
||||||
reSpaceGen = func(i int) *regexp.Regexp {
|
|
||||||
return regexp.MustCompile(fmt.Sprintf(`(?m)^ {1,%d}`, i))
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
var reList = struct {
|
|
||||||
item, marker, loose *regexp.Regexp
|
|
||||||
scanLine, scanNewLine func(src string) string
|
|
||||||
}{
|
|
||||||
regexp.MustCompile(`^( *)(?:[*+-]|\d{1,9}\.) (.*)(?:\n|)`),
|
|
||||||
regexp.MustCompile(`^ *([*+-]|\d+\.) +`),
|
|
||||||
regexp.MustCompile(`(?m)\n\n(.*)`),
|
|
||||||
regexp.MustCompile(`^(.*)(?:\n|)`).FindString,
|
|
||||||
regexp.MustCompile(`^\n{1,}`).FindString,
|
|
||||||
}
|
|
||||||
|
|
||||||
var reCodeBlock = struct {
|
|
||||||
*regexp.Regexp
|
|
||||||
trim func(src, repl string) string
|
|
||||||
}{
|
|
||||||
regexp.MustCompile(`^( {4}[^\n]+(?: *\n)*)+`),
|
|
||||||
regexp.MustCompile("(?m)^( {0,4})").ReplaceAllLiteralString,
|
|
||||||
}
|
|
||||||
|
|
||||||
var reGfmCode = struct {
|
|
||||||
*regexp.Regexp
|
|
||||||
endGen func(end string, i int) *regexp.Regexp
|
|
||||||
}{
|
|
||||||
regexp.MustCompile("^( {0,3})([`~]{3,}) *(\\S*)?(?:.*)"),
|
|
||||||
func(end string, i int) *regexp.Regexp {
|
|
||||||
return regexp.MustCompile(fmt.Sprintf(`(?s)(.*?)(?:((?m)^ {0,3}%s{%d,} *$)|$)`, end, i))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var reTable = struct {
|
|
||||||
item, itemLp *regexp.Regexp
|
|
||||||
split func(s string, n int) []string
|
|
||||||
trim func(src, repl string) string
|
|
||||||
}{
|
|
||||||
regexp.MustCompile(`^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*`),
|
|
||||||
regexp.MustCompile(`(^ *\|.+)\n( *\| *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*`),
|
|
||||||
regexp.MustCompile(` *\| *`).Split,
|
|
||||||
regexp.MustCompile(`^ *\| *| *\| *$`).ReplaceAllString,
|
|
||||||
}
|
|
||||||
|
|
||||||
var reHTML = struct {
|
|
||||||
CDATA_OPEN, CDATA_CLOSE string
|
|
||||||
item, comment, tag, span *regexp.Regexp
|
|
||||||
endTagGen func(tag string) *regexp.Regexp
|
|
||||||
}{
|
|
||||||
`![CDATA[`,
|
|
||||||
"?\\]\\]",
|
|
||||||
regexp.MustCompile(`^<(\w+|!\[CDATA\[)(?:"[^"]*"|'[^']*'|[^'">])*?>`),
|
|
||||||
regexp.MustCompile(`(?sm)<!--.*?-->`),
|
|
||||||
regexp.MustCompile(`^<!--.*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>`),
|
|
||||||
// TODO: Add all span-tags and move to config.
|
|
||||||
regexp.MustCompile(`^(a|em|strong|small|s|q|data|time|code|sub|sup|i|b|u|span|br|del|img)$`),
|
|
||||||
func(tag string) *regexp.Regexp {
|
|
||||||
return regexp.MustCompile(fmt.Sprintf(`(?s)(.+?)<\/%s> *`, tag))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inline Grammar
|
|
||||||
var (
|
|
||||||
reBr = regexp.MustCompile(`^(?: {2,}|\\)\n`)
|
|
||||||
reLinkText = `(?:\[[^\]]*\]|[^\[\]]|\])*`
|
|
||||||
reLinkHref = `\s*<?(.*?)>?(?:\s+['"\(](.*?)['"\)])?\s*`
|
|
||||||
reGfmLink = regexp.MustCompile(`^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])`)
|
|
||||||
reLink = regexp.MustCompile(fmt.Sprintf(`(?s)^!?\[(%s)\]\(%s\)`, reLinkText, reLinkHref))
|
|
||||||
reAutoLink = regexp.MustCompile(`^<([^ >]+(@|:\/)[^ >]+)>`)
|
|
||||||
reRefLink = regexp.MustCompile(`^!?\[((?:\[[^\]]*\]|[^\[\]]|\])*)\](?:\s*\[([^\]]*)\])?`)
|
|
||||||
reImage = regexp.MustCompile(fmt.Sprintf(`(?s)^!?\[(%s)\]\(%s\)`, reLinkText, reLinkHref))
|
|
||||||
reCode = regexp.MustCompile("(?s)^`{1,2}\\s*(.*?[^`])\\s*`{1,2}")
|
|
||||||
reStrike = regexp.MustCompile(`(?s)^~{2}(.+?)~{2}`)
|
|
||||||
reEmphasise = `(?s)^_{%[1]d}(\S.*?_*)_{%[1]d}|^\*{%[1]d}(\S.*?\**)\*{%[1]d}`
|
|
||||||
reItalic = regexp.MustCompile(fmt.Sprintf(reEmphasise, 1))
|
|
||||||
reStrong = regexp.MustCompile(fmt.Sprintf(reEmphasise, 2))
|
|
||||||
)
|
|
568
vendor/github.com/a8m/mark/lexer.go
generated
vendored
568
vendor/github.com/a8m/mark/lexer.go
generated
vendored
@ -1,568 +0,0 @@
|
|||||||
package mark
|
|
||||||
|
|
||||||
import (
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"unicode/utf8"
|
|
||||||
)
|
|
||||||
|
|
||||||
// type position
|
|
||||||
type Pos int
|
|
||||||
|
|
||||||
// itemType identifies the type of lex items.
|
|
||||||
type itemType int
|
|
||||||
|
|
||||||
// Item represent a token or text string returned from the scanner
|
|
||||||
type item struct {
|
|
||||||
typ itemType // The type of this item.
|
|
||||||
pos Pos // The starting position, in bytes, of this item in the input string.
|
|
||||||
val string // The value of this item.
|
|
||||||
}
|
|
||||||
|
|
||||||
const eof = -1 // Zero value so closed channel delivers EOF
|
|
||||||
|
|
||||||
const (
|
|
||||||
itemError itemType = iota // Error occurred; value is text of error
|
|
||||||
itemEOF
|
|
||||||
itemNewLine
|
|
||||||
itemHTML
|
|
||||||
itemHeading
|
|
||||||
itemLHeading
|
|
||||||
itemBlockQuote
|
|
||||||
itemList
|
|
||||||
itemListItem
|
|
||||||
itemLooseItem
|
|
||||||
itemCodeBlock
|
|
||||||
itemGfmCodeBlock
|
|
||||||
itemHr
|
|
||||||
itemTable
|
|
||||||
itemLpTable
|
|
||||||
itemTableRow
|
|
||||||
itemTableCell
|
|
||||||
itemStrong
|
|
||||||
itemItalic
|
|
||||||
itemStrike
|
|
||||||
itemCode
|
|
||||||
itemLink
|
|
||||||
itemDefLink
|
|
||||||
itemRefLink
|
|
||||||
itemAutoLink
|
|
||||||
itemGfmLink
|
|
||||||
itemImage
|
|
||||||
itemRefImage
|
|
||||||
itemText
|
|
||||||
itemBr
|
|
||||||
itemPipe
|
|
||||||
itemIndent
|
|
||||||
)
|
|
||||||
|
|
||||||
// stateFn represents the state of the scanner as a function that returns the next state.
|
|
||||||
type stateFn func(*lexer) stateFn
|
|
||||||
|
|
||||||
// Lexer interface, used to composed it inside the parser
|
|
||||||
type Lexer interface {
|
|
||||||
nextItem() item
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexer holds the state of the scanner.
|
|
||||||
type lexer struct {
|
|
||||||
input string // the string being scanned
|
|
||||||
state stateFn // the next lexing function to enter
|
|
||||||
pos Pos // current position in the input
|
|
||||||
start Pos // start position of this item
|
|
||||||
width Pos // width of last rune read from input
|
|
||||||
lastPos Pos // position of most recent item returned by nextItem
|
|
||||||
items chan item // channel of scanned items
|
|
||||||
}
|
|
||||||
|
|
||||||
// lex creates a new lexer for the input string.
|
|
||||||
func lex(input string) *lexer {
|
|
||||||
l := &lexer{
|
|
||||||
input: input,
|
|
||||||
items: make(chan item),
|
|
||||||
}
|
|
||||||
go l.run()
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexInline create a new lexer for one phase lexing(inline blocks).
|
|
||||||
func lexInline(input string) *lexer {
|
|
||||||
l := &lexer{
|
|
||||||
input: input,
|
|
||||||
items: make(chan item),
|
|
||||||
}
|
|
||||||
go l.lexInline()
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
// run runs the state machine for the lexer.
|
|
||||||
func (l *lexer) run() {
|
|
||||||
for l.state = lexAny; l.state != nil; {
|
|
||||||
l.state = l.state(l)
|
|
||||||
}
|
|
||||||
close(l.items)
|
|
||||||
}
|
|
||||||
|
|
||||||
// next return the next rune in the input
|
|
||||||
func (l *lexer) next() rune {
|
|
||||||
if int(l.pos) >= len(l.input) {
|
|
||||||
l.width = 0
|
|
||||||
return eof
|
|
||||||
}
|
|
||||||
r, w := utf8.DecodeRuneInString(l.input[l.pos:])
|
|
||||||
l.width = Pos(w)
|
|
||||||
l.pos += l.width
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexAny scanner is kind of forwarder, it get the current char in the text
|
|
||||||
// and forward it to the appropriate scanner based on some conditions.
|
|
||||||
func lexAny(l *lexer) stateFn {
|
|
||||||
switch r := l.peek(); r {
|
|
||||||
case '*', '-', '_':
|
|
||||||
return lexHr
|
|
||||||
case '+', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
|
||||||
return lexList
|
|
||||||
case '<':
|
|
||||||
return lexHTML
|
|
||||||
case '>':
|
|
||||||
return lexBlockQuote
|
|
||||||
case '[':
|
|
||||||
return lexDefLink
|
|
||||||
case '#':
|
|
||||||
return lexHeading
|
|
||||||
case '`', '~':
|
|
||||||
return lexGfmCode
|
|
||||||
case ' ':
|
|
||||||
if reCodeBlock.MatchString(l.input[l.pos:]) {
|
|
||||||
return lexCode
|
|
||||||
} else if reGfmCode.MatchString(l.input[l.pos:]) {
|
|
||||||
return lexGfmCode
|
|
||||||
}
|
|
||||||
// Keep moving forward until we get all the indentation size
|
|
||||||
for ; r == l.peek(); r = l.next() {
|
|
||||||
}
|
|
||||||
l.emit(itemIndent)
|
|
||||||
return lexAny
|
|
||||||
case '|':
|
|
||||||
if m := reTable.itemLp.MatchString(l.input[l.pos:]); m {
|
|
||||||
l.emit(itemLpTable)
|
|
||||||
return lexTable
|
|
||||||
}
|
|
||||||
fallthrough
|
|
||||||
default:
|
|
||||||
if m := reTable.item.MatchString(l.input[l.pos:]); m {
|
|
||||||
l.emit(itemTable)
|
|
||||||
return lexTable
|
|
||||||
}
|
|
||||||
return lexText
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexHeading test if the current text position is an heading item.
|
|
||||||
// is so, it will emit an item and return back to lenAny function
|
|
||||||
// else, lex it as a simple text value
|
|
||||||
func lexHeading(l *lexer) stateFn {
|
|
||||||
if m := reHeading.FindString(l.input[l.pos:]); m != "" {
|
|
||||||
l.pos += Pos(len(m))
|
|
||||||
l.emit(itemHeading)
|
|
||||||
return lexAny
|
|
||||||
}
|
|
||||||
return lexText
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexHr test if the current text position is an horizontal rules item.
|
|
||||||
// is so, it will emit an horizontal rule item and return back to lenAny function
|
|
||||||
// else, forward it to lexList function
|
|
||||||
func lexHr(l *lexer) stateFn {
|
|
||||||
if match := reHr.FindString(l.input[l.pos:]); match != "" {
|
|
||||||
l.pos += Pos(len(match))
|
|
||||||
l.emit(itemHr)
|
|
||||||
return lexAny
|
|
||||||
}
|
|
||||||
return lexList
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexGfmCode test if the current text position is start of GFM code-block item.
|
|
||||||
// if so, it will generate regexp based on the fence type[`~] and it length.
|
|
||||||
// it scan until the end, and then emit the code-block item and return back to the
|
|
||||||
// lenAny forwarder.
|
|
||||||
// else, lex it as a simple inline text.
|
|
||||||
func lexGfmCode(l *lexer) stateFn {
|
|
||||||
if match := reGfmCode.FindStringSubmatch(l.input[l.pos:]); len(match) != 0 {
|
|
||||||
l.pos += Pos(len(match[0]))
|
|
||||||
fence := match[2]
|
|
||||||
// Generate Regexp based on fence type[`~] and length
|
|
||||||
reGfmEnd := reGfmCode.endGen(fence[0:1], len(fence))
|
|
||||||
infoContainer := reGfmEnd.FindStringSubmatch(l.input[l.pos:])
|
|
||||||
l.pos += Pos(len(infoContainer[0]))
|
|
||||||
infoString := infoContainer[1]
|
|
||||||
// Remove leading and trailing spaces
|
|
||||||
if indent := len(match[1]); indent > 0 {
|
|
||||||
reSpace := reSpaceGen(indent)
|
|
||||||
infoString = reSpace.ReplaceAllString(infoString, "")
|
|
||||||
}
|
|
||||||
l.emit(itemGfmCodeBlock, match[0]+infoString)
|
|
||||||
return lexAny
|
|
||||||
}
|
|
||||||
return lexText
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexCode scans code block.
|
|
||||||
func lexCode(l *lexer) stateFn {
|
|
||||||
match := reCodeBlock.FindString(l.input[l.pos:])
|
|
||||||
l.pos += Pos(len(match))
|
|
||||||
l.emit(itemCodeBlock)
|
|
||||||
return lexAny
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexText scans until end-of-line(\n)
|
|
||||||
func lexText(l *lexer) stateFn {
|
|
||||||
// Drain text before emitting
|
|
||||||
emit := func(item itemType, pos Pos) {
|
|
||||||
if l.pos > l.start {
|
|
||||||
l.emit(itemText)
|
|
||||||
}
|
|
||||||
l.pos += pos
|
|
||||||
l.emit(item)
|
|
||||||
}
|
|
||||||
Loop:
|
|
||||||
for {
|
|
||||||
switch r := l.peek(); r {
|
|
||||||
case eof:
|
|
||||||
emit(itemEOF, Pos(0))
|
|
||||||
break Loop
|
|
||||||
case '\n':
|
|
||||||
// CM 4.4: An indented code block cannot interrupt a paragraph.
|
|
||||||
if l.pos > l.start && strings.HasPrefix(l.input[l.pos+1:], " ") {
|
|
||||||
l.next()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
emit(itemNewLine, l.width)
|
|
||||||
break Loop
|
|
||||||
default:
|
|
||||||
// Test for Setext-style headers
|
|
||||||
if m := reLHeading.FindString(l.input[l.pos:]); m != "" {
|
|
||||||
emit(itemLHeading, Pos(len(m)))
|
|
||||||
break Loop
|
|
||||||
}
|
|
||||||
l.next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lexAny
|
|
||||||
}
|
|
||||||
|
|
||||||
// backup steps back one rune. Can only be called once per call of next.
|
|
||||||
func (l *lexer) backup() {
|
|
||||||
l.pos -= l.width
|
|
||||||
}
|
|
||||||
|
|
||||||
// peek returns but does not consume the next rune in the input.
|
|
||||||
func (l *lexer) peek() rune {
|
|
||||||
r := l.next()
|
|
||||||
l.backup()
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// emit passes an item back to the client.
|
|
||||||
func (l *lexer) emit(t itemType, s ...string) {
|
|
||||||
if len(s) == 0 {
|
|
||||||
s = append(s, l.input[l.start:l.pos])
|
|
||||||
}
|
|
||||||
l.items <- item{t, l.start, s[0]}
|
|
||||||
l.start = l.pos
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexItem return the next item token, called by the parser.
|
|
||||||
func (l *lexer) nextItem() item {
|
|
||||||
item := <-l.items
|
|
||||||
l.lastPos = l.pos
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
|
|
||||||
// One phase lexing(inline reason)
|
|
||||||
func (l *lexer) lexInline() {
|
|
||||||
escape := regexp.MustCompile("^\\\\([\\`*{}\\[\\]()#+\\-.!_>~|])")
|
|
||||||
// Drain text before emitting
|
|
||||||
emit := func(item itemType, pos int) {
|
|
||||||
if l.pos > l.start {
|
|
||||||
l.emit(itemText)
|
|
||||||
}
|
|
||||||
l.pos += Pos(pos)
|
|
||||||
l.emit(item)
|
|
||||||
}
|
|
||||||
Loop:
|
|
||||||
for {
|
|
||||||
switch r := l.peek(); r {
|
|
||||||
case eof:
|
|
||||||
if l.pos > l.start {
|
|
||||||
l.emit(itemText)
|
|
||||||
}
|
|
||||||
break Loop
|
|
||||||
// backslash escaping
|
|
||||||
case '\\':
|
|
||||||
if m := escape.FindStringSubmatch(l.input[l.pos:]); len(m) != 0 {
|
|
||||||
if l.pos > l.start {
|
|
||||||
l.emit(itemText)
|
|
||||||
}
|
|
||||||
l.pos += Pos(len(m[0]))
|
|
||||||
l.emit(itemText, m[1])
|
|
||||||
break
|
|
||||||
}
|
|
||||||
fallthrough
|
|
||||||
case ' ':
|
|
||||||
if m := reBr.FindString(l.input[l.pos:]); m != "" {
|
|
||||||
// pos - length of new-line
|
|
||||||
emit(itemBr, len(m))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
l.next()
|
|
||||||
case '_', '*', '~', '`':
|
|
||||||
input := l.input[l.pos:]
|
|
||||||
// Strong
|
|
||||||
if m := reStrong.FindString(input); m != "" {
|
|
||||||
emit(itemStrong, len(m))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// Italic
|
|
||||||
if m := reItalic.FindString(input); m != "" {
|
|
||||||
emit(itemItalic, len(m))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// Strike
|
|
||||||
if m := reStrike.FindString(input); m != "" {
|
|
||||||
emit(itemStrike, len(m))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// InlineCode
|
|
||||||
if m := reCode.FindString(input); m != "" {
|
|
||||||
emit(itemCode, len(m))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
l.next()
|
|
||||||
// itemLink, itemImage, itemRefLink, itemRefImage
|
|
||||||
case '[', '!':
|
|
||||||
input := l.input[l.pos:]
|
|
||||||
if m := reLink.FindString(input); m != "" {
|
|
||||||
pos := len(m)
|
|
||||||
if r == '[' {
|
|
||||||
emit(itemLink, pos)
|
|
||||||
} else {
|
|
||||||
emit(itemImage, pos)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if m := reRefLink.FindString(input); m != "" {
|
|
||||||
pos := len(m)
|
|
||||||
if r == '[' {
|
|
||||||
emit(itemRefLink, pos)
|
|
||||||
} else {
|
|
||||||
emit(itemRefImage, pos)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
l.next()
|
|
||||||
// itemAutoLink, htmlBlock
|
|
||||||
case '<':
|
|
||||||
if m := reAutoLink.FindString(l.input[l.pos:]); m != "" {
|
|
||||||
emit(itemAutoLink, len(m))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if match, res := l.matchHTML(l.input[l.pos:]); match {
|
|
||||||
emit(itemHTML, len(res))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
l.next()
|
|
||||||
default:
|
|
||||||
if m := reGfmLink.FindString(l.input[l.pos:]); m != "" {
|
|
||||||
emit(itemGfmLink, len(m))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
l.next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(l.items)
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexHTML.
|
|
||||||
func lexHTML(l *lexer) stateFn {
|
|
||||||
if match, res := l.matchHTML(l.input[l.pos:]); match {
|
|
||||||
l.pos += Pos(len(res))
|
|
||||||
l.emit(itemHTML)
|
|
||||||
return lexAny
|
|
||||||
}
|
|
||||||
return lexText
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test if the given input is match the HTML pattern(blocks only)
|
|
||||||
func (l *lexer) matchHTML(input string) (bool, string) {
|
|
||||||
if m := reHTML.comment.FindString(input); m != "" {
|
|
||||||
return true, m
|
|
||||||
}
|
|
||||||
if m := reHTML.item.FindStringSubmatch(input); len(m) != 0 {
|
|
||||||
el, name := m[0], m[1]
|
|
||||||
// if name is a span... is a text
|
|
||||||
if reHTML.span.MatchString(name) {
|
|
||||||
return false, ""
|
|
||||||
}
|
|
||||||
// if it's a self-closed html element, but not a itemAutoLink
|
|
||||||
if strings.HasSuffix(el, "/>") && !reAutoLink.MatchString(el) {
|
|
||||||
return true, el
|
|
||||||
}
|
|
||||||
if name == reHTML.CDATA_OPEN {
|
|
||||||
name = reHTML.CDATA_CLOSE
|
|
||||||
}
|
|
||||||
reEndTag := reHTML.endTagGen(name)
|
|
||||||
if m := reEndTag.FindString(input); m != "" {
|
|
||||||
return true, m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexDefLink scans link definition
|
|
||||||
func lexDefLink(l *lexer) stateFn {
|
|
||||||
if m := reDefLink.FindString(l.input[l.pos:]); m != "" {
|
|
||||||
l.pos += Pos(len(m))
|
|
||||||
l.emit(itemDefLink)
|
|
||||||
return lexAny
|
|
||||||
}
|
|
||||||
return lexText
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexList scans ordered and unordered lists.
|
|
||||||
func lexList(l *lexer) stateFn {
|
|
||||||
match, items := l.matchList(l.input[l.pos:])
|
|
||||||
if !match {
|
|
||||||
return lexText
|
|
||||||
}
|
|
||||||
var space int
|
|
||||||
var typ itemType
|
|
||||||
for i, item := range items {
|
|
||||||
// Emit itemList on the first loop
|
|
||||||
if i == 0 {
|
|
||||||
l.emit(itemList, reList.marker.FindStringSubmatch(item)[1])
|
|
||||||
}
|
|
||||||
// Initialize each loop
|
|
||||||
typ = itemListItem
|
|
||||||
space = len(item)
|
|
||||||
l.pos += Pos(space)
|
|
||||||
item = reList.marker.ReplaceAllString(item, "")
|
|
||||||
// Indented
|
|
||||||
if strings.Contains(item, "\n ") {
|
|
||||||
space -= len(item)
|
|
||||||
reSpace := reSpaceGen(space)
|
|
||||||
item = reSpace.ReplaceAllString(item, "")
|
|
||||||
}
|
|
||||||
// If current is loose
|
|
||||||
for _, l := range reList.loose.FindAllString(item, -1) {
|
|
||||||
if len(strings.TrimSpace(l)) > 0 || i != len(items)-1 {
|
|
||||||
typ = itemLooseItem
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// or previous
|
|
||||||
if typ != itemLooseItem && i > 0 && strings.HasSuffix(items[i-1], "\n\n") {
|
|
||||||
typ = itemLooseItem
|
|
||||||
}
|
|
||||||
l.emit(typ, strings.TrimSpace(item))
|
|
||||||
}
|
|
||||||
return lexAny
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *lexer) matchList(input string) (bool, []string) {
|
|
||||||
var res []string
|
|
||||||
reItem := reList.item
|
|
||||||
if !reItem.MatchString(input) {
|
|
||||||
return false, res
|
|
||||||
}
|
|
||||||
// First item
|
|
||||||
m := reItem.FindStringSubmatch(input)
|
|
||||||
item, depth := m[0], len(m[1])
|
|
||||||
input = input[len(item):]
|
|
||||||
// Loop over the input
|
|
||||||
for len(input) > 0 {
|
|
||||||
// Count new-lines('\n')
|
|
||||||
if m := reList.scanNewLine(input); m != "" {
|
|
||||||
item += m
|
|
||||||
input = input[len(m):]
|
|
||||||
if len(m) >= 2 || !reItem.MatchString(input) && !strings.HasPrefix(input, " ") {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// DefLink or hr
|
|
||||||
if reDefLink.MatchString(input) || reHr.MatchString(input) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// It's list in the same depth
|
|
||||||
if m := reItem.FindStringSubmatch(input); len(m) > 0 && len(m[1]) == depth {
|
|
||||||
if item != "" {
|
|
||||||
res = append(res, item)
|
|
||||||
}
|
|
||||||
item = m[0]
|
|
||||||
input = input[len(item):]
|
|
||||||
} else {
|
|
||||||
m := reList.scanLine(input)
|
|
||||||
item += m
|
|
||||||
input = input[len(m):]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Drain res
|
|
||||||
if item != "" {
|
|
||||||
res = append(res, item)
|
|
||||||
}
|
|
||||||
return true, res
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test if the given input match blockquote
|
|
||||||
func (l *lexer) matchBlockQuote(input string) (bool, string) {
|
|
||||||
match := reBlockQuote.FindString(input)
|
|
||||||
if match == "" {
|
|
||||||
return false, match
|
|
||||||
}
|
|
||||||
lines := strings.Split(match, "\n")
|
|
||||||
for i, line := range lines {
|
|
||||||
// if line is a link-definition or horizontal role, we cut the match until this point
|
|
||||||
if reDefLink.MatchString(line) || reHr.MatchString(line) {
|
|
||||||
match = strings.Join(lines[0:i], "\n")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true, match
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexBlockQuote
|
|
||||||
func lexBlockQuote(l *lexer) stateFn {
|
|
||||||
if match, res := l.matchBlockQuote(l.input[l.pos:]); match {
|
|
||||||
l.pos += Pos(len(res))
|
|
||||||
l.emit(itemBlockQuote)
|
|
||||||
return lexAny
|
|
||||||
}
|
|
||||||
return lexText
|
|
||||||
}
|
|
||||||
|
|
||||||
// lexTable
|
|
||||||
func lexTable(l *lexer) stateFn {
|
|
||||||
re := reTable.item
|
|
||||||
if l.peek() == '|' {
|
|
||||||
re = reTable.itemLp
|
|
||||||
}
|
|
||||||
table := re.FindStringSubmatch(l.input[l.pos:])
|
|
||||||
l.pos += Pos(len(table[0]))
|
|
||||||
l.start = l.pos
|
|
||||||
// Ignore the first match, and flat all rows(by splitting \n)
|
|
||||||
rows := append(table[1:3], strings.Split(table[3], "\n")...)
|
|
||||||
for _, row := range rows {
|
|
||||||
if row == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
l.emit(itemTableRow)
|
|
||||||
rawCells := reTable.trim(row, "")
|
|
||||||
cells := reTable.split(rawCells, -1)
|
|
||||||
// Emit cells in the current row
|
|
||||||
for _, cell := range cells {
|
|
||||||
l.emit(itemTableCell, cell)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lexAny
|
|
||||||
}
|
|
60
vendor/github.com/a8m/mark/mark.go
generated
vendored
60
vendor/github.com/a8m/mark/mark.go
generated
vendored
@ -1,60 +0,0 @@
|
|||||||
package mark
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
// Mark
|
|
||||||
type Mark struct {
|
|
||||||
*parse
|
|
||||||
Input string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark options used to configure your Mark object
|
|
||||||
// set `Smartypants` and `Fractions` to true to enable
|
|
||||||
// smartypants and smartfractions rendering.
|
|
||||||
type Options struct {
|
|
||||||
Gfm bool
|
|
||||||
Tables bool
|
|
||||||
Smartypants bool
|
|
||||||
Fractions bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultOptions return an options struct with default configuration
|
|
||||||
// it's means that only Gfm, and Tables set to true.
|
|
||||||
func DefaultOptions() *Options {
|
|
||||||
return &Options{
|
|
||||||
Gfm: true,
|
|
||||||
Tables: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// New return a new Mark
|
|
||||||
func New(input string, opts *Options) *Mark {
|
|
||||||
// Preprocessing
|
|
||||||
input = strings.Replace(input, "\t", " ", -1)
|
|
||||||
if opts == nil {
|
|
||||||
opts = DefaultOptions()
|
|
||||||
}
|
|
||||||
return &Mark{
|
|
||||||
Input: input,
|
|
||||||
parse: newParse(input, opts),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse and render input
|
|
||||||
func (m *Mark) Render() string {
|
|
||||||
m.parse.parse()
|
|
||||||
m.render()
|
|
||||||
return m.output
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddRenderFn let you pass NodeType, and RenderFn function
|
|
||||||
// and override the default Node rendering
|
|
||||||
func (m *Mark) AddRenderFn(typ NodeType, fn RenderFn) {
|
|
||||||
m.renderFn[typ] = fn
|
|
||||||
}
|
|
||||||
|
|
||||||
// Staic render function
|
|
||||||
func Render(input string) string {
|
|
||||||
m := New(input, nil)
|
|
||||||
return m.Render()
|
|
||||||
}
|
|
614
vendor/github.com/a8m/mark/node.go
generated
vendored
614
vendor/github.com/a8m/mark/node.go
generated
vendored
@ -1,614 +0,0 @@
|
|||||||
package mark
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// A Node is an element in the parse tree.
|
|
||||||
type Node interface {
|
|
||||||
Type() NodeType
|
|
||||||
Render() string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NodeType identifies the type of a parse tree node.
|
|
||||||
type NodeType int
|
|
||||||
|
|
||||||
// Type returns itself and provides an easy default implementation
|
|
||||||
// for embedding in a Node. Embedded in all non-trivial Nodes.
|
|
||||||
func (t NodeType) Type() NodeType {
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render function, used for overriding default rendering.
|
|
||||||
type RenderFn func(Node) string
|
|
||||||
|
|
||||||
const (
|
|
||||||
NodeText NodeType = iota // A plain text
|
|
||||||
NodeParagraph // A Paragraph
|
|
||||||
NodeEmphasis // An emphasis(strong, em, ...)
|
|
||||||
NodeHeading // A heading (h1, h2, ...)
|
|
||||||
NodeBr // A link break
|
|
||||||
NodeHr // A horizontal rule
|
|
||||||
NodeImage // An image
|
|
||||||
NodeRefImage // A image reference
|
|
||||||
NodeList // A list of ListItems
|
|
||||||
NodeListItem // A list item node
|
|
||||||
NodeLink // A link(href)
|
|
||||||
NodeRefLink // A link reference
|
|
||||||
NodeDefLink // A link definition
|
|
||||||
NodeTable // A table of NodeRows
|
|
||||||
NodeRow // A row of NodeCells
|
|
||||||
NodeCell // A table-cell(td)
|
|
||||||
NodeCode // A code block(wrapped with pre)
|
|
||||||
NodeBlockQuote // A blockquote
|
|
||||||
NodeHTML // An inline HTML
|
|
||||||
NodeCheckbox // A checkbox
|
|
||||||
)
|
|
||||||
|
|
||||||
// ParagraphNode hold simple paragraph node contains text
|
|
||||||
// that may be emphasis.
|
|
||||||
type ParagraphNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Nodes []Node
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation of ParagraphNode
|
|
||||||
func (n *ParagraphNode) Render() (s string) {
|
|
||||||
for _, node := range n.Nodes {
|
|
||||||
s += node.Render()
|
|
||||||
}
|
|
||||||
return wrap("p", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newParagraph(pos Pos) *ParagraphNode {
|
|
||||||
return &ParagraphNode{NodeType: NodeParagraph, Pos: pos}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TextNode holds plain text.
|
|
||||||
type TextNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Text string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the string representation of TexNode
|
|
||||||
func (n *TextNode) Render() string {
|
|
||||||
return n.Text
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newText(pos Pos, text string) *TextNode {
|
|
||||||
return &TextNode{NodeType: NodeText, Pos: pos, Text: p.text(text)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTMLNode holds the raw html source.
|
|
||||||
type HTMLNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Src string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the src of the HTMLNode
|
|
||||||
func (n *HTMLNode) Render() string {
|
|
||||||
return n.Src
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newHTML(pos Pos, src string) *HTMLNode {
|
|
||||||
return &HTMLNode{NodeType: NodeHTML, Pos: pos, Src: src}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HrNode represents horizontal rule
|
|
||||||
type HrNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation of hr.
|
|
||||||
func (n *HrNode) Render() string {
|
|
||||||
return "<hr>"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newHr(pos Pos) *HrNode {
|
|
||||||
return &HrNode{NodeType: NodeHr, Pos: pos}
|
|
||||||
}
|
|
||||||
|
|
||||||
// BrNode represents a link-break element.
|
|
||||||
type BrNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation of line-break.
|
|
||||||
func (n *BrNode) Render() string {
|
|
||||||
return "<br>"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newBr(pos Pos) *BrNode {
|
|
||||||
return &BrNode{NodeType: NodeBr, Pos: pos}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EmphasisNode holds plain-text wrapped with style.
|
|
||||||
// (strong, em, del, code)
|
|
||||||
type EmphasisNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Style itemType
|
|
||||||
Nodes []Node
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tag return the tagName based on the Style field.
|
|
||||||
func (n *EmphasisNode) Tag() (s string) {
|
|
||||||
switch n.Style {
|
|
||||||
case itemStrong:
|
|
||||||
s = "strong"
|
|
||||||
case itemItalic:
|
|
||||||
s = "em"
|
|
||||||
case itemStrike:
|
|
||||||
s = "del"
|
|
||||||
case itemCode:
|
|
||||||
s = "code"
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the html representation of emphasis text.
|
|
||||||
func (n *EmphasisNode) Render() string {
|
|
||||||
var s string
|
|
||||||
for _, node := range n.Nodes {
|
|
||||||
s += node.Render()
|
|
||||||
}
|
|
||||||
return wrap(n.Tag(), s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newEmphasis(pos Pos, style itemType) *EmphasisNode {
|
|
||||||
return &EmphasisNode{NodeType: NodeEmphasis, Pos: pos, Style: style}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HeadingNode holds heaing element with specific level(1-6).
|
|
||||||
type HeadingNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Level int
|
|
||||||
Text string
|
|
||||||
Nodes []Node
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation based on heading level.
|
|
||||||
func (n *HeadingNode) Render() (s string) {
|
|
||||||
for _, node := range n.Nodes {
|
|
||||||
s += node.Render()
|
|
||||||
}
|
|
||||||
re := regexp.MustCompile(`[^\w]+`)
|
|
||||||
id := re.ReplaceAllString(n.Text, "-")
|
|
||||||
// ToLowerCase
|
|
||||||
id = strings.ToLower(id)
|
|
||||||
return fmt.Sprintf("<%[1]s id=\"%s\">%s</%[1]s>", "h"+strconv.Itoa(n.Level), id, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newHeading(pos Pos, level int, text string) *HeadingNode {
|
|
||||||
return &HeadingNode{NodeType: NodeHeading, Pos: pos, Level: level, Text: p.text(text)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Code holds CodeBlock node with specific lang field.
|
|
||||||
type CodeNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Lang, Text string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the html representation of codeBlock
|
|
||||||
func (n *CodeNode) Render() string {
|
|
||||||
var attr string
|
|
||||||
if n.Lang != "" {
|
|
||||||
attr = fmt.Sprintf(" class=\"lang-%s\"", n.Lang)
|
|
||||||
}
|
|
||||||
code := fmt.Sprintf("<%[1]s%s>%s</%[1]s>", "code", attr, n.Text)
|
|
||||||
return wrap("pre", code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newCode(pos Pos, lang, text string) *CodeNode {
|
|
||||||
// DRY: see `escape()` below
|
|
||||||
text = strings.NewReplacer("<", "<", ">", ">", "\"", """, "&", "&").Replace(text)
|
|
||||||
return &CodeNode{NodeType: NodeCode, Pos: pos, Lang: lang, Text: text}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Link holds a tag with optional title
|
|
||||||
type LinkNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Title, Href string
|
|
||||||
Nodes []Node
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the html representation of link node
|
|
||||||
func (n *LinkNode) Render() (s string) {
|
|
||||||
for _, node := range n.Nodes {
|
|
||||||
s += node.Render()
|
|
||||||
}
|
|
||||||
attrs := fmt.Sprintf("href=\"%s\"", n.Href)
|
|
||||||
if n.Title != "" {
|
|
||||||
attrs += fmt.Sprintf(" title=\"%s\"", n.Title)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("<a %s>%s</a>", attrs, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newLink(pos Pos, title, href string, nodes ...Node) *LinkNode {
|
|
||||||
return &LinkNode{NodeType: NodeLink, Pos: pos, Title: p.text(title), Href: p.text(href), Nodes: nodes}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RefLink holds link with refrence to link definition
|
|
||||||
type RefNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
tr *parse
|
|
||||||
Text, Ref, Raw string
|
|
||||||
Nodes []Node
|
|
||||||
}
|
|
||||||
|
|
||||||
// rendering based type
|
|
||||||
func (n *RefNode) Render() string {
|
|
||||||
var node Node
|
|
||||||
ref := strings.ToLower(n.Ref)
|
|
||||||
if l, ok := n.tr.links[ref]; ok {
|
|
||||||
if n.Type() == NodeRefLink {
|
|
||||||
node = n.tr.newLink(n.Pos, l.Title, l.Href, n.Nodes...)
|
|
||||||
} else {
|
|
||||||
node = n.tr.newImage(n.Pos, l.Title, l.Href, n.Text)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
node = n.tr.newText(n.Pos, n.Raw)
|
|
||||||
}
|
|
||||||
return node.Render()
|
|
||||||
}
|
|
||||||
|
|
||||||
// newRefLink create new RefLink that suitable for link
|
|
||||||
func (p *parse) newRefLink(typ itemType, pos Pos, raw, ref string, text []Node) *RefNode {
|
|
||||||
return &RefNode{NodeType: NodeRefLink, Pos: pos, tr: p.root(), Raw: raw, Ref: ref, Nodes: text}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newRefImage create new RefLink that suitable for image
|
|
||||||
func (p *parse) newRefImage(typ itemType, pos Pos, raw, ref, text string) *RefNode {
|
|
||||||
return &RefNode{NodeType: NodeRefImage, Pos: pos, tr: p.root(), Raw: raw, Ref: ref, Text: text}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefLinkNode refresent single reference to link-definition
|
|
||||||
type DefLinkNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Name, Href, Title string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deflink have no representation(Transparent node)
|
|
||||||
func (n *DefLinkNode) Render() string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newDefLink(pos Pos, name, href, title string) *DefLinkNode {
|
|
||||||
return &DefLinkNode{NodeType: NodeLink, Pos: pos, Name: name, Href: href, Title: title}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ImageNode represents an image element with optional alt and title attributes.
|
|
||||||
type ImageNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Title, Src, Alt string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation on image node
|
|
||||||
func (n *ImageNode) Render() string {
|
|
||||||
attrs := fmt.Sprintf("src=\"%s\" alt=\"%s\"", n.Src, n.Alt)
|
|
||||||
if n.Title != "" {
|
|
||||||
attrs += fmt.Sprintf(" title=\"%s\"", n.Title)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("<img %s>", attrs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newImage(pos Pos, title, src, alt string) *ImageNode {
|
|
||||||
return &ImageNode{NodeType: NodeImage, Pos: pos, Title: p.text(title), Src: p.text(src), Alt: p.text(alt)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListNode holds list items nodes in ordered or unordered states.
|
|
||||||
type ListNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Ordered bool
|
|
||||||
Items []*ListItemNode
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *ListNode) append(item *ListItemNode) {
|
|
||||||
n.Items = append(n.Items, item)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation of orderd(ol) or unordered(ul) list.
|
|
||||||
func (n *ListNode) Render() (s string) {
|
|
||||||
tag := "ul"
|
|
||||||
if n.Ordered {
|
|
||||||
tag = "ol"
|
|
||||||
}
|
|
||||||
for _, item := range n.Items {
|
|
||||||
s += "\n" + item.Render()
|
|
||||||
}
|
|
||||||
s += "\n"
|
|
||||||
return wrap(tag, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newList(pos Pos, ordered bool) *ListNode {
|
|
||||||
return &ListNode{NodeType: NodeList, Pos: pos, Ordered: ordered}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListItem represents single item in ListNode that may contains nested nodes.
|
|
||||||
type ListItemNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Nodes []Node
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ListItemNode) append(n Node) {
|
|
||||||
l.Nodes = append(l.Nodes, n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation of list-item
|
|
||||||
func (l *ListItemNode) Render() (s string) {
|
|
||||||
for _, node := range l.Nodes {
|
|
||||||
s += node.Render()
|
|
||||||
}
|
|
||||||
return wrap("li", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newListItem(pos Pos) *ListItemNode {
|
|
||||||
return &ListItemNode{NodeType: NodeListItem, Pos: pos}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableNode represents table element contains head and body
|
|
||||||
type TableNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Rows []*RowNode
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *TableNode) append(row *RowNode) {
|
|
||||||
n.Rows = append(n.Rows, row)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation of a table
|
|
||||||
func (n *TableNode) Render() string {
|
|
||||||
var s string
|
|
||||||
for i, row := range n.Rows {
|
|
||||||
s += "\n"
|
|
||||||
switch i {
|
|
||||||
case 0:
|
|
||||||
s += wrap("thead", "\n"+row.Render()+"\n")
|
|
||||||
case 1:
|
|
||||||
s += "<tbody>\n"
|
|
||||||
fallthrough
|
|
||||||
default:
|
|
||||||
s += row.Render()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s += "\n</tbody>\n"
|
|
||||||
return wrap("table", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newTable(pos Pos) *TableNode {
|
|
||||||
return &TableNode{NodeType: NodeTable, Pos: pos}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RowNode represnt tr that holds list of cell-nodes
|
|
||||||
type RowNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Cells []*CellNode
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RowNode) append(cell *CellNode) {
|
|
||||||
r.Cells = append(r.Cells, cell)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation of table-row
|
|
||||||
func (r *RowNode) Render() string {
|
|
||||||
var s string
|
|
||||||
for _, cell := range r.Cells {
|
|
||||||
s += "\n" + cell.Render()
|
|
||||||
}
|
|
||||||
s += "\n"
|
|
||||||
return wrap("tr", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newRow(pos Pos) *RowNode {
|
|
||||||
return &RowNode{NodeType: NodeRow, Pos: pos}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AlignType identifies the aligment-type of specfic cell.
|
|
||||||
type AlignType int
|
|
||||||
|
|
||||||
// Align returns itself and provides an easy default implementation
|
|
||||||
// for embedding in a Node.
|
|
||||||
func (t AlignType) Align() AlignType {
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alignment
|
|
||||||
const (
|
|
||||||
None AlignType = iota
|
|
||||||
Right
|
|
||||||
Left
|
|
||||||
Center
|
|
||||||
)
|
|
||||||
|
|
||||||
// Cell types
|
|
||||||
const (
|
|
||||||
Header = iota
|
|
||||||
Data
|
|
||||||
)
|
|
||||||
|
|
||||||
// CellNode represents table-data/cell that holds simple text(may be emphasis)
|
|
||||||
// Note: the text in <th> elements are bold and centered by default.
|
|
||||||
type CellNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
AlignType
|
|
||||||
Kind int
|
|
||||||
Nodes []Node
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html reprenestation of table-cell
|
|
||||||
func (c *CellNode) Render() string {
|
|
||||||
var s string
|
|
||||||
tag := "td"
|
|
||||||
if c.Kind == Header {
|
|
||||||
tag = "th"
|
|
||||||
}
|
|
||||||
for _, node := range c.Nodes {
|
|
||||||
s += node.Render()
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("<%[1]s%s>%s</%[1]s>", tag, c.Style(), s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Style return the cell-style based on alignment field
|
|
||||||
func (c *CellNode) Style() string {
|
|
||||||
s := " style=\"text-align:"
|
|
||||||
switch c.Align() {
|
|
||||||
case Right:
|
|
||||||
s += "right\""
|
|
||||||
case Left:
|
|
||||||
s += "left\""
|
|
||||||
case Center:
|
|
||||||
s += "center\""
|
|
||||||
default:
|
|
||||||
s = ""
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newCell(pos Pos, kind int, align AlignType) *CellNode {
|
|
||||||
return &CellNode{NodeType: NodeCell, Pos: pos, Kind: kind, AlignType: align}
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockQuote represents block-quote tag.
|
|
||||||
type BlockQuoteNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Nodes []Node
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation of BlockQuote
|
|
||||||
func (n *BlockQuoteNode) Render() string {
|
|
||||||
var s string
|
|
||||||
for _, node := range n.Nodes {
|
|
||||||
s += node.Render()
|
|
||||||
}
|
|
||||||
return wrap("blockquote", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newBlockQuote(pos Pos) *BlockQuoteNode {
|
|
||||||
return &BlockQuoteNode{NodeType: NodeBlockQuote, Pos: pos}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CheckboxNode represents checked and unchecked checkbox tag.
|
|
||||||
// Used in task lists.
|
|
||||||
type CheckboxNode struct {
|
|
||||||
NodeType
|
|
||||||
Pos
|
|
||||||
Checked bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render returns the html representation of checked and unchecked CheckBox.
|
|
||||||
func (n *CheckboxNode) Render() string {
|
|
||||||
s := "<input type=\"checkbox\""
|
|
||||||
if n.Checked {
|
|
||||||
s += " checked"
|
|
||||||
}
|
|
||||||
return s + ">"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) newCheckbox(pos Pos, checked bool) *CheckboxNode {
|
|
||||||
return &CheckboxNode{NodeType: NodeCheckbox, Pos: pos, Checked: checked}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wrap text with specific tag.
|
|
||||||
func wrap(tag, body string) string {
|
|
||||||
return fmt.Sprintf("<%[1]s>%s</%[1]s>", tag, body)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Group all text configuration in one place(escaping, smartypants, etc..)
|
|
||||||
func (p *parse) text(input string) string {
|
|
||||||
opts := p.root().options
|
|
||||||
if opts.Smartypants {
|
|
||||||
input = smartypants(input)
|
|
||||||
}
|
|
||||||
if opts.Fractions {
|
|
||||||
input = smartyfractions(input)
|
|
||||||
}
|
|
||||||
return escape(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper escaper
|
|
||||||
func escape(str string) (cpy string) {
|
|
||||||
emp := regexp.MustCompile(`&\w+;`)
|
|
||||||
for i := 0; i < len(str); i++ {
|
|
||||||
switch s := str[i]; s {
|
|
||||||
case '>':
|
|
||||||
cpy += ">"
|
|
||||||
case '"':
|
|
||||||
cpy += """
|
|
||||||
case '\'':
|
|
||||||
cpy += "'"
|
|
||||||
case '<':
|
|
||||||
if res := reHTML.tag.FindString(str[i:]); res != "" {
|
|
||||||
cpy += res
|
|
||||||
i += len(res) - 1
|
|
||||||
} else {
|
|
||||||
cpy += "<"
|
|
||||||
}
|
|
||||||
case '&':
|
|
||||||
if res := emp.FindString(str[i:]); res != "" {
|
|
||||||
cpy += res
|
|
||||||
i += len(res) - 1
|
|
||||||
} else {
|
|
||||||
cpy += "&"
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
cpy += str[i : i+1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Smartypants transformation helper, translate from marked.js
|
|
||||||
func smartypants(text string) string {
|
|
||||||
// em-dashes, en-dashes, ellipses
|
|
||||||
re := strings.NewReplacer("---", "\u2014", "--", "\u2013", "...", "\u2026")
|
|
||||||
text = re.Replace(text)
|
|
||||||
// opening singles
|
|
||||||
text = regexp.MustCompile("(^|[-\u2014/(\\[{\"\\s])'").ReplaceAllString(text, "$1\u2018")
|
|
||||||
// closing singles & apostrophes
|
|
||||||
text = strings.Replace(text, "'", "\u2019", -1)
|
|
||||||
// opening doubles
|
|
||||||
text = regexp.MustCompile("(^|[-\u2014/(\\[{\u2018\\s])\"").ReplaceAllString(text, "$1\u201c")
|
|
||||||
// closing doubles
|
|
||||||
text = strings.Replace(text, "\"", "\u201d", -1)
|
|
||||||
return text
|
|
||||||
}
|
|
||||||
|
|
||||||
// Smartyfractions transformation helper.
|
|
||||||
func smartyfractions(text string) string {
|
|
||||||
re := regexp.MustCompile(`(\d+)(/\d+)(/\d+|)`)
|
|
||||||
return re.ReplaceAllStringFunc(text, func(str string) string {
|
|
||||||
var match []string
|
|
||||||
// If it's date like
|
|
||||||
if match = re.FindStringSubmatch(str); match[3] != "" {
|
|
||||||
return str
|
|
||||||
}
|
|
||||||
switch n := match[1] + match[2]; n {
|
|
||||||
case "1/2", "1/3", "2/3", "1/4", "3/4", "1/5", "2/5", "3/5", "4/5",
|
|
||||||
"1/6", "5/6", "1/7", "1/8", "3/8", "5/8", "7/8":
|
|
||||||
return fmt.Sprintf("&frac%s;", strings.Replace(n, "/", "", 1))
|
|
||||||
default:
|
|
||||||
return fmt.Sprintf("<sup>%s</sup>⁄<sub>%s</sub>",
|
|
||||||
match[1], strings.Replace(match[2], "/", "", 1))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
436
vendor/github.com/a8m/mark/parser.go
generated
vendored
436
vendor/github.com/a8m/mark/parser.go
generated
vendored
@ -1,436 +0,0 @@
|
|||||||
package mark
|
|
||||||
|
|
||||||
import (
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"unicode"
|
|
||||||
"unicode/utf8"
|
|
||||||
)
|
|
||||||
|
|
||||||
// parse holds the state of the parser.
|
|
||||||
type parse struct {
|
|
||||||
Nodes []Node
|
|
||||||
lex Lexer
|
|
||||||
options *Options
|
|
||||||
tr *parse
|
|
||||||
output string
|
|
||||||
peekCount int
|
|
||||||
token [3]item // three-token lookahead for parser
|
|
||||||
links map[string]*DefLinkNode // Deflink parsing, used RefLinks
|
|
||||||
renderFn map[NodeType]RenderFn // Custom overridden fns
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return new parser
|
|
||||||
func newParse(input string, opts *Options) *parse {
|
|
||||||
return &parse{
|
|
||||||
lex: lex(input),
|
|
||||||
options: opts,
|
|
||||||
links: make(map[string]*DefLinkNode),
|
|
||||||
renderFn: make(map[NodeType]RenderFn),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse convert the raw text to Nodeparse.
|
|
||||||
func (p *parse) parse() {
|
|
||||||
Loop:
|
|
||||||
for {
|
|
||||||
var n Node
|
|
||||||
switch t := p.peek(); t.typ {
|
|
||||||
case itemEOF, itemError:
|
|
||||||
break Loop
|
|
||||||
case itemNewLine:
|
|
||||||
p.next()
|
|
||||||
case itemHr:
|
|
||||||
n = p.newHr(p.next().pos)
|
|
||||||
case itemHTML:
|
|
||||||
t = p.next()
|
|
||||||
n = p.newHTML(t.pos, t.val)
|
|
||||||
case itemDefLink:
|
|
||||||
n = p.parseDefLink()
|
|
||||||
case itemHeading, itemLHeading:
|
|
||||||
n = p.parseHeading()
|
|
||||||
case itemCodeBlock, itemGfmCodeBlock:
|
|
||||||
n = p.parseCodeBlock()
|
|
||||||
case itemList:
|
|
||||||
n = p.parseList()
|
|
||||||
case itemTable, itemLpTable:
|
|
||||||
n = p.parseTable()
|
|
||||||
case itemBlockQuote:
|
|
||||||
n = p.parseBlockQuote()
|
|
||||||
case itemIndent:
|
|
||||||
space := p.next()
|
|
||||||
// If it isn't followed by itemText
|
|
||||||
if p.peek().typ != itemText {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
p.backup2(space)
|
|
||||||
fallthrough
|
|
||||||
// itemText
|
|
||||||
default:
|
|
||||||
tmp := p.newParagraph(t.pos)
|
|
||||||
tmp.Nodes = p.parseText(p.next().val + p.scanLines())
|
|
||||||
n = tmp
|
|
||||||
}
|
|
||||||
if n != nil {
|
|
||||||
p.append(n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Root getter
|
|
||||||
func (p *parse) root() *parse {
|
|
||||||
if p.tr == nil {
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
return p.tr.root()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render parse nodes to the wanted output
|
|
||||||
func (p *parse) render() {
|
|
||||||
var output string
|
|
||||||
for i, node := range p.Nodes {
|
|
||||||
// If there's a custom render function, use it instead.
|
|
||||||
if fn, ok := p.renderFn[node.Type()]; ok {
|
|
||||||
output = fn(node)
|
|
||||||
} else {
|
|
||||||
output = node.Render()
|
|
||||||
}
|
|
||||||
p.output += output
|
|
||||||
if output != "" && i != len(p.Nodes)-1 {
|
|
||||||
p.output += "\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// append new node to nodes-list
|
|
||||||
func (p *parse) append(n Node) {
|
|
||||||
p.Nodes = append(p.Nodes, n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// next returns the next token
|
|
||||||
func (p *parse) next() item {
|
|
||||||
if p.peekCount > 0 {
|
|
||||||
p.peekCount--
|
|
||||||
} else {
|
|
||||||
p.token[0] = p.lex.nextItem()
|
|
||||||
}
|
|
||||||
return p.token[p.peekCount]
|
|
||||||
}
|
|
||||||
|
|
||||||
// peek returns but does not consume the next token.
|
|
||||||
func (p *parse) peek() item {
|
|
||||||
if p.peekCount > 0 {
|
|
||||||
return p.token[p.peekCount-1]
|
|
||||||
}
|
|
||||||
p.peekCount = 1
|
|
||||||
p.token[0] = p.lex.nextItem()
|
|
||||||
return p.token[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
// backup backs the input stream tp one token
|
|
||||||
func (p *parse) backup() {
|
|
||||||
p.peekCount++
|
|
||||||
}
|
|
||||||
|
|
||||||
// backup2 backs the input stream up two tokens.
|
|
||||||
// The zeroth token is already there.
|
|
||||||
func (p *parse) backup2(t1 item) {
|
|
||||||
p.token[1] = t1
|
|
||||||
p.peekCount = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseText
|
|
||||||
func (p *parse) parseText(input string) (nodes []Node) {
|
|
||||||
// Trim whitespaces that not a line-break
|
|
||||||
input = regexp.MustCompile(`(?m)^ +| +(\n|$)`).ReplaceAllStringFunc(input, func(s string) string {
|
|
||||||
if reBr.MatchString(s) {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return strings.Replace(s, " ", "", -1)
|
|
||||||
})
|
|
||||||
l := lexInline(input)
|
|
||||||
for token := range l.items {
|
|
||||||
var node Node
|
|
||||||
switch token.typ {
|
|
||||||
case itemBr:
|
|
||||||
node = p.newBr(token.pos)
|
|
||||||
case itemStrong, itemItalic, itemStrike, itemCode:
|
|
||||||
node = p.parseEmphasis(token.typ, token.pos, token.val)
|
|
||||||
case itemLink, itemAutoLink, itemGfmLink:
|
|
||||||
var title, href string
|
|
||||||
var text []Node
|
|
||||||
if token.typ == itemLink {
|
|
||||||
match := reLink.FindStringSubmatch(token.val)
|
|
||||||
text = p.parseText(match[1])
|
|
||||||
href, title = match[2], match[3]
|
|
||||||
} else {
|
|
||||||
var match []string
|
|
||||||
if token.typ == itemGfmLink {
|
|
||||||
match = reGfmLink.FindStringSubmatch(token.val)
|
|
||||||
} else {
|
|
||||||
match = reAutoLink.FindStringSubmatch(token.val)
|
|
||||||
}
|
|
||||||
href = match[1]
|
|
||||||
text = append(text, p.newText(token.pos, match[1]))
|
|
||||||
}
|
|
||||||
node = p.newLink(token.pos, title, href, text...)
|
|
||||||
case itemImage:
|
|
||||||
match := reImage.FindStringSubmatch(token.val)
|
|
||||||
node = p.newImage(token.pos, match[3], match[2], match[1])
|
|
||||||
case itemRefLink, itemRefImage:
|
|
||||||
match := reRefLink.FindStringSubmatch(token.val)
|
|
||||||
text, ref := match[1], match[2]
|
|
||||||
if ref == "" {
|
|
||||||
ref = text
|
|
||||||
}
|
|
||||||
if token.typ == itemRefLink {
|
|
||||||
node = p.newRefLink(token.typ, token.pos, token.val, ref, p.parseText(text))
|
|
||||||
} else {
|
|
||||||
node = p.newRefImage(token.typ, token.pos, token.val, ref, text)
|
|
||||||
}
|
|
||||||
case itemHTML:
|
|
||||||
node = p.newHTML(token.pos, token.val)
|
|
||||||
default:
|
|
||||||
node = p.newText(token.pos, token.val)
|
|
||||||
}
|
|
||||||
nodes = append(nodes, node)
|
|
||||||
}
|
|
||||||
return nodes
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse inline emphasis
|
|
||||||
func (p *parse) parseEmphasis(typ itemType, pos Pos, val string) *EmphasisNode {
|
|
||||||
var re *regexp.Regexp
|
|
||||||
switch typ {
|
|
||||||
case itemStrike:
|
|
||||||
re = reStrike
|
|
||||||
case itemStrong:
|
|
||||||
re = reStrong
|
|
||||||
case itemCode:
|
|
||||||
re = reCode
|
|
||||||
case itemItalic:
|
|
||||||
re = reItalic
|
|
||||||
}
|
|
||||||
node := p.newEmphasis(pos, typ)
|
|
||||||
match := re.FindStringSubmatch(val)
|
|
||||||
text := match[len(match)-1]
|
|
||||||
if text == "" {
|
|
||||||
text = match[1]
|
|
||||||
}
|
|
||||||
node.Nodes = p.parseText(text)
|
|
||||||
return node
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse heading block
|
|
||||||
func (p *parse) parseHeading() (node *HeadingNode) {
|
|
||||||
token := p.next()
|
|
||||||
level := 1
|
|
||||||
var text string
|
|
||||||
if token.typ == itemHeading {
|
|
||||||
match := reHeading.FindStringSubmatch(token.val)
|
|
||||||
level, text = len(match[1]), match[2]
|
|
||||||
} else {
|
|
||||||
match := reLHeading.FindStringSubmatch(token.val)
|
|
||||||
// using equal signs for first-level, and dashes for second-level.
|
|
||||||
text = match[1]
|
|
||||||
if match[2] == "-" {
|
|
||||||
level = 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node = p.newHeading(token.pos, level, text)
|
|
||||||
node.Nodes = p.parseText(text)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) parseDefLink() *DefLinkNode {
|
|
||||||
token := p.next()
|
|
||||||
match := reDefLink.FindStringSubmatch(token.val)
|
|
||||||
name := strings.ToLower(match[1])
|
|
||||||
// name(lowercase), href, title
|
|
||||||
n := p.newDefLink(token.pos, name, match[2], match[3])
|
|
||||||
// store in links
|
|
||||||
links := p.root().links
|
|
||||||
if _, ok := links[name]; !ok {
|
|
||||||
links[name] = n
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse codeBlock
|
|
||||||
func (p *parse) parseCodeBlock() *CodeNode {
|
|
||||||
var lang, text string
|
|
||||||
token := p.next()
|
|
||||||
if token.typ == itemGfmCodeBlock {
|
|
||||||
codeStart := reGfmCode.FindStringSubmatch(token.val)
|
|
||||||
lang = codeStart[3]
|
|
||||||
text = token.val[len(codeStart[0]):]
|
|
||||||
} else {
|
|
||||||
text = reCodeBlock.trim(token.val, "")
|
|
||||||
}
|
|
||||||
return p.newCode(token.pos, lang, text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parse) parseBlockQuote() (n *BlockQuoteNode) {
|
|
||||||
token := p.next()
|
|
||||||
// replacer
|
|
||||||
re := regexp.MustCompile(`(?m)^ *> ?`)
|
|
||||||
raw := re.ReplaceAllString(token.val, "")
|
|
||||||
// TODO(a8m): doesn't work right now with defLink(inside the blockQuote)
|
|
||||||
tr := &parse{lex: lex(raw), tr: p}
|
|
||||||
tr.parse()
|
|
||||||
n = p.newBlockQuote(token.pos)
|
|
||||||
n.Nodes = tr.Nodes
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse list
|
|
||||||
func (p *parse) parseList() *ListNode {
|
|
||||||
token := p.next()
|
|
||||||
list := p.newList(token.pos, isDigit(token.val))
|
|
||||||
Loop:
|
|
||||||
for {
|
|
||||||
switch token = p.peek(); token.typ {
|
|
||||||
case itemLooseItem, itemListItem:
|
|
||||||
list.append(p.parseListItem())
|
|
||||||
default:
|
|
||||||
break Loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse listItem
|
|
||||||
func (p *parse) parseListItem() *ListItemNode {
|
|
||||||
token := p.next()
|
|
||||||
item := p.newListItem(token.pos)
|
|
||||||
token.val = strings.TrimSpace(token.val)
|
|
||||||
if p.isTaskItem(token.val) {
|
|
||||||
item.Nodes = p.parseTaskItem(token)
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
tr := &parse{lex: lex(token.val), tr: p}
|
|
||||||
tr.parse()
|
|
||||||
for _, node := range tr.Nodes {
|
|
||||||
// wrap with paragraph only when it's a loose item
|
|
||||||
if n, ok := node.(*ParagraphNode); ok && token.typ == itemListItem {
|
|
||||||
item.Nodes = append(item.Nodes, n.Nodes...)
|
|
||||||
} else {
|
|
||||||
item.append(node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseTaskItem parses list item as a task item.
|
|
||||||
func (p *parse) parseTaskItem(token item) []Node {
|
|
||||||
checkbox := p.newCheckbox(token.pos, token.val[1] == 'x')
|
|
||||||
token.val = strings.TrimSpace(token.val[3:])
|
|
||||||
return append([]Node{checkbox}, p.parseText(token.val)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// isTaskItem tests if the given string is list task item.
|
|
||||||
func (p *parse) isTaskItem(s string) bool {
|
|
||||||
if len(s) < 5 || s[0] != '[' || (s[1] != 'x' && s[1] != ' ') || s[2] != ']' {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return "" != strings.TrimSpace(s[3:])
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse table
|
|
||||||
func (p *parse) parseTable() *TableNode {
|
|
||||||
table := p.newTable(p.next().pos)
|
|
||||||
// Align [ None, Left, Right, ... ]
|
|
||||||
// Header [ Cells: [ ... ] ]
|
|
||||||
// Data: [ Rows: [ Cells: [ ... ] ] ]
|
|
||||||
rows := struct {
|
|
||||||
Align []AlignType
|
|
||||||
Header []item
|
|
||||||
Cells [][]item
|
|
||||||
}{}
|
|
||||||
Loop:
|
|
||||||
for i := 0; ; {
|
|
||||||
switch token := p.next(); token.typ {
|
|
||||||
case itemTableRow:
|
|
||||||
i++
|
|
||||||
if i > 2 {
|
|
||||||
rows.Cells = append(rows.Cells, []item{})
|
|
||||||
}
|
|
||||||
case itemTableCell:
|
|
||||||
// Header
|
|
||||||
if i == 1 {
|
|
||||||
rows.Header = append(rows.Header, token)
|
|
||||||
// Alignment
|
|
||||||
} else if i == 2 {
|
|
||||||
rows.Align = append(rows.Align, parseAlign(token.val))
|
|
||||||
// Data
|
|
||||||
} else {
|
|
||||||
pos := i - 3
|
|
||||||
rows.Cells[pos] = append(rows.Cells[pos], token)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
p.backup()
|
|
||||||
break Loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Tranform to nodes
|
|
||||||
table.append(p.parseCells(Header, rows.Header, rows.Align))
|
|
||||||
// Table body
|
|
||||||
for _, row := range rows.Cells {
|
|
||||||
table.append(p.parseCells(Data, row, rows.Align))
|
|
||||||
}
|
|
||||||
return table
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse cells and return new row
|
|
||||||
func (p *parse) parseCells(kind int, items []item, align []AlignType) *RowNode {
|
|
||||||
var row *RowNode
|
|
||||||
for i, item := range items {
|
|
||||||
if i == 0 {
|
|
||||||
row = p.newRow(item.pos)
|
|
||||||
}
|
|
||||||
cell := p.newCell(item.pos, kind, align[i])
|
|
||||||
cell.Nodes = p.parseText(item.val)
|
|
||||||
row.append(cell)
|
|
||||||
}
|
|
||||||
return row
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used to consume lines(itemText) for a continues paragraphs
|
|
||||||
func (p *parse) scanLines() (s string) {
|
|
||||||
for {
|
|
||||||
tkn := p.next()
|
|
||||||
if tkn.typ == itemText || tkn.typ == itemIndent {
|
|
||||||
s += tkn.val
|
|
||||||
} else if tkn.typ == itemNewLine {
|
|
||||||
if t := p.peek().typ; t != itemText && t != itemIndent {
|
|
||||||
p.backup2(tkn)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
s += tkn.val
|
|
||||||
} else {
|
|
||||||
p.backup()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// get align-string and return the align type of it
|
|
||||||
func parseAlign(s string) (typ AlignType) {
|
|
||||||
sfx, pfx := strings.HasSuffix(s, ":"), strings.HasPrefix(s, ":")
|
|
||||||
switch {
|
|
||||||
case sfx && pfx:
|
|
||||||
typ = Center
|
|
||||||
case sfx:
|
|
||||||
typ = Right
|
|
||||||
case pfx:
|
|
||||||
typ = Left
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// test if given string is digit
|
|
||||||
func isDigit(s string) bool {
|
|
||||||
r, _ := utf8.DecodeRuneInString(s)
|
|
||||||
return unicode.IsDigit(r)
|
|
||||||
}
|
|
2388
vendor/github.com/beorn7/perks/quantile/exampledata.txt
generated
vendored
Normal file
2388
vendor/github.com/beorn7/perks/quantile/exampledata.txt
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
vendor/github.com/bkaradzic/go-lz4/.gitignore
generated
vendored
Normal file
1
vendor/github.com/bkaradzic/go-lz4/.gitignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/lz4-example/lz4-example
|
9
vendor/github.com/bkaradzic/go-lz4/.travis.yml
generated
vendored
Normal file
9
vendor/github.com/bkaradzic/go-lz4/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
language: go
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1.1
|
||||||
|
- 1.2
|
||||||
|
- 1.3
|
||||||
|
- 1.4
|
||||||
|
- 1.5
|
||||||
|
- tip
|
76
vendor/github.com/bkaradzic/go-lz4/README.md
generated
vendored
Normal file
76
vendor/github.com/bkaradzic/go-lz4/README.md
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
go-lz4
|
||||||
|
======
|
||||||
|
|
||||||
|
go-lz4 is port of LZ4 lossless compression algorithm to Go. The original C code
|
||||||
|
is located at:
|
||||||
|
|
||||||
|
https://github.com/Cyan4973/lz4
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
[![Build Status](https://secure.travis-ci.org/bkaradzic/go-lz4.png)](http://travis-ci.org/bkaradzic/go-lz4)
|
||||||
|
[![GoDoc](https://godoc.org/github.com/bkaradzic/go-lz4?status.png)](https://godoc.org/github.com/bkaradzic/go-lz4)
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
go get github.com/bkaradzic/go-lz4
|
||||||
|
|
||||||
|
import "github.com/bkaradzic/go-lz4"
|
||||||
|
|
||||||
|
The package name is `lz4`
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
* go-lz4 saves a uint32 with the original uncompressed length at the beginning
|
||||||
|
of the encoded buffer. They may get in the way of interoperability with
|
||||||
|
other implementations.
|
||||||
|
|
||||||
|
Alternative
|
||||||
|
-----------
|
||||||
|
|
||||||
|
https://github.com/pierrec/lz4
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
Damian Gryski ([@dgryski](https://github.com/dgryski))
|
||||||
|
Dustin Sallings ([@dustin](https://github.com/dustin))
|
||||||
|
|
||||||
|
Contact
|
||||||
|
-------
|
||||||
|
|
||||||
|
[@bkaradzic](https://twitter.com/bkaradzic)
|
||||||
|
http://www.stuckingeometry.com
|
||||||
|
|
||||||
|
Project page
|
||||||
|
https://github.com/bkaradzic/go-lz4
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
Copyright 2011-2012 Branimir Karadzic. All rights reserved.
|
||||||
|
Copyright 2013 Damian Gryski. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||||
|
SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||||
|
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
|
THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
74
vendor/github.com/bkaradzic/go-lz4/fuzzer/main.go
generated
vendored
74
vendor/github.com/bkaradzic/go-lz4/fuzzer/main.go
generated
vendored
@ -1,74 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/bkaradzic/go-lz4"
|
|
||||||
|
|
||||||
// lz4's API matches snappy's, so we can easily see how it performs
|
|
||||||
// lz4 "code.google.com/p/snappy-go/snappy"
|
|
||||||
)
|
|
||||||
|
|
||||||
var input = `
|
|
||||||
ADVENTURE I. A SCANDAL IN BOHEMIA
|
|
||||||
|
|
||||||
I.
|
|
||||||
|
|
||||||
To Sherlock Holmes she is always THE woman. I have seldom heard
|
|
||||||
him mention her under any other name. In his eyes she eclipses
|
|
||||||
and predominates the whole of her sex. It was not that he felt
|
|
||||||
any emotion akin to love for Irene Adler. All emotions, and that
|
|
||||||
one particularly, were abhorrent to his cold, precise but
|
|
||||||
admirably balanced mind. He was, I take it, the most perfect
|
|
||||||
reasoning and observing machine that the world has seen, but as a
|
|
||||||
lover he would have placed himself in a false position. He never
|
|
||||||
spoke of the softer passions, save with a gibe and a sneer. They
|
|
||||||
were admirable things for the observer--excellent for drawing the
|
|
||||||
veil from men's motives and actions. But for the trained reasoner
|
|
||||||
to admit such intrusions into his own delicate and finely
|
|
||||||
adjusted temperament was to introduce a distracting factor which
|
|
||||||
might throw a doubt upon all his mental results. Grit in a
|
|
||||||
sensitive instrument, or a crack in one of his own high-power
|
|
||||||
lenses, would not be more disturbing than a strong emotion in a
|
|
||||||
nature such as his. And yet there was but one woman to him, and
|
|
||||||
that woman was the late Irene Adler, of dubious and questionable
|
|
||||||
memory.
|
|
||||||
|
|
||||||
I had seen little of Holmes lately. My marriage had drifted us
|
|
||||||
away from each other. My own complete happiness, and the
|
|
||||||
home-centred interests which rise up around the man who first
|
|
||||||
finds himself master of his own establishment, were sufficient to
|
|
||||||
absorb all my attention, while Holmes, who loathed every form of
|
|
||||||
society with his whole Bohemian soul, remained in our lodgings in
|
|
||||||
Baker Street, buried among his old books, and alternating from
|
|
||||||
week to week between cocaine and ambition, the drowsiness of the
|
|
||||||
drug, and the fierce energy of his own keen nature. He was still,
|
|
||||||
as ever, deeply attracted by the study of crime, and occupied his
|
|
||||||
immense faculties and extraordinary powers of observation in
|
|
||||||
following out those clues, and clearing up those mysteries which
|
|
||||||
had been abandoned as hopeless by the official police. From time
|
|
||||||
to time I heard some vague account of his doings: of his summons
|
|
||||||
to Odessa in the case of the Trepoff murder, of his clearing up
|
|
||||||
of the singular tragedy of the Atkinson brothers at Trincomalee,
|
|
||||||
and finally of the mission which he had accomplished so
|
|
||||||
delicately and successfully for the reigning family of Holland.
|
|
||||||
Beyond these signs of his activity, however, which I merely
|
|
||||||
shared with all the readers of the daily press, I knew little of
|
|
||||||
my former friend and companion.
|
|
||||||
`
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
compressed, _ := lz4.Encode(nil, []byte(input))
|
|
||||||
|
|
||||||
modified := make([]byte, len(compressed))
|
|
||||||
|
|
||||||
for {
|
|
||||||
copy(modified, compressed)
|
|
||||||
for i := 0; i < 100; i++ {
|
|
||||||
modified[rand.Intn(len(compressed)-4)+4] = byte(rand.Intn(256))
|
|
||||||
}
|
|
||||||
lz4.Decode(nil, modified)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
94
vendor/github.com/bkaradzic/go-lz4/lz4-example/main.go
generated
vendored
94
vendor/github.com/bkaradzic/go-lz4/lz4-example/main.go
generated
vendored
@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 Branimir Karadzic. All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
* are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
||||||
* SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
||||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
||||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
||||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"runtime/pprof"
|
|
||||||
|
|
||||||
lz4 "github.com/bkaradzic/go-lz4"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
decompress = flag.Bool("d", false, "decompress")
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
var optCPUProfile = flag.String("cpuprofile", "", "profile")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if *optCPUProfile != "" {
|
|
||||||
f, err := os.Create(*optCPUProfile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
pprof.StartCPUProfile(f)
|
|
||||||
defer pprof.StopCPUProfile()
|
|
||||||
}
|
|
||||||
|
|
||||||
args := flag.Args()
|
|
||||||
|
|
||||||
var data []byte
|
|
||||||
|
|
||||||
if len(args) < 2 {
|
|
||||||
fmt.Print("Usage: lz4 [-d] <input> <output>\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
input, err := os.OpenFile(args[0], os.O_RDONLY, 0644)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to open input file %s\n", args[0])
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
defer input.Close()
|
|
||||||
|
|
||||||
if *decompress {
|
|
||||||
data, _ = ioutil.ReadAll(input)
|
|
||||||
data, err = lz4.Decode(nil, data)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to decode:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
data, _ = ioutil.ReadAll(input)
|
|
||||||
data, err = lz4.Encode(nil, data)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to encode:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ioutil.WriteFile(args[1], data, 0644)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Failed to open output file %s\n", args[1])
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
14
vendor/github.com/calmh/du/README.md
generated
vendored
Normal file
14
vendor/github.com/calmh/du/README.md
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
du
|
||||||
|
==
|
||||||
|
|
||||||
|
Get total and available disk space on a given volume.
|
||||||
|
|
||||||
|
Documentation
|
||||||
|
-------------
|
||||||
|
|
||||||
|
http://godoc.org/github.com/calmh/du
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
Public Domain
|
21
vendor/github.com/calmh/du/cmd/du/main.go
generated
vendored
21
vendor/github.com/calmh/du/cmd/du/main.go
generated
vendored
@ -1,21 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/calmh/du"
|
|
||||||
)
|
|
||||||
|
|
||||||
var KB = int64(1024)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
usage, err := du.Get(os.Args[1])
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fmt.Println("Free:", usage.FreeBytes/(KB*KB), "MiB")
|
|
||||||
fmt.Println("Available:", usage.AvailBytes/(KB*KB), "MiB")
|
|
||||||
fmt.Println("Size:", usage.TotalBytes/(KB*KB), "MiB")
|
|
||||||
}
|
|
1
vendor/github.com/calmh/xdr/.gitignore
generated
vendored
Normal file
1
vendor/github.com/calmh/xdr/.gitignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
coverage.out
|
19
vendor/github.com/calmh/xdr/.travis.yml
generated
vendored
Normal file
19
vendor/github.com/calmh/xdr/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
language: go
|
||||||
|
go:
|
||||||
|
- tip
|
||||||
|
|
||||||
|
install:
|
||||||
|
- export PATH=$PATH:$HOME/gopath/bin
|
||||||
|
- go get golang.org/x/tools/cover
|
||||||
|
- go get github.com/mattn/goveralls
|
||||||
|
|
||||||
|
script:
|
||||||
|
- ./generate.sh
|
||||||
|
- go test -coverprofile=coverage.out
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- goveralls -coverprofile=coverage.out -service=travis-ci -package=calmh/xdr -repotoken="$COVERALLS_TOKEN"
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
secure: SmgnrGfp2zLrA44ChRMpjPeujubt9veZ8Fx/OseMWECmacyV5N/TuDhzIbwo6QwV4xB0sBacoPzvxQbJRVjNKsPiSu72UbcQmQ7flN4Tf7nW09tSh1iW8NgrpBCq/3UYLoBu2iPBEBKm93IK0aGNAKs6oEkB0fU27iTVBwiTXOY=
|
18
vendor/github.com/calmh/xdr/README.md
generated
vendored
Normal file
18
vendor/github.com/calmh/xdr/README.md
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# This project is not actively maintained
|
||||||
|
|
||||||
|
Issues and pull requests on this repository may not be acted on in a timely
|
||||||
|
manner, or at all. You are of course welcome to use it anyway. You are even
|
||||||
|
more welcome to fork it and maintain the results.
|
||||||
|
|
||||||
|
![Unmaintained](https://nym.se/img/unmaintained.jpg)
|
||||||
|
|
||||||
|
xdr
|
||||||
|
===
|
||||||
|
|
||||||
|
[![Build Status](https://img.shields.io/circleci/project/calmh/xdr.svg?style=flat-square)](https://circleci.com/gh/calmh/xdr)
|
||||||
|
[![Coverage Status](https://img.shields.io/coveralls/calmh/xdr.svg?style=flat)](https://coveralls.io/r/calmh/xdr?branch=master)
|
||||||
|
[![API Documentation](http://img.shields.io/badge/api-Godoc-blue.svg?style=flat)](http://godoc.org/github.com/calmh/xdr)
|
||||||
|
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
This is an XDR marshalling/unmarshalling library. It uses code generation and
|
||||||
|
not reflection.
|
3
vendor/github.com/calmh/xdr/circle.yml
generated
vendored
Normal file
3
vendor/github.com/calmh/xdr/circle.yml
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
post:
|
||||||
|
- ./generate.sh
|
586
vendor/github.com/calmh/xdr/cmd/genxdr/main.go
generated
vendored
586
vendor/github.com/calmh/xdr/cmd/genxdr/main.go
generated
vendored
@ -1,586 +0,0 @@
|
|||||||
// Copyright (C) 2014 Jakob Borg. All rights reserved. Use of this source code
|
|
||||||
// is governed by an MIT-style license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"go/ast"
|
|
||||||
"go/format"
|
|
||||||
"go/parser"
|
|
||||||
"go/token"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
)
|
|
||||||
|
|
||||||
type fieldInfo struct {
|
|
||||||
Name string
|
|
||||||
IsBasic bool // handled by one the native Read/WriteUint64 etc functions
|
|
||||||
IsSlice bool // field is a slice of FieldType
|
|
||||||
FieldType string // original type of field, i.e. "int"
|
|
||||||
Encoder string // the encoder name, i.e. "Uint64" for Read/WriteUint64
|
|
||||||
Convert string // what to convert to when encoding, i.e. "uint64"
|
|
||||||
Max int // max size for slices and strings
|
|
||||||
Submax int // max size for strings inside slices
|
|
||||||
}
|
|
||||||
|
|
||||||
type structInfo struct {
|
|
||||||
Name string
|
|
||||||
Fields []fieldInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i structInfo) SizeExpr() string {
|
|
||||||
var xdrSizes = map[string]int{
|
|
||||||
"int8": 4,
|
|
||||||
"uint8": 4,
|
|
||||||
"int16": 4,
|
|
||||||
"uint16": 4,
|
|
||||||
"int32": 4,
|
|
||||||
"uint32": 4,
|
|
||||||
"int64": 8,
|
|
||||||
"uint64": 8,
|
|
||||||
"int": 8,
|
|
||||||
"bool": 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
var terms []string
|
|
||||||
nl := ""
|
|
||||||
for _, f := range i.Fields {
|
|
||||||
if size := xdrSizes[f.FieldType]; size > 0 {
|
|
||||||
if f.IsSlice {
|
|
||||||
terms = append(terms, nl+"4+len(o."+f.Name+")*"+strconv.Itoa(size))
|
|
||||||
} else {
|
|
||||||
terms = append(terms, strconv.Itoa(size))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch f.FieldType {
|
|
||||||
case "string", "[]byte":
|
|
||||||
if f.IsSlice {
|
|
||||||
terms = append(terms, nl+"4+xdr.SizeOfSlice(o."+f.Name+")")
|
|
||||||
} else {
|
|
||||||
terms = append(terms, nl+"4+len(o."+f.Name+")+xdr.Padding(len(o."+f.Name+"))")
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
if f.IsSlice {
|
|
||||||
terms = append(terms, nl+"4+xdr.SizeOfSlice(o."+f.Name+")")
|
|
||||||
} else {
|
|
||||||
terms = append(terms, nl+"o."+f.Name+".XDRSize()")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nl = "\n"
|
|
||||||
}
|
|
||||||
return strings.Join(terms, "+")
|
|
||||||
}
|
|
||||||
|
|
||||||
var headerData = `// ************************************************************
|
|
||||||
// This file is automatically generated by genxdr. Do not edit.
|
|
||||||
// ************************************************************
|
|
||||||
|
|
||||||
package {{.Package}}
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/calmh/xdr"
|
|
||||||
)
|
|
||||||
`
|
|
||||||
|
|
||||||
var encoderData = `
|
|
||||||
func (o {{.Name}}) XDRSize() int {
|
|
||||||
return {{.SizeExpr}}
|
|
||||||
}//+n
|
|
||||||
|
|
||||||
func (o {{.Name}}) MarshalXDR() ([]byte, error) {
|
|
||||||
buf:= make([]byte, o.XDRSize())
|
|
||||||
m := &xdr.Marshaller{Data: buf}
|
|
||||||
return buf, o.MarshalXDRInto(m)
|
|
||||||
}//+n
|
|
||||||
|
|
||||||
func (o {{.Name}}) MustMarshalXDR() []byte {
|
|
||||||
bs, err := o.MarshalXDR()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return bs
|
|
||||||
}//+n
|
|
||||||
|
|
||||||
func (o {{.Name}}) MarshalXDRInto(m *xdr.Marshaller) error {
|
|
||||||
{{range $fi := .Fields}}
|
|
||||||
{{if $fi.IsSlice}}
|
|
||||||
{{template "marshalSlice" $fi}}
|
|
||||||
{{else}}
|
|
||||||
{{template "marshalValue" $fi}}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
return m.Error
|
|
||||||
}//+n
|
|
||||||
|
|
||||||
{{define "marshalValue"}}
|
|
||||||
{{if ne .Convert ""}}
|
|
||||||
m.Marshal{{.Encoder}}({{.Convert}}(o.{{.Name}}))
|
|
||||||
{{else if .IsBasic}}
|
|
||||||
{{if ge .Max 1}}
|
|
||||||
if l := len(o.{{.Name}}); l > {{.Max}} {
|
|
||||||
return xdr.ElementSizeExceeded("{{.Name}}", l, {{.Max}})
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
m.Marshal{{.Encoder}}(o.{{.Name}})
|
|
||||||
{{else}}
|
|
||||||
if err := o.{{.Name}}.MarshalXDRInto(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "marshalSlice"}}
|
|
||||||
{{if ge .Max 1}}
|
|
||||||
if l := len(o.{{.Name}}); l > {{.Max}} {
|
|
||||||
return xdr.ElementSizeExceeded("{{.Name}}", l, {{.Max}})
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
m.MarshalUint32(uint32(len(o.{{.Name}})))
|
|
||||||
for i := range o.{{.Name}} {
|
|
||||||
{{if ne .Convert ""}}
|
|
||||||
m.Marshal{{.Encoder}}({{.Convert}}(o.{{.Name}}[i]))
|
|
||||||
{{else if .IsBasic}}
|
|
||||||
m.Marshal{{.Encoder}}(o.{{.Name}}[i])
|
|
||||||
{{else}}
|
|
||||||
if err := o.{{.Name}}[i].MarshalXDRInto(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
func (o *{{.Name}}) UnmarshalXDR(bs []byte) error {
|
|
||||||
u := &xdr.Unmarshaller{Data: bs}
|
|
||||||
return o.UnmarshalXDRFrom(u)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *{{.Name}}) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
|
||||||
{{range $fi := .Fields}}
|
|
||||||
{{if $fi.IsSlice}}
|
|
||||||
{{template "unmarshalSlice" $fi}}
|
|
||||||
{{else}}
|
|
||||||
{{template "unmarshalValue" $fi}}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
return u.Error
|
|
||||||
}//+n
|
|
||||||
|
|
||||||
{{define "unmarshalValue"}}
|
|
||||||
{{if ne .Convert ""}}
|
|
||||||
o.{{.Name}} = {{.FieldType}}(u.Unmarshal{{.Encoder}}())
|
|
||||||
{{else if .IsBasic}}
|
|
||||||
{{if ge .Max 1}}
|
|
||||||
o.{{.Name}} = u.Unmarshal{{.Encoder}}Max({{.Max}})
|
|
||||||
{{else}}
|
|
||||||
o.{{.Name}} = u.Unmarshal{{.Encoder}}()
|
|
||||||
{{end}}
|
|
||||||
{{else}}
|
|
||||||
(&o.{{.Name}}).UnmarshalXDRFrom(u)
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "unmarshalSlice"}}
|
|
||||||
_{{.Name}}Size := int(u.UnmarshalUint32())
|
|
||||||
if _{{.Name}}Size < 0 {
|
|
||||||
return xdr.ElementSizeExceeded("{{.Name}}", _{{.Name}}Size, {{.Max}})
|
|
||||||
} else if _{{.Name}}Size == 0 {
|
|
||||||
o.{{.Name}} = nil
|
|
||||||
} else {
|
|
||||||
{{if ge .Max 1}}
|
|
||||||
if _{{.Name}}Size > {{.Max}} {
|
|
||||||
return xdr.ElementSizeExceeded("{{.Name}}", _{{.Name}}Size, {{.Max}})
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
if _{{.Name}}Size <= len(o.{{.Name}}) {
|
|
||||||
{{if eq .FieldType "string"}}
|
|
||||||
for i := _{{.Name}}Size; i < len(o.{{.Name}}); i++ { o.{{.Name}}[i] = "" }
|
|
||||||
{{end}}
|
|
||||||
{{if eq .FieldType "[]byte"}}
|
|
||||||
for i := _{{.Name}}Size; i < len(o.{{.Name}}); i++ { o.{{.Name}}[i] = nil }
|
|
||||||
{{end}}
|
|
||||||
o.{{.Name}} = o.{{.Name}}[:_{{.Name}}Size]
|
|
||||||
} else {
|
|
||||||
o.{{.Name}} = make([]{{.FieldType}}, _{{.Name}}Size)
|
|
||||||
}
|
|
||||||
for i := range o.{{.Name}} {
|
|
||||||
{{if ne .Convert ""}}
|
|
||||||
o.{{.Name}}[i] = {{.FieldType}}(u.Unmarshal{{.Encoder}}())
|
|
||||||
{{else if .IsBasic}}
|
|
||||||
{{if ge .Submax 1}}
|
|
||||||
o.{{.Name}}[i] = u.Unmarshal{{.Encoder}}Max({{.Submax}})
|
|
||||||
{{else}}
|
|
||||||
o.{{.Name}}[i] = u.Unmarshal{{.Encoder}}()
|
|
||||||
{{end}}
|
|
||||||
{{else}}
|
|
||||||
(&o.{{.Name}}[i]).UnmarshalXDRFrom(u)
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
`
|
|
||||||
|
|
||||||
var (
|
|
||||||
encodeTpl = template.Must(template.New("encoder").Parse(encoderData))
|
|
||||||
headerTpl = template.Must(template.New("header").Parse(headerData))
|
|
||||||
)
|
|
||||||
|
|
||||||
var emptyTypeTpl = template.Must(template.New("encoder").Parse(`
|
|
||||||
func (o {{.Name}}) XDRSize() int {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o {{.Name}}) MarshalXDR() ([]byte, error) {
|
|
||||||
return nil, nil
|
|
||||||
}//+n
|
|
||||||
|
|
||||||
func (o {{.Name}}) MustMarshalXDR() []byte {
|
|
||||||
return nil
|
|
||||||
}//+n
|
|
||||||
|
|
||||||
func (o {{.Name}}) MarshalXDRInto(m *xdr.Marshaller) error {
|
|
||||||
return nil
|
|
||||||
}//+n
|
|
||||||
|
|
||||||
func (o *{{.Name}}) UnmarshalXDR(bs []byte) error {
|
|
||||||
return nil
|
|
||||||
}//+n
|
|
||||||
|
|
||||||
func (o *{{.Name}}) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
|
||||||
return nil
|
|
||||||
}//+n
|
|
||||||
`))
|
|
||||||
|
|
||||||
var maxRe = regexp.MustCompile(`(?:\Wmax:)(\d+)(?:\s*,\s*(\d+))?`)
|
|
||||||
|
|
||||||
type typeSet struct {
|
|
||||||
Type string
|
|
||||||
Encoder string
|
|
||||||
}
|
|
||||||
|
|
||||||
var xdrEncoders = map[string]typeSet{
|
|
||||||
"int8": typeSet{"uint8", "Uint8"},
|
|
||||||
"uint8": typeSet{"", "Uint8"},
|
|
||||||
"int16": typeSet{"uint16", "Uint16"},
|
|
||||||
"uint16": typeSet{"", "Uint16"},
|
|
||||||
"int32": typeSet{"uint32", "Uint32"},
|
|
||||||
"uint32": typeSet{"", "Uint32"},
|
|
||||||
"int64": typeSet{"uint64", "Uint64"},
|
|
||||||
"uint64": typeSet{"", "Uint64"},
|
|
||||||
"int": typeSet{"uint64", "Uint64"},
|
|
||||||
"string": typeSet{"", "String"},
|
|
||||||
"[]byte": typeSet{"", "Bytes"},
|
|
||||||
"bool": typeSet{"", "Bool"},
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleStruct(t *ast.StructType) []fieldInfo {
|
|
||||||
var fs []fieldInfo
|
|
||||||
|
|
||||||
for _, sf := range t.Fields.List {
|
|
||||||
if len(sf.Names) == 0 {
|
|
||||||
// We don't handle anonymous fields
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
fn := sf.Names[0].Name
|
|
||||||
var max1, max2 int
|
|
||||||
if sf.Comment != nil {
|
|
||||||
c := sf.Comment.List[0].Text
|
|
||||||
m := maxRe.FindStringSubmatch(c)
|
|
||||||
if len(m) >= 2 {
|
|
||||||
max1, _ = strconv.Atoi(m[1])
|
|
||||||
}
|
|
||||||
if len(m) >= 3 {
|
|
||||||
max2, _ = strconv.Atoi(m[2])
|
|
||||||
}
|
|
||||||
if strings.Contains(c, "noencode") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var f fieldInfo
|
|
||||||
switch ft := sf.Type.(type) {
|
|
||||||
case *ast.Ident:
|
|
||||||
tn := ft.Name
|
|
||||||
if enc, ok := xdrEncoders[tn]; ok {
|
|
||||||
f = fieldInfo{
|
|
||||||
Name: fn,
|
|
||||||
IsBasic: true,
|
|
||||||
FieldType: tn,
|
|
||||||
Encoder: enc.Encoder,
|
|
||||||
Convert: enc.Type,
|
|
||||||
Max: max1,
|
|
||||||
Submax: max2,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
f = fieldInfo{
|
|
||||||
Name: fn,
|
|
||||||
IsBasic: false,
|
|
||||||
FieldType: tn,
|
|
||||||
Max: max1,
|
|
||||||
Submax: max2,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case *ast.ArrayType:
|
|
||||||
if ft.Len != nil {
|
|
||||||
// We don't handle arrays
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
tn := ft.Elt.(*ast.Ident).Name
|
|
||||||
if enc, ok := xdrEncoders["[]"+tn]; ok {
|
|
||||||
f = fieldInfo{
|
|
||||||
Name: fn,
|
|
||||||
IsBasic: true,
|
|
||||||
FieldType: "[]" + tn,
|
|
||||||
Encoder: enc.Encoder,
|
|
||||||
Convert: enc.Type,
|
|
||||||
Max: max1,
|
|
||||||
Submax: max2,
|
|
||||||
}
|
|
||||||
} else if enc, ok := xdrEncoders[tn]; ok {
|
|
||||||
f = fieldInfo{
|
|
||||||
Name: fn,
|
|
||||||
IsBasic: true,
|
|
||||||
IsSlice: true,
|
|
||||||
FieldType: tn,
|
|
||||||
Encoder: enc.Encoder,
|
|
||||||
Convert: enc.Type,
|
|
||||||
Max: max1,
|
|
||||||
Submax: max2,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
f = fieldInfo{
|
|
||||||
Name: fn,
|
|
||||||
IsSlice: true,
|
|
||||||
FieldType: tn,
|
|
||||||
Max: max1,
|
|
||||||
Submax: max2,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case *ast.SelectorExpr:
|
|
||||||
f = fieldInfo{
|
|
||||||
Name: fn,
|
|
||||||
FieldType: ft.Sel.Name,
|
|
||||||
Max: max1,
|
|
||||||
Submax: max2,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs = append(fs, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
return fs
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateCode(output io.Writer, s structInfo) {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
var err error
|
|
||||||
if len(s.Fields) == 0 {
|
|
||||||
// This is an empty type. We can create a quite simple codec for it.
|
|
||||||
err = emptyTypeTpl.Execute(&buf, s)
|
|
||||||
} else {
|
|
||||||
// Generate with the default template.
|
|
||||||
err = encodeTpl.Execute(&buf, s)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
bs := regexp.MustCompile(`(\s*\n)+`).ReplaceAll(buf.Bytes(), []byte("\n"))
|
|
||||||
bs = bytes.Replace(bs, []byte("//+n"), []byte("\n"), -1)
|
|
||||||
output.Write(bs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func uncamelize(s string) string {
|
|
||||||
return regexp.MustCompile("[a-z][A-Z]").ReplaceAllStringFunc(s, func(camel string) string {
|
|
||||||
return camel[:1] + " " + camel[1:]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateDiagram(output io.Writer, s structInfo) {
|
|
||||||
sn := s.Name
|
|
||||||
fs := s.Fields
|
|
||||||
|
|
||||||
fmt.Fprintln(output, sn+" Structure:")
|
|
||||||
|
|
||||||
if len(fs) == 0 {
|
|
||||||
fmt.Fprintln(output, "(contains no fields)")
|
|
||||||
fmt.Fprintln(output)
|
|
||||||
fmt.Fprintln(output)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintln(output)
|
|
||||||
fmt.Fprintln(output, " 0 1 2 3")
|
|
||||||
fmt.Fprintln(output, " 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1")
|
|
||||||
line := "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
|
|
||||||
fmt.Fprintln(output, line)
|
|
||||||
|
|
||||||
for _, f := range fs {
|
|
||||||
tn := f.FieldType
|
|
||||||
name := uncamelize(f.Name)
|
|
||||||
|
|
||||||
suffix := ""
|
|
||||||
if f.IsSlice {
|
|
||||||
fmt.Fprintf(output, "| %s |\n", center("Number of "+name, 61))
|
|
||||||
fmt.Fprintln(output, line)
|
|
||||||
suffix = " (n items)"
|
|
||||||
fmt.Fprintf(output, "/ %s /\n", center("", 61))
|
|
||||||
}
|
|
||||||
switch tn {
|
|
||||||
case "bool":
|
|
||||||
fmt.Fprintf(output, "| %s |V|\n", center(name+" (V=0 or 1)", 59))
|
|
||||||
case "int16", "uint16":
|
|
||||||
fmt.Fprintf(output, "| %s | %s |\n", center("16 zero bits", 29), center(name, 29))
|
|
||||||
case "int8", "uint8":
|
|
||||||
fmt.Fprintf(output, "| %s | %s |\n", center("24 zero bits", 45), center(name, 13))
|
|
||||||
case "int32", "uint32":
|
|
||||||
fmt.Fprintf(output, "| %s |\n", center(name+suffix, 61))
|
|
||||||
case "int64", "uint64":
|
|
||||||
fmt.Fprintf(output, "| %-61s |\n", "")
|
|
||||||
fmt.Fprintf(output, "+ %s +\n", center(name+" (64 bits)", 61))
|
|
||||||
fmt.Fprintf(output, "| %-61s |\n", "")
|
|
||||||
case "string", "[]byte":
|
|
||||||
fmt.Fprintf(output, "/ %61s /\n", "")
|
|
||||||
fmt.Fprintf(output, "\\ %s \\\n", center(name+" (length + padded data)", 61))
|
|
||||||
fmt.Fprintf(output, "/ %61s /\n", "")
|
|
||||||
default:
|
|
||||||
if f.IsSlice {
|
|
||||||
tn = "Zero or more " + tn + " Structures"
|
|
||||||
fmt.Fprintf(output, "\\ %s \\\n", center(tn, 61))
|
|
||||||
} else {
|
|
||||||
tn = tn + " Structure"
|
|
||||||
fmt.Fprintf(output, "/ %s /\n", center("", 61))
|
|
||||||
fmt.Fprintf(output, "\\ %s \\\n", center(tn, 61))
|
|
||||||
fmt.Fprintf(output, "/ %s /\n", center("", 61))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.IsSlice {
|
|
||||||
fmt.Fprintf(output, "/ %s /\n", center("", 61))
|
|
||||||
}
|
|
||||||
fmt.Fprintln(output, line)
|
|
||||||
}
|
|
||||||
fmt.Fprintln(output)
|
|
||||||
fmt.Fprintln(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateXdr(output io.Writer, s structInfo) {
|
|
||||||
sn := s.Name
|
|
||||||
fs := s.Fields
|
|
||||||
|
|
||||||
fmt.Fprintf(output, "struct %s {\n", sn)
|
|
||||||
|
|
||||||
for _, f := range fs {
|
|
||||||
tn := f.FieldType
|
|
||||||
fn := f.Name
|
|
||||||
suf := ""
|
|
||||||
l := ""
|
|
||||||
if f.Max > 0 {
|
|
||||||
l = strconv.Itoa(f.Max)
|
|
||||||
}
|
|
||||||
if f.IsSlice {
|
|
||||||
suf = "<" + l + ">"
|
|
||||||
}
|
|
||||||
|
|
||||||
switch tn {
|
|
||||||
case "int8", "int16", "int32":
|
|
||||||
fmt.Fprintf(output, "\tint %s%s;\n", fn, suf)
|
|
||||||
case "uint8", "uint16", "uint32":
|
|
||||||
fmt.Fprintf(output, "\tunsigned int %s%s;\n", fn, suf)
|
|
||||||
case "int64":
|
|
||||||
fmt.Fprintf(output, "\thyper %s%s;\n", fn, suf)
|
|
||||||
case "uint64":
|
|
||||||
fmt.Fprintf(output, "\tunsigned hyper %s%s;\n", fn, suf)
|
|
||||||
case "string":
|
|
||||||
fmt.Fprintf(output, "\tstring %s<%s>;\n", fn, l)
|
|
||||||
case "[]byte":
|
|
||||||
fmt.Fprintf(output, "\topaque %s<%s>;\n", fn, l)
|
|
||||||
default:
|
|
||||||
fmt.Fprintf(output, "\t%s %s%s;\n", tn, fn, suf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprintln(output, "}")
|
|
||||||
fmt.Fprintln(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
func center(s string, w int) string {
|
|
||||||
w -= len(s)
|
|
||||||
l := w / 2
|
|
||||||
r := l
|
|
||||||
if l+r < w {
|
|
||||||
r++
|
|
||||||
}
|
|
||||||
return strings.Repeat(" ", l) + s + strings.Repeat(" ", r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func inspector(structs *[]structInfo) func(ast.Node) bool {
|
|
||||||
return func(n ast.Node) bool {
|
|
||||||
switch n := n.(type) {
|
|
||||||
case *ast.TypeSpec:
|
|
||||||
switch t := n.Type.(type) {
|
|
||||||
case *ast.StructType:
|
|
||||||
name := n.Name.Name
|
|
||||||
fs := handleStruct(t)
|
|
||||||
*structs = append(*structs, structInfo{name, fs})
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
default:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
outputFile := flag.String("o", "", "Output file, blank for stdout")
|
|
||||||
flag.Parse()
|
|
||||||
fname := flag.Arg(0)
|
|
||||||
|
|
||||||
fset := token.NewFileSet()
|
|
||||||
f, err := parser.ParseFile(fset, fname, nil, parser.ParseComments)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var structs []structInfo
|
|
||||||
i := inspector(&structs)
|
|
||||||
ast.Inspect(f, i)
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
headerTpl.Execute(buf, map[string]string{"Package": f.Name.Name})
|
|
||||||
for _, s := range structs {
|
|
||||||
fmt.Fprintf(buf, "\n/*\n\n")
|
|
||||||
generateDiagram(buf, s)
|
|
||||||
generateXdr(buf, s)
|
|
||||||
fmt.Fprintf(buf, "*/\n")
|
|
||||||
generateCode(buf, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
bs, err := format.Source(buf.Bytes())
|
|
||||||
if err != nil {
|
|
||||||
log.Print(buf.String())
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var output io.Writer = os.Stdout
|
|
||||||
if *outputFile != "" {
|
|
||||||
fd, err := os.Create(*outputFile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
output = fd
|
|
||||||
}
|
|
||||||
output.Write(bs)
|
|
||||||
}
|
|
4
vendor/github.com/calmh/xdr/generate.sh
generated
vendored
Normal file
4
vendor/github.com/calmh/xdr/generate.sh
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
go run cmd/genxdr/main.go -- bench_test.go > bench_xdr_test.go
|
||||||
|
go run cmd/genxdr/main.go -- encdec_test.go > encdec_xdr_test.go
|
12
vendor/github.com/cheggaaa/pb/LICENSE
generated
vendored
12
vendor/github.com/cheggaaa/pb/LICENSE
generated
vendored
@ -1,12 +0,0 @@
|
|||||||
Copyright (c) 2012-2015, Sergey Cherepanov
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
118
vendor/github.com/cheggaaa/pb/format.go
generated
vendored
118
vendor/github.com/cheggaaa/pb/format.go
generated
vendored
@ -1,118 +0,0 @@
|
|||||||
package pb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Units int
|
|
||||||
|
|
||||||
const (
|
|
||||||
// U_NO are default units, they represent a simple value and are not formatted at all.
|
|
||||||
U_NO Units = iota
|
|
||||||
// U_BYTES units are formatted in a human readable way (B, KiB, MiB, ...)
|
|
||||||
U_BYTES
|
|
||||||
// U_BYTES_DEC units are like U_BYTES, but base 10 (B, KB, MB, ...)
|
|
||||||
U_BYTES_DEC
|
|
||||||
// U_DURATION units are formatted in a human readable way (3h14m15s)
|
|
||||||
U_DURATION
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
KiB = 1024
|
|
||||||
MiB = 1048576
|
|
||||||
GiB = 1073741824
|
|
||||||
TiB = 1099511627776
|
|
||||||
|
|
||||||
KB = 1e3
|
|
||||||
MB = 1e6
|
|
||||||
GB = 1e9
|
|
||||||
TB = 1e12
|
|
||||||
)
|
|
||||||
|
|
||||||
func Format(i int64) *formatter {
|
|
||||||
return &formatter{n: i}
|
|
||||||
}
|
|
||||||
|
|
||||||
type formatter struct {
|
|
||||||
n int64
|
|
||||||
unit Units
|
|
||||||
width int
|
|
||||||
perSec bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *formatter) To(unit Units) *formatter {
|
|
||||||
f.unit = unit
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *formatter) Width(width int) *formatter {
|
|
||||||
f.width = width
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *formatter) PerSec() *formatter {
|
|
||||||
f.perSec = true
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *formatter) String() (out string) {
|
|
||||||
switch f.unit {
|
|
||||||
case U_BYTES:
|
|
||||||
out = formatBytes(f.n)
|
|
||||||
case U_BYTES_DEC:
|
|
||||||
out = formatBytesDec(f.n)
|
|
||||||
case U_DURATION:
|
|
||||||
out = formatDuration(f.n)
|
|
||||||
default:
|
|
||||||
out = fmt.Sprintf(fmt.Sprintf("%%%dd", f.width), f.n)
|
|
||||||
}
|
|
||||||
if f.perSec {
|
|
||||||
out += "/s"
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert bytes to human readable string. Like 2 MiB, 64.2 KiB, 52 B
|
|
||||||
func formatBytes(i int64) (result string) {
|
|
||||||
switch {
|
|
||||||
case i >= TiB:
|
|
||||||
result = fmt.Sprintf("%.02f TiB", float64(i)/TiB)
|
|
||||||
case i >= GiB:
|
|
||||||
result = fmt.Sprintf("%.02f GiB", float64(i)/GiB)
|
|
||||||
case i >= MiB:
|
|
||||||
result = fmt.Sprintf("%.02f MiB", float64(i)/MiB)
|
|
||||||
case i >= KiB:
|
|
||||||
result = fmt.Sprintf("%.02f KiB", float64(i)/KiB)
|
|
||||||
default:
|
|
||||||
result = fmt.Sprintf("%d B", i)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert bytes to base-10 human readable string. Like 2 MB, 64.2 KB, 52 B
|
|
||||||
func formatBytesDec(i int64) (result string) {
|
|
||||||
switch {
|
|
||||||
case i >= TB:
|
|
||||||
result = fmt.Sprintf("%.02f TB", float64(i)/TB)
|
|
||||||
case i >= GB:
|
|
||||||
result = fmt.Sprintf("%.02f GB", float64(i)/GB)
|
|
||||||
case i >= MB:
|
|
||||||
result = fmt.Sprintf("%.02f MB", float64(i)/MB)
|
|
||||||
case i >= KB:
|
|
||||||
result = fmt.Sprintf("%.02f KB", float64(i)/KB)
|
|
||||||
default:
|
|
||||||
result = fmt.Sprintf("%d B", i)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func formatDuration(n int64) (result string) {
|
|
||||||
d := time.Duration(n)
|
|
||||||
if d > time.Hour*24 {
|
|
||||||
result = fmt.Sprintf("%dd", d/24/time.Hour)
|
|
||||||
d -= (d / time.Hour / 24) * (time.Hour * 24)
|
|
||||||
}
|
|
||||||
result = fmt.Sprintf("%s%v", result, d)
|
|
||||||
return
|
|
||||||
}
|
|
469
vendor/github.com/cheggaaa/pb/pb.go
generated
vendored
469
vendor/github.com/cheggaaa/pb/pb.go
generated
vendored
@ -1,469 +0,0 @@
|
|||||||
// Simple console progress bars
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"math"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
|
||||||
"unicode/utf8"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Current version
|
|
||||||
const Version = "1.0.19"
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Default refresh rate - 200ms
|
|
||||||
DEFAULT_REFRESH_RATE = time.Millisecond * 200
|
|
||||||
FORMAT = "[=>-]"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DEPRECATED
|
|
||||||
// variables for backward compatibility, from now do not work
|
|
||||||
// use pb.Format and pb.SetRefreshRate
|
|
||||||
var (
|
|
||||||
DefaultRefreshRate = DEFAULT_REFRESH_RATE
|
|
||||||
BarStart, BarEnd, Empty, Current, CurrentN string
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create new progress bar object
|
|
||||||
func New(total int) *ProgressBar {
|
|
||||||
return New64(int64(total))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new progress bar object using int64 as total
|
|
||||||
func New64(total int64) *ProgressBar {
|
|
||||||
pb := &ProgressBar{
|
|
||||||
Total: total,
|
|
||||||
RefreshRate: DEFAULT_REFRESH_RATE,
|
|
||||||
ShowPercent: true,
|
|
||||||
ShowCounters: true,
|
|
||||||
ShowBar: true,
|
|
||||||
ShowTimeLeft: true,
|
|
||||||
ShowFinalTime: true,
|
|
||||||
Units: U_NO,
|
|
||||||
ManualUpdate: false,
|
|
||||||
finish: make(chan struct{}),
|
|
||||||
}
|
|
||||||
return pb.Format(FORMAT)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new object and start
|
|
||||||
func StartNew(total int) *ProgressBar {
|
|
||||||
return New(total).Start()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback for custom output
|
|
||||||
// For example:
|
|
||||||
// bar.Callback = func(s string) {
|
|
||||||
// mySuperPrint(s)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
type Callback func(out string)
|
|
||||||
|
|
||||||
type ProgressBar struct {
|
|
||||||
current int64 // current must be first member of struct (https://code.google.com/p/go/issues/detail?id=5278)
|
|
||||||
previous int64
|
|
||||||
|
|
||||||
Total int64
|
|
||||||
RefreshRate time.Duration
|
|
||||||
ShowPercent, ShowCounters bool
|
|
||||||
ShowSpeed, ShowTimeLeft, ShowBar bool
|
|
||||||
ShowFinalTime bool
|
|
||||||
Output io.Writer
|
|
||||||
Callback Callback
|
|
||||||
NotPrint bool
|
|
||||||
Units Units
|
|
||||||
Width int
|
|
||||||
ForceWidth bool
|
|
||||||
ManualUpdate bool
|
|
||||||
AutoStat bool
|
|
||||||
|
|
||||||
// Default width for the time box.
|
|
||||||
UnitsWidth int
|
|
||||||
TimeBoxWidth int
|
|
||||||
|
|
||||||
finishOnce sync.Once //Guards isFinish
|
|
||||||
finish chan struct{}
|
|
||||||
isFinish bool
|
|
||||||
|
|
||||||
startTime time.Time
|
|
||||||
startValue int64
|
|
||||||
|
|
||||||
changeTime time.Time
|
|
||||||
|
|
||||||
prefix, postfix string
|
|
||||||
|
|
||||||
mu sync.Mutex
|
|
||||||
lastPrint string
|
|
||||||
|
|
||||||
BarStart string
|
|
||||||
BarEnd string
|
|
||||||
Empty string
|
|
||||||
Current string
|
|
||||||
CurrentN string
|
|
||||||
|
|
||||||
AlwaysUpdate bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start print
|
|
||||||
func (pb *ProgressBar) Start() *ProgressBar {
|
|
||||||
pb.startTime = time.Now()
|
|
||||||
pb.startValue = atomic.LoadInt64(&pb.current)
|
|
||||||
if pb.Total == 0 {
|
|
||||||
pb.ShowTimeLeft = false
|
|
||||||
pb.ShowPercent = false
|
|
||||||
pb.AutoStat = false
|
|
||||||
}
|
|
||||||
if !pb.ManualUpdate {
|
|
||||||
pb.Update() // Initial printing of the bar before running the bar refresher.
|
|
||||||
go pb.refresher()
|
|
||||||
}
|
|
||||||
return pb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment current value
|
|
||||||
func (pb *ProgressBar) Increment() int {
|
|
||||||
return pb.Add(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current value
|
|
||||||
func (pb *ProgressBar) Get() int64 {
|
|
||||||
c := atomic.LoadInt64(&pb.current)
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set current value
|
|
||||||
func (pb *ProgressBar) Set(current int) *ProgressBar {
|
|
||||||
return pb.Set64(int64(current))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set64 sets the current value as int64
|
|
||||||
func (pb *ProgressBar) Set64(current int64) *ProgressBar {
|
|
||||||
atomic.StoreInt64(&pb.current, current)
|
|
||||||
return pb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add to current value
|
|
||||||
func (pb *ProgressBar) Add(add int) int {
|
|
||||||
return int(pb.Add64(int64(add)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pb *ProgressBar) Add64(add int64) int64 {
|
|
||||||
return atomic.AddInt64(&pb.current, add)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set prefix string
|
|
||||||
func (pb *ProgressBar) Prefix(prefix string) *ProgressBar {
|
|
||||||
pb.prefix = prefix
|
|
||||||
return pb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set postfix string
|
|
||||||
func (pb *ProgressBar) Postfix(postfix string) *ProgressBar {
|
|
||||||
pb.postfix = postfix
|
|
||||||
return pb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set custom format for bar
|
|
||||||
// Example: bar.Format("[=>_]")
|
|
||||||
// Example: bar.Format("[\x00=\x00>\x00-\x00]") // \x00 is the delimiter
|
|
||||||
func (pb *ProgressBar) Format(format string) *ProgressBar {
|
|
||||||
var formatEntries []string
|
|
||||||
if utf8.RuneCountInString(format) == 5 {
|
|
||||||
formatEntries = strings.Split(format, "")
|
|
||||||
} else {
|
|
||||||
formatEntries = strings.Split(format, "\x00")
|
|
||||||
}
|
|
||||||
if len(formatEntries) == 5 {
|
|
||||||
pb.BarStart = formatEntries[0]
|
|
||||||
pb.BarEnd = formatEntries[4]
|
|
||||||
pb.Empty = formatEntries[3]
|
|
||||||
pb.Current = formatEntries[1]
|
|
||||||
pb.CurrentN = formatEntries[2]
|
|
||||||
}
|
|
||||||
return pb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set bar refresh rate
|
|
||||||
func (pb *ProgressBar) SetRefreshRate(rate time.Duration) *ProgressBar {
|
|
||||||
pb.RefreshRate = rate
|
|
||||||
return pb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set units
|
|
||||||
// bar.SetUnits(U_NO) - by default
|
|
||||||
// bar.SetUnits(U_BYTES) - for Mb, Kb, etc
|
|
||||||
func (pb *ProgressBar) SetUnits(units Units) *ProgressBar {
|
|
||||||
pb.Units = units
|
|
||||||
return pb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set max width, if width is bigger than terminal width, will be ignored
|
|
||||||
func (pb *ProgressBar) SetMaxWidth(width int) *ProgressBar {
|
|
||||||
pb.Width = width
|
|
||||||
pb.ForceWidth = false
|
|
||||||
return pb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set bar width
|
|
||||||
func (pb *ProgressBar) SetWidth(width int) *ProgressBar {
|
|
||||||
pb.Width = width
|
|
||||||
pb.ForceWidth = true
|
|
||||||
return pb
|
|
||||||
}
|
|
||||||
|
|
||||||
// End print
|
|
||||||
func (pb *ProgressBar) Finish() {
|
|
||||||
//Protect multiple calls
|
|
||||||
pb.finishOnce.Do(func() {
|
|
||||||
close(pb.finish)
|
|
||||||
pb.write(atomic.LoadInt64(&pb.current))
|
|
||||||
pb.mu.Lock()
|
|
||||||
defer pb.mu.Unlock()
|
|
||||||
switch {
|
|
||||||
case pb.Output != nil:
|
|
||||||
fmt.Fprintln(pb.Output)
|
|
||||||
case !pb.NotPrint:
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
pb.isFinish = true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsFinished return boolean
|
|
||||||
func (pb *ProgressBar) IsFinished() bool {
|
|
||||||
pb.mu.Lock()
|
|
||||||
defer pb.mu.Unlock()
|
|
||||||
return pb.isFinish
|
|
||||||
}
|
|
||||||
|
|
||||||
// End print and write string 'str'
|
|
||||||
func (pb *ProgressBar) FinishPrint(str string) {
|
|
||||||
pb.Finish()
|
|
||||||
if pb.Output != nil {
|
|
||||||
fmt.Fprintln(pb.Output, str)
|
|
||||||
} else {
|
|
||||||
fmt.Println(str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// implement io.Writer
|
|
||||||
func (pb *ProgressBar) Write(p []byte) (n int, err error) {
|
|
||||||
n = len(p)
|
|
||||||
pb.Add(n)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// implement io.Reader
|
|
||||||
func (pb *ProgressBar) Read(p []byte) (n int, err error) {
|
|
||||||
n = len(p)
|
|
||||||
pb.Add(n)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new proxy reader over bar
|
|
||||||
// Takes io.Reader or io.ReadCloser
|
|
||||||
func (pb *ProgressBar) NewProxyReader(r io.Reader) *Reader {
|
|
||||||
return &Reader{r, pb}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pb *ProgressBar) write(current int64) {
|
|
||||||
width := pb.GetWidth()
|
|
||||||
|
|
||||||
var percentBox, countersBox, timeLeftBox, speedBox, barBox, end, out string
|
|
||||||
|
|
||||||
// percents
|
|
||||||
if pb.ShowPercent {
|
|
||||||
var percent float64
|
|
||||||
if pb.Total > 0 {
|
|
||||||
percent = float64(current) / (float64(pb.Total) / float64(100))
|
|
||||||
} else {
|
|
||||||
percent = float64(current) / float64(100)
|
|
||||||
}
|
|
||||||
percentBox = fmt.Sprintf(" %6.02f%%", percent)
|
|
||||||
}
|
|
||||||
|
|
||||||
// counters
|
|
||||||
if pb.ShowCounters {
|
|
||||||
current := Format(current).To(pb.Units).Width(pb.UnitsWidth)
|
|
||||||
if pb.Total > 0 {
|
|
||||||
total := Format(pb.Total).To(pb.Units).Width(pb.UnitsWidth)
|
|
||||||
countersBox = fmt.Sprintf(" %s / %s ", current, total)
|
|
||||||
} else {
|
|
||||||
countersBox = fmt.Sprintf(" %s / ? ", current)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// time left
|
|
||||||
pb.mu.Lock()
|
|
||||||
currentFromStart := current - pb.startValue
|
|
||||||
fromStart := time.Now().Sub(pb.startTime)
|
|
||||||
lastChangeTime := pb.changeTime
|
|
||||||
fromChange := lastChangeTime.Sub(pb.startTime)
|
|
||||||
pb.mu.Unlock()
|
|
||||||
select {
|
|
||||||
case <-pb.finish:
|
|
||||||
if pb.ShowFinalTime {
|
|
||||||
var left time.Duration
|
|
||||||
left = (fromStart / time.Second) * time.Second
|
|
||||||
timeLeftBox = fmt.Sprintf(" %s", left.String())
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
if pb.ShowTimeLeft && currentFromStart > 0 {
|
|
||||||
perEntry := fromChange / time.Duration(currentFromStart)
|
|
||||||
var left time.Duration
|
|
||||||
if pb.Total > 0 {
|
|
||||||
left = time.Duration(pb.Total-currentFromStart) * perEntry
|
|
||||||
left -= time.Since(lastChangeTime)
|
|
||||||
left = (left / time.Second) * time.Second
|
|
||||||
} else {
|
|
||||||
left = time.Duration(currentFromStart) * perEntry
|
|
||||||
left = (left / time.Second) * time.Second
|
|
||||||
}
|
|
||||||
if left > 0 {
|
|
||||||
timeLeft := Format(int64(left)).To(U_DURATION).String()
|
|
||||||
timeLeftBox = fmt.Sprintf(" %s", timeLeft)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(timeLeftBox) < pb.TimeBoxWidth {
|
|
||||||
timeLeftBox = fmt.Sprintf("%s%s", strings.Repeat(" ", pb.TimeBoxWidth-len(timeLeftBox)), timeLeftBox)
|
|
||||||
}
|
|
||||||
|
|
||||||
// speed
|
|
||||||
if pb.ShowSpeed && currentFromStart > 0 {
|
|
||||||
fromStart := time.Now().Sub(pb.startTime)
|
|
||||||
speed := float64(currentFromStart) / (float64(fromStart) / float64(time.Second))
|
|
||||||
speedBox = " " + Format(int64(speed)).To(pb.Units).Width(pb.UnitsWidth).PerSec().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
barWidth := escapeAwareRuneCountInString(countersBox + pb.BarStart + pb.BarEnd + percentBox + timeLeftBox + speedBox + pb.prefix + pb.postfix)
|
|
||||||
// bar
|
|
||||||
if pb.ShowBar {
|
|
||||||
size := width - barWidth
|
|
||||||
if size > 0 {
|
|
||||||
if pb.Total > 0 {
|
|
||||||
curSize := int(math.Ceil((float64(current) / float64(pb.Total)) * float64(size)))
|
|
||||||
emptySize := size - curSize
|
|
||||||
barBox = pb.BarStart
|
|
||||||
if emptySize < 0 {
|
|
||||||
emptySize = 0
|
|
||||||
}
|
|
||||||
if curSize > size {
|
|
||||||
curSize = size
|
|
||||||
}
|
|
||||||
|
|
||||||
cursorLen := escapeAwareRuneCountInString(pb.Current)
|
|
||||||
if emptySize <= 0 {
|
|
||||||
barBox += strings.Repeat(pb.Current, curSize/cursorLen)
|
|
||||||
} else if curSize > 0 {
|
|
||||||
cursorEndLen := escapeAwareRuneCountInString(pb.CurrentN)
|
|
||||||
cursorRepetitions := (curSize - cursorEndLen) / cursorLen
|
|
||||||
barBox += strings.Repeat(pb.Current, cursorRepetitions)
|
|
||||||
barBox += pb.CurrentN
|
|
||||||
}
|
|
||||||
|
|
||||||
emptyLen := escapeAwareRuneCountInString(pb.Empty)
|
|
||||||
barBox += strings.Repeat(pb.Empty, emptySize/emptyLen)
|
|
||||||
barBox += pb.BarEnd
|
|
||||||
} else {
|
|
||||||
pos := size - int(current)%int(size)
|
|
||||||
barBox = pb.BarStart
|
|
||||||
if pos-1 > 0 {
|
|
||||||
barBox += strings.Repeat(pb.Empty, pos-1)
|
|
||||||
}
|
|
||||||
barBox += pb.Current
|
|
||||||
if size-pos-1 > 0 {
|
|
||||||
barBox += strings.Repeat(pb.Empty, size-pos-1)
|
|
||||||
}
|
|
||||||
barBox += pb.BarEnd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check len
|
|
||||||
out = pb.prefix + countersBox + barBox + percentBox + speedBox + timeLeftBox + pb.postfix
|
|
||||||
if cl := escapeAwareRuneCountInString(out); cl < width {
|
|
||||||
end = strings.Repeat(" ", width-cl)
|
|
||||||
}
|
|
||||||
|
|
||||||
// and print!
|
|
||||||
pb.mu.Lock()
|
|
||||||
pb.lastPrint = out + end
|
|
||||||
isFinish := pb.isFinish
|
|
||||||
pb.mu.Unlock()
|
|
||||||
switch {
|
|
||||||
case isFinish:
|
|
||||||
return
|
|
||||||
case pb.Output != nil:
|
|
||||||
fmt.Fprint(pb.Output, "\r"+out+end)
|
|
||||||
case pb.Callback != nil:
|
|
||||||
pb.Callback(out + end)
|
|
||||||
case !pb.NotPrint:
|
|
||||||
fmt.Print("\r" + out + end)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTerminalWidth - returns terminal width for all platforms.
|
|
||||||
func GetTerminalWidth() (int, error) {
|
|
||||||
return terminalWidth()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pb *ProgressBar) GetWidth() int {
|
|
||||||
if pb.ForceWidth {
|
|
||||||
return pb.Width
|
|
||||||
}
|
|
||||||
|
|
||||||
width := pb.Width
|
|
||||||
termWidth, _ := terminalWidth()
|
|
||||||
if width == 0 || termWidth <= width {
|
|
||||||
width = termWidth
|
|
||||||
}
|
|
||||||
|
|
||||||
return width
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the current state of the progressbar
|
|
||||||
func (pb *ProgressBar) Update() {
|
|
||||||
c := atomic.LoadInt64(&pb.current)
|
|
||||||
p := atomic.LoadInt64(&pb.previous)
|
|
||||||
if p != c {
|
|
||||||
pb.mu.Lock()
|
|
||||||
pb.changeTime = time.Now()
|
|
||||||
pb.mu.Unlock()
|
|
||||||
atomic.StoreInt64(&pb.previous, c)
|
|
||||||
}
|
|
||||||
pb.write(c)
|
|
||||||
if pb.AutoStat {
|
|
||||||
if c == 0 {
|
|
||||||
pb.startTime = time.Now()
|
|
||||||
pb.startValue = 0
|
|
||||||
} else if c >= pb.Total && pb.isFinish != true {
|
|
||||||
pb.Finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// String return the last bar print
|
|
||||||
func (pb *ProgressBar) String() string {
|
|
||||||
pb.mu.Lock()
|
|
||||||
defer pb.mu.Unlock()
|
|
||||||
return pb.lastPrint
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internal loop for refreshing the progressbar
|
|
||||||
func (pb *ProgressBar) refresher() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-pb.finish:
|
|
||||||
return
|
|
||||||
case <-time.After(pb.RefreshRate):
|
|
||||||
pb.Update()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
11
vendor/github.com/cheggaaa/pb/pb_appengine.go
generated
vendored
11
vendor/github.com/cheggaaa/pb/pb_appengine.go
generated
vendored
@ -1,11 +0,0 @@
|
|||||||
// +build appengine
|
|
||||||
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
// terminalWidth returns width of the terminal, which is not supported
|
|
||||||
// and should always failed on appengine classic which is a sandboxed PaaS.
|
|
||||||
func terminalWidth() (int, error) {
|
|
||||||
return 0, errors.New("Not supported")
|
|
||||||
}
|
|
141
vendor/github.com/cheggaaa/pb/pb_win.go
generated
vendored
141
vendor/github.com/cheggaaa/pb/pb_win.go
generated
vendored
@ -1,141 +0,0 @@
|
|||||||
// +build windows
|
|
||||||
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var tty = os.Stdin
|
|
||||||
|
|
||||||
var (
|
|
||||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
||||||
|
|
||||||
// GetConsoleScreenBufferInfo retrieves information about the
|
|
||||||
// specified console screen buffer.
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx
|
|
||||||
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
|
|
||||||
|
|
||||||
// GetConsoleMode retrieves the current input mode of a console's
|
|
||||||
// input buffer or the current output mode of a console screen buffer.
|
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx
|
|
||||||
getConsoleMode = kernel32.NewProc("GetConsoleMode")
|
|
||||||
|
|
||||||
// SetConsoleMode sets the input mode of a console's input buffer
|
|
||||||
// or the output mode of a console screen buffer.
|
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
|
|
||||||
setConsoleMode = kernel32.NewProc("SetConsoleMode")
|
|
||||||
|
|
||||||
// SetConsoleCursorPosition sets the cursor position in the
|
|
||||||
// specified console screen buffer.
|
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms686025(v=vs.85).aspx
|
|
||||||
setConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// Defines the coordinates of the upper left and lower right corners
|
|
||||||
// of a rectangle.
|
|
||||||
// See
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms686311(v=vs.85).aspx
|
|
||||||
smallRect struct {
|
|
||||||
Left, Top, Right, Bottom int16
|
|
||||||
}
|
|
||||||
|
|
||||||
// Defines the coordinates of a character cell in a console screen
|
|
||||||
// buffer. The origin of the coordinate system (0,0) is at the top, left cell
|
|
||||||
// of the buffer.
|
|
||||||
// See
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682119(v=vs.85).aspx
|
|
||||||
coordinates struct {
|
|
||||||
X, Y int16
|
|
||||||
}
|
|
||||||
|
|
||||||
word int16
|
|
||||||
|
|
||||||
// Contains information about a console screen buffer.
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682093(v=vs.85).aspx
|
|
||||||
consoleScreenBufferInfo struct {
|
|
||||||
dwSize coordinates
|
|
||||||
dwCursorPosition coordinates
|
|
||||||
wAttributes word
|
|
||||||
srWindow smallRect
|
|
||||||
dwMaximumWindowSize coordinates
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// terminalWidth returns width of the terminal.
|
|
||||||
func terminalWidth() (width int, err error) {
|
|
||||||
var info consoleScreenBufferInfo
|
|
||||||
_, _, e := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&info)), 0)
|
|
||||||
if e != 0 {
|
|
||||||
return 0, error(e)
|
|
||||||
}
|
|
||||||
return int(info.dwSize.X) - 1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getCursorPos() (pos coordinates, err error) {
|
|
||||||
var info consoleScreenBufferInfo
|
|
||||||
_, _, e := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&info)), 0)
|
|
||||||
if e != 0 {
|
|
||||||
return info.dwCursorPosition, error(e)
|
|
||||||
}
|
|
||||||
return info.dwCursorPosition, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setCursorPos(pos coordinates) error {
|
|
||||||
_, _, e := syscall.Syscall(setConsoleCursorPosition.Addr(), 2, uintptr(syscall.Stdout), uintptr(uint32(uint16(pos.Y))<<16|uint32(uint16(pos.X))), 0)
|
|
||||||
if e != 0 {
|
|
||||||
return error(e)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var ErrPoolWasStarted = errors.New("Bar pool was started")
|
|
||||||
|
|
||||||
var echoLocked bool
|
|
||||||
var echoLockMutex sync.Mutex
|
|
||||||
|
|
||||||
var oldState word
|
|
||||||
|
|
||||||
func lockEcho() (quit chan int, err error) {
|
|
||||||
echoLockMutex.Lock()
|
|
||||||
defer echoLockMutex.Unlock()
|
|
||||||
if echoLocked {
|
|
||||||
err = ErrPoolWasStarted
|
|
||||||
return
|
|
||||||
}
|
|
||||||
echoLocked = true
|
|
||||||
|
|
||||||
if _, _, e := syscall.Syscall(getConsoleMode.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&oldState)), 0); e != 0 {
|
|
||||||
err = fmt.Errorf("Can't get terminal settings: %v", e)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
newState := oldState
|
|
||||||
const ENABLE_ECHO_INPUT = 0x0004
|
|
||||||
const ENABLE_LINE_INPUT = 0x0002
|
|
||||||
newState = newState & (^(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT))
|
|
||||||
if _, _, e := syscall.Syscall(setConsoleMode.Addr(), 2, uintptr(syscall.Stdout), uintptr(newState), 0); e != 0 {
|
|
||||||
err = fmt.Errorf("Can't set terminal settings: %v", e)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func unlockEcho() (err error) {
|
|
||||||
echoLockMutex.Lock()
|
|
||||||
defer echoLockMutex.Unlock()
|
|
||||||
if !echoLocked {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
echoLocked = false
|
|
||||||
if _, _, e := syscall.Syscall(setConsoleMode.Addr(), 2, uintptr(syscall.Stdout), uintptr(oldState), 0); e != 0 {
|
|
||||||
err = fmt.Errorf("Can't set terminal settings")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
108
vendor/github.com/cheggaaa/pb/pb_x.go
generated
vendored
108
vendor/github.com/cheggaaa/pb/pb_x.go
generated
vendored
@ -1,108 +0,0 @@
|
|||||||
// +build linux darwin freebsd netbsd openbsd solaris dragonfly
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"sync"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ErrPoolWasStarted = errors.New("Bar pool was started")
|
|
||||||
|
|
||||||
var (
|
|
||||||
echoLockMutex sync.Mutex
|
|
||||||
origTermStatePtr *unix.Termios
|
|
||||||
tty *os.File
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
echoLockMutex.Lock()
|
|
||||||
defer echoLockMutex.Unlock()
|
|
||||||
|
|
||||||
var err error
|
|
||||||
tty, err = os.Open("/dev/tty")
|
|
||||||
if err != nil {
|
|
||||||
tty = os.Stdin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// terminalWidth returns width of the terminal.
|
|
||||||
func terminalWidth() (int, error) {
|
|
||||||
echoLockMutex.Lock()
|
|
||||||
defer echoLockMutex.Unlock()
|
|
||||||
|
|
||||||
fd := int(tty.Fd())
|
|
||||||
|
|
||||||
ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return int(ws.Col), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func lockEcho() (quit chan int, err error) {
|
|
||||||
echoLockMutex.Lock()
|
|
||||||
defer echoLockMutex.Unlock()
|
|
||||||
if origTermStatePtr != nil {
|
|
||||||
return quit, ErrPoolWasStarted
|
|
||||||
}
|
|
||||||
|
|
||||||
fd := int(tty.Fd())
|
|
||||||
|
|
||||||
oldTermStatePtr, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Can't get terminal settings: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
oldTermios := *oldTermStatePtr
|
|
||||||
newTermios := oldTermios
|
|
||||||
newTermios.Lflag &^= syscall.ECHO
|
|
||||||
newTermios.Lflag |= syscall.ICANON | syscall.ISIG
|
|
||||||
newTermios.Iflag |= syscall.ICRNL
|
|
||||||
if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, &newTermios); err != nil {
|
|
||||||
return nil, fmt.Errorf("Can't set terminal settings: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
quit = make(chan int, 1)
|
|
||||||
go catchTerminate(quit)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func unlockEcho() error {
|
|
||||||
echoLockMutex.Lock()
|
|
||||||
defer echoLockMutex.Unlock()
|
|
||||||
if origTermStatePtr == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
fd := int(tty.Fd())
|
|
||||||
|
|
||||||
if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, origTermStatePtr); err != nil {
|
|
||||||
return fmt.Errorf("Can't set terminal settings: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
origTermStatePtr = nil
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// listen exit signals and restore terminal state
|
|
||||||
func catchTerminate(quit chan int) {
|
|
||||||
sig := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(sig, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL)
|
|
||||||
defer signal.Stop(sig)
|
|
||||||
select {
|
|
||||||
case <-quit:
|
|
||||||
unlockEcho()
|
|
||||||
case <-sig:
|
|
||||||
unlockEcho()
|
|
||||||
}
|
|
||||||
}
|
|
82
vendor/github.com/cheggaaa/pb/pool.go
generated
vendored
82
vendor/github.com/cheggaaa/pb/pool.go
generated
vendored
@ -1,82 +0,0 @@
|
|||||||
// +build linux darwin freebsd netbsd openbsd solaris dragonfly windows
|
|
||||||
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create and start new pool with given bars
|
|
||||||
// You need call pool.Stop() after work
|
|
||||||
func StartPool(pbs ...*ProgressBar) (pool *Pool, err error) {
|
|
||||||
pool = new(Pool)
|
|
||||||
if err = pool.start(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pool.Add(pbs...)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type Pool struct {
|
|
||||||
Output io.Writer
|
|
||||||
RefreshRate time.Duration
|
|
||||||
bars []*ProgressBar
|
|
||||||
lastBarsCount int
|
|
||||||
quit chan int
|
|
||||||
m sync.Mutex
|
|
||||||
finishOnce sync.Once
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add progress bars.
|
|
||||||
func (p *Pool) Add(pbs ...*ProgressBar) {
|
|
||||||
p.m.Lock()
|
|
||||||
defer p.m.Unlock()
|
|
||||||
for _, bar := range pbs {
|
|
||||||
bar.ManualUpdate = true
|
|
||||||
bar.NotPrint = true
|
|
||||||
bar.Start()
|
|
||||||
p.bars = append(p.bars, bar)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pool) start() (err error) {
|
|
||||||
p.RefreshRate = DefaultRefreshRate
|
|
||||||
quit, err := lockEcho()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.quit = make(chan int)
|
|
||||||
go p.writer(quit)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pool) writer(finish chan int) {
|
|
||||||
var first = true
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-time.After(p.RefreshRate):
|
|
||||||
if p.print(first) {
|
|
||||||
p.print(false)
|
|
||||||
finish <- 1
|
|
||||||
return
|
|
||||||
}
|
|
||||||
first = false
|
|
||||||
case <-p.quit:
|
|
||||||
finish <- 1
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore terminal state and close pool
|
|
||||||
func (p *Pool) Stop() error {
|
|
||||||
// Wait until one final refresh has passed.
|
|
||||||
time.Sleep(p.RefreshRate)
|
|
||||||
|
|
||||||
p.finishOnce.Do(func() {
|
|
||||||
close(p.quit)
|
|
||||||
})
|
|
||||||
return unlockEcho()
|
|
||||||
}
|
|
45
vendor/github.com/cheggaaa/pb/pool_win.go
generated
vendored
45
vendor/github.com/cheggaaa/pb/pool_win.go
generated
vendored
@ -1,45 +0,0 @@
|
|||||||
// +build windows
|
|
||||||
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (p *Pool) print(first bool) bool {
|
|
||||||
p.m.Lock()
|
|
||||||
defer p.m.Unlock()
|
|
||||||
var out string
|
|
||||||
if !first {
|
|
||||||
coords, err := getCursorPos()
|
|
||||||
if err != nil {
|
|
||||||
log.Panic(err)
|
|
||||||
}
|
|
||||||
coords.Y -= int16(p.lastBarsCount)
|
|
||||||
if coords.Y < 0 {
|
|
||||||
coords.Y = 0
|
|
||||||
}
|
|
||||||
coords.X = 0
|
|
||||||
|
|
||||||
err = setCursorPos(coords)
|
|
||||||
if err != nil {
|
|
||||||
log.Panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isFinished := true
|
|
||||||
for _, bar := range p.bars {
|
|
||||||
if !bar.IsFinished() {
|
|
||||||
isFinished = false
|
|
||||||
}
|
|
||||||
bar.Update()
|
|
||||||
out += fmt.Sprintf("\r%s\n", bar.String())
|
|
||||||
}
|
|
||||||
if p.Output != nil {
|
|
||||||
fmt.Fprint(p.Output, out)
|
|
||||||
} else {
|
|
||||||
fmt.Print(out)
|
|
||||||
}
|
|
||||||
p.lastBarsCount = len(p.bars)
|
|
||||||
return isFinished
|
|
||||||
}
|
|
29
vendor/github.com/cheggaaa/pb/pool_x.go
generated
vendored
29
vendor/github.com/cheggaaa/pb/pool_x.go
generated
vendored
@ -1,29 +0,0 @@
|
|||||||
// +build linux darwin freebsd netbsd openbsd solaris dragonfly
|
|
||||||
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func (p *Pool) print(first bool) bool {
|
|
||||||
p.m.Lock()
|
|
||||||
defer p.m.Unlock()
|
|
||||||
var out string
|
|
||||||
if !first {
|
|
||||||
out = fmt.Sprintf("\033[%dA", p.lastBarsCount)
|
|
||||||
}
|
|
||||||
isFinished := true
|
|
||||||
for _, bar := range p.bars {
|
|
||||||
if !bar.IsFinished() {
|
|
||||||
isFinished = false
|
|
||||||
}
|
|
||||||
bar.Update()
|
|
||||||
out += fmt.Sprintf("\r%s\n", bar.String())
|
|
||||||
}
|
|
||||||
if p.Output != nil {
|
|
||||||
fmt.Fprint(p.Output, out)
|
|
||||||
} else {
|
|
||||||
fmt.Print(out)
|
|
||||||
}
|
|
||||||
p.lastBarsCount = len(p.bars)
|
|
||||||
return isFinished
|
|
||||||
}
|
|
25
vendor/github.com/cheggaaa/pb/reader.go
generated
vendored
25
vendor/github.com/cheggaaa/pb/reader.go
generated
vendored
@ -1,25 +0,0 @@
|
|||||||
package pb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
// It's proxy reader, implement io.Reader
|
|
||||||
type Reader struct {
|
|
||||||
io.Reader
|
|
||||||
bar *ProgressBar
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Reader) Read(p []byte) (n int, err error) {
|
|
||||||
n, err = r.Reader.Read(p)
|
|
||||||
r.bar.Add(n)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the reader when it implements io.Closer
|
|
||||||
func (r *Reader) Close() (err error) {
|
|
||||||
if closer, ok := r.Reader.(io.Closer); ok {
|
|
||||||
return closer.Close()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
17
vendor/github.com/cheggaaa/pb/runecount.go
generated
vendored
17
vendor/github.com/cheggaaa/pb/runecount.go
generated
vendored
@ -1,17 +0,0 @@
|
|||||||
package pb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/mattn/go-runewidth"
|
|
||||||
"regexp"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Finds the control character sequences (like colors)
|
|
||||||
var ctrlFinder = regexp.MustCompile("\x1b\x5b[0-9]+\x6d")
|
|
||||||
|
|
||||||
func escapeAwareRuneCountInString(s string) int {
|
|
||||||
n := runewidth.StringWidth(s)
|
|
||||||
for _, sm := range ctrlFinder.FindAllString(s, -1) {
|
|
||||||
n -= runewidth.StringWidth(sm)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
9
vendor/github.com/cheggaaa/pb/termios_bsd.go
generated
vendored
9
vendor/github.com/cheggaaa/pb/termios_bsd.go
generated
vendored
@ -1,9 +0,0 @@
|
|||||||
// +build darwin freebsd netbsd openbsd dragonfly
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import "syscall"
|
|
||||||
|
|
||||||
const ioctlReadTermios = syscall.TIOCGETA
|
|
||||||
const ioctlWriteTermios = syscall.TIOCSETA
|
|
13
vendor/github.com/cheggaaa/pb/termios_sysv.go
generated
vendored
13
vendor/github.com/cheggaaa/pb/termios_sysv.go
generated
vendored
@ -1,13 +0,0 @@
|
|||||||
// Copyright 2013 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build linux solaris
|
|
||||||
// +build !appengine
|
|
||||||
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
|
||||||
|
|
||||||
const ioctlReadTermios = unix.TCGETS
|
|
||||||
const ioctlWriteTermios = unix.TCSETS
|
|
12
vendor/github.com/chmduquesne/rollinghash/.travis.yml
generated
vendored
Normal file
12
vendor/github.com/chmduquesne/rollinghash/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
language: go
|
||||||
|
go:
|
||||||
|
- "1.10"
|
||||||
|
- "1.9"
|
||||||
|
- "1.8"
|
||||||
|
- "1.7"
|
||||||
|
before_install:
|
||||||
|
- go get github.com/mattn/goveralls
|
||||||
|
script:
|
||||||
|
- go test -v ./...
|
||||||
|
- go test -bench=. ./...
|
||||||
|
- $HOME/gopath/bin/goveralls -package=./... -service=travis-ci
|
120
vendor/github.com/chmduquesne/rollinghash/README.md
generated
vendored
Normal file
120
vendor/github.com/chmduquesne/rollinghash/README.md
generated
vendored
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
[![Build Status](https://travis-ci.org/chmduquesne/rollinghash.svg?branch=master)](https://travis-ci.org/chmduquesne/rollinghash)
|
||||||
|
[![Coverage Status](https://coveralls.io/repos/github/chmduquesne/rollinghash/badge.svg?branch=master)](https://coveralls.io/github/chmduquesne/rollinghash?branch=master)
|
||||||
|
[![GoDoc Reference](http://godoc.org/github.com/chmduquesne/rollinghash?status.svg)](https://godoc.org/github.com/chmduquesne/rollinghash)
|
||||||
|
![Go 1.7+](https://img.shields.io/badge/go-1.7%2B-orange.svg)
|
||||||
|
|
||||||
|
Rolling Hashes
|
||||||
|
==============
|
||||||
|
|
||||||
|
Philosophy
|
||||||
|
----------
|
||||||
|
|
||||||
|
This package contains several various rolling hashes for you to play with
|
||||||
|
crazy ideas. The API design philosophy is to stick as closely as possible
|
||||||
|
to the interface provided by the builtin hash package (the hashes
|
||||||
|
implemented here are effectively drop-in replacements for their builtin
|
||||||
|
counterparts), while providing simultaneously the highest speed and
|
||||||
|
simplicity.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
A [`rollinghash.Hash`](https://godoc.org/github.com/chmduquesne/rollinghash#Hash)
|
||||||
|
is just a [`hash.Hash`](https://golang.org/pkg/hash/#Hash) which
|
||||||
|
implements the
|
||||||
|
[`Roller`](https://godoc.org/github.com/chmduquesne/rollinghash#Roller)
|
||||||
|
interface. Here is how it is typically used:
|
||||||
|
|
||||||
|
```golang
|
||||||
|
data := []byte("here is some data to roll on")
|
||||||
|
h := buzhash64.New()
|
||||||
|
n := 16
|
||||||
|
|
||||||
|
// Initialize the rolling window
|
||||||
|
h.Write(data[:n])
|
||||||
|
|
||||||
|
for _, c := range(data[n:]) {
|
||||||
|
|
||||||
|
// Slide the window and update the hash
|
||||||
|
h.Roll(c)
|
||||||
|
|
||||||
|
// Get the updated hash value
|
||||||
|
fmt.Println(h.Sum64())
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Gotchas
|
||||||
|
-------
|
||||||
|
|
||||||
|
The rolling window MUST be initialized by calling `Write` first (which
|
||||||
|
saves a copy). The byte leaving the rolling window is inferred from the
|
||||||
|
internal copy of the rolling window, which is updated with every call to
|
||||||
|
`Roll`.
|
||||||
|
|
||||||
|
If you want your code to run at the highest speed, do NOT cast the result
|
||||||
|
of a `New()` as a rollinghash.Hash. Instead, use the native type returned
|
||||||
|
by `New()`. This is because the go compiler cannot inline calls from an
|
||||||
|
interface. When later you call Roll(), the native type call will be
|
||||||
|
inlined by the compiler, but not the casted type call.
|
||||||
|
|
||||||
|
```golang
|
||||||
|
var h1 rollinghash.Hash
|
||||||
|
h1 = buzhash32.New()
|
||||||
|
h2 := buzhash32.New()
|
||||||
|
|
||||||
|
[...]
|
||||||
|
|
||||||
|
h1.Roll(b) // Not inlined (slow)
|
||||||
|
h2.Roll(b) // inlined (fast)
|
||||||
|
```
|
||||||
|
|
||||||
|
What's new in v4
|
||||||
|
----------------
|
||||||
|
|
||||||
|
In v4:
|
||||||
|
|
||||||
|
* `Write` has become fully consistent with `hash.Hash`. As opposed to
|
||||||
|
previous versions, where writing data would reinitialize the window, it
|
||||||
|
now appends this data to the existing window. In order to reset the
|
||||||
|
window, one should instead use the `Reset` method.
|
||||||
|
|
||||||
|
* Calling `Roll` on an empty window is considered a bug, and now triggers
|
||||||
|
a panic.
|
||||||
|
|
||||||
|
Brief reminder of the behaviors in previous versions:
|
||||||
|
|
||||||
|
* From v0.x.x to v2.x.x: `Roll` returns an error for an empty window.
|
||||||
|
`Write` reinitializes the rolling window.
|
||||||
|
|
||||||
|
* v3.x.x : `Roll` does not return anything. `Write` still reinitializes
|
||||||
|
the rolling window. The rolling window always has a minimum size of 1,
|
||||||
|
which yields wrong results when using roll before having initialized the
|
||||||
|
window.
|
||||||
|
|
||||||
|
Go versions
|
||||||
|
-----------
|
||||||
|
|
||||||
|
The `RabinKarp64` rollinghash does not yield consistent results before
|
||||||
|
go1.7. This is because it uses `Rand.Read()` from the builtin `math/rand`.
|
||||||
|
This function was [fixed in go
|
||||||
|
1.7](https://golang.org/doc/go1.7#math_rand) to produce a consistent
|
||||||
|
stream of bytes that is independant of the size of the input buffer. If
|
||||||
|
you depend on this hash, it is strongly recommended to stick to versions
|
||||||
|
of go superior to 1.7.
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
This code is delivered to you under the terms of the MIT public license,
|
||||||
|
except the `rabinkarp64` subpackage, which has been adapted from
|
||||||
|
[restic](https://github.com/restic/chunker) (BSD 2-clause "Simplified").
|
||||||
|
|
||||||
|
Notable users
|
||||||
|
-------------
|
||||||
|
|
||||||
|
* [syncthing](https://syncthing.net/), a decentralized synchronisation
|
||||||
|
solution
|
||||||
|
* [muscato](https://github.com/kshedden/muscato), a genome analysis tool
|
||||||
|
|
||||||
|
If you are using this in production or for research, let me know and I
|
||||||
|
will happily put a link here!
|
140
vendor/github.com/chmduquesne/rollinghash/roll/main.go
generated
vendored
140
vendor/github.com/chmduquesne/rollinghash/roll/main.go
generated
vendored
@ -1,140 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"hash"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"runtime/pprof"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"code.cloudfoundry.org/bytefmt"
|
|
||||||
//rollsum "github.com/chmduquesne/rollinghash/adler32"
|
|
||||||
//rollsum "github.com/chmduquesne/rollinghash/buzhash32"
|
|
||||||
rollsum "github.com/chmduquesne/rollinghash/buzhash64"
|
|
||||||
//rollsum "github.com/chmduquesne/rollinghash/bozo32"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
KiB = 1024
|
|
||||||
MiB = 1024 * KiB
|
|
||||||
GiB = 1024 * MiB
|
|
||||||
|
|
||||||
clearscreen = "\033[2J\033[1;1H"
|
|
||||||
clearline = "\x1b[2K"
|
|
||||||
)
|
|
||||||
|
|
||||||
func genMasks() (res []uint64) {
|
|
||||||
res = make([]uint64, 64)
|
|
||||||
ones := ^uint64(0) // 0xffffffffffffffff
|
|
||||||
for i := 0; i < 64; i++ {
|
|
||||||
res[i] = ones >> uint(63-i)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the hash sum as a uint64
|
|
||||||
func sum64(h hash.Hash) (res uint64) {
|
|
||||||
buf := make([]byte, 0, 8)
|
|
||||||
s := h.Sum(buf)
|
|
||||||
for _, b := range s {
|
|
||||||
res <<= 8
|
|
||||||
res |= uint64(b)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
|
|
||||||
dostats := flag.Bool("stats", false, "Do some stats about the rolling sum")
|
|
||||||
size := flag.String("size", "256M", "How much data to read")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if *cpuprofile != "" {
|
|
||||||
f, err := os.Create(*cpuprofile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
pprof.StartCPUProfile(f)
|
|
||||||
defer pprof.StopCPUProfile()
|
|
||||||
}
|
|
||||||
|
|
||||||
fileSize, err := bytefmt.ToBytes(*size)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
bufsize := 16 * MiB
|
|
||||||
buf := make([]byte, bufsize)
|
|
||||||
t := time.Now()
|
|
||||||
|
|
||||||
f, err := os.Open("/dev/urandom")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err := f.Close(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
io.ReadFull(f, buf)
|
|
||||||
|
|
||||||
roll := rollsum.New()
|
|
||||||
roll.Write(buf[:64])
|
|
||||||
|
|
||||||
masks := genMasks()
|
|
||||||
hits := make(map[uint64]uint64)
|
|
||||||
for _, m := range masks {
|
|
||||||
hits[m] = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
n := uint64(0)
|
|
||||||
k := 0
|
|
||||||
for n < fileSize {
|
|
||||||
if k >= bufsize {
|
|
||||||
status := fmt.Sprintf("Byte count: %s", bytefmt.ByteSize(n))
|
|
||||||
if *dostats {
|
|
||||||
fmt.Printf(clearscreen)
|
|
||||||
fmt.Println(status)
|
|
||||||
for i, m := range masks {
|
|
||||||
frequency := "NaN"
|
|
||||||
if hits[m] != 0 {
|
|
||||||
frequency = bytefmt.ByteSize(n / hits[m])
|
|
||||||
}
|
|
||||||
fmt.Printf("0x%016x (%02d bits): every %s\n", m, i+1, frequency)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Printf(clearline)
|
|
||||||
fmt.Printf(status)
|
|
||||||
fmt.Printf("\r")
|
|
||||||
}
|
|
||||||
_, err := io.ReadFull(f, buf)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
k = 0
|
|
||||||
}
|
|
||||||
roll.Roll(buf[k])
|
|
||||||
if *dostats {
|
|
||||||
s := sum64(roll)
|
|
||||||
for _, m := range masks {
|
|
||||||
if s&m == m {
|
|
||||||
hits[m] += 1
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
k++
|
|
||||||
n++
|
|
||||||
}
|
|
||||||
duration := time.Since(t)
|
|
||||||
fmt.Printf("Rolled %s of data in %v (%s/s).\n",
|
|
||||||
bytefmt.ByteSize(n),
|
|
||||||
duration,
|
|
||||||
bytefmt.ByteSize(n*1e9/uint64(duration)),
|
|
||||||
)
|
|
||||||
}
|
|
1
vendor/github.com/d4l3k/messagediff/.coveralls.yml
generated
vendored
Normal file
1
vendor/github.com/d4l3k/messagediff/.coveralls.yml
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
repo_token: LWIe7rP7M3hBnAxpsMaZhrVBs2DSyhzoQ
|
24
vendor/github.com/d4l3k/messagediff/.gitignore
generated
vendored
Normal file
24
vendor/github.com/d4l3k/messagediff/.gitignore
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Folders
|
||||||
|
_obj
|
||||||
|
_test
|
||||||
|
|
||||||
|
# Architecture specific extensions/prefixes
|
||||||
|
*.[568vq]
|
||||||
|
[568vq].out
|
||||||
|
|
||||||
|
*.cgo1.go
|
||||||
|
*.cgo2.c
|
||||||
|
_cgo_defun.c
|
||||||
|
_cgo_gotypes.go
|
||||||
|
_cgo_export.*
|
||||||
|
|
||||||
|
_testmain.go
|
||||||
|
|
||||||
|
*.exe
|
||||||
|
*.test
|
||||||
|
*.prof
|
26
vendor/github.com/d4l3k/messagediff/.travis.yml
generated
vendored
Normal file
26
vendor/github.com/d4l3k/messagediff/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
language: go
|
||||||
|
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1
|
||||||
|
- 1.3
|
||||||
|
- 1.4
|
||||||
|
- 1.5
|
||||||
|
- 1.6
|
||||||
|
- 1.7.x
|
||||||
|
- 1.8.x
|
||||||
|
- tip
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
|
||||||
|
- go get github.com/axw/gocov/gocov
|
||||||
|
- go get github.com/modocache/gover
|
||||||
|
- go get github.com/mattn/goveralls
|
||||||
|
|
||||||
|
script:
|
||||||
|
- go test -v -coverprofile=example.coverprofile ./example
|
||||||
|
- go test -v -coverprofile=main.coverprofile
|
||||||
|
- $HOME/gopath/bin/gover
|
||||||
|
- $HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=gover.coverprofile
|
14
vendor/github.com/d4l3k/messagediff/CHANGELOG.md
generated
vendored
Normal file
14
vendor/github.com/d4l3k/messagediff/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
## nightly
|
||||||
|
* Added support for ignoring fields.
|
||||||
|
|
||||||
|
## v1.1.0
|
||||||
|
|
||||||
|
* Added support for recursive data structures.
|
||||||
|
* Fixed bug with embedded fixed length arrays in structs.
|
||||||
|
* Added `example/` directory.
|
||||||
|
* Minor test bug fixes for future go versions.
|
||||||
|
* Added change log.
|
||||||
|
|
||||||
|
## v1.0.0
|
||||||
|
|
||||||
|
Initial tagged release release.
|
90
vendor/github.com/d4l3k/messagediff/README.md
generated
vendored
Normal file
90
vendor/github.com/d4l3k/messagediff/README.md
generated
vendored
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
# messagediff [![Build Status](https://travis-ci.org/d4l3k/messagediff.svg?branch=master)](https://travis-ci.org/d4l3k/messagediff) [![Coverage Status](https://coveralls.io/repos/github/d4l3k/messagediff/badge.svg?branch=master)](https://coveralls.io/github/d4l3k/messagediff?branch=master) [![GoDoc](https://godoc.org/github.com/d4l3k/messagediff?status.svg)](https://godoc.org/github.com/d4l3k/messagediff)
|
||||||
|
|
||||||
|
A library for doing diffs of arbitrary Golang structs.
|
||||||
|
|
||||||
|
If the unsafe package is available messagediff will diff unexported fields in
|
||||||
|
addition to exported fields. This is primarily used for testing purposes as it
|
||||||
|
allows for providing informative error messages.
|
||||||
|
|
||||||
|
Optionally, fields in structs can be tagged as `testdiff:"ignore"` to make
|
||||||
|
messagediff skip it when doing the comparison.
|
||||||
|
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
In a normal file:
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "gopkg.in/d4l3k/messagediff.v1"
|
||||||
|
|
||||||
|
type someStruct struct {
|
||||||
|
A, b int
|
||||||
|
C []int
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
a := someStruct{1, 2, []int{1}}
|
||||||
|
b := someStruct{1, 3, []int{1, 2}}
|
||||||
|
diff, equal := messagediff.PrettyDiff(a, b)
|
||||||
|
/*
|
||||||
|
diff =
|
||||||
|
`added: .C[1] = 2
|
||||||
|
modified: .b = 3`
|
||||||
|
|
||||||
|
equal = false
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
In a test:
|
||||||
|
```go
|
||||||
|
import "gopkg.in/d4l3k/messagediff.v1"
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
type someStruct struct {
|
||||||
|
A, b int
|
||||||
|
C []int
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSomething(t *testing.T) {
|
||||||
|
want := someStruct{1, 2, []int{1}}
|
||||||
|
got := someStruct{1, 3, []int{1, 2}}
|
||||||
|
if diff, equal := messagediff.PrettyDiff(want, got); !equal {
|
||||||
|
t.Errorf("Something() = %#v\n%s", got, diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
To ignore a field in a struct, just annotate it with testdiff:"ignore" like
|
||||||
|
this:
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "gopkg.in/d4l3k/messagediff.v1"
|
||||||
|
|
||||||
|
type someStruct struct {
|
||||||
|
A int
|
||||||
|
B int `testdiff:"ignore"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
a := someStruct{1, 2}
|
||||||
|
b := someStruct{1, 3}
|
||||||
|
diff, equal := messagediff.PrettyDiff(a, b)
|
||||||
|
/*
|
||||||
|
equal = true
|
||||||
|
diff = ""
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the `DeepDiff` function for using the diff results programmatically.
|
||||||
|
|
||||||
|
## License
|
||||||
|
Copyright (c) 2015 [Tristan Rice](https://fn.lc) <rice@fn.lc>
|
||||||
|
|
||||||
|
messagediff is licensed under the MIT license. See the LICENSE file for more information.
|
||||||
|
|
||||||
|
bypass.go and bypasssafe.go are borrowed from
|
||||||
|
[go-spew](https://github.com/davecgh/go-spew) and have a seperate copyright
|
||||||
|
notice.
|
1
vendor/github.com/d4l3k/messagediff/example/example.go
generated
vendored
1
vendor/github.com/d4l3k/messagediff/example/example.go
generated
vendored
@ -1 +0,0 @@
|
|||||||
package examples
|
|
21
vendor/github.com/dustin/go-humanize/LICENSE
generated
vendored
21
vendor/github.com/dustin/go-humanize/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
|||||||
Copyright (c) 2005-2008 Dustin Sallings <dustin@spy.net>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
<http://www.opensource.org/licenses/mit-license.php>
|
|
31
vendor/github.com/dustin/go-humanize/big.go
generated
vendored
31
vendor/github.com/dustin/go-humanize/big.go
generated
vendored
@ -1,31 +0,0 @@
|
|||||||
package humanize
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/big"
|
|
||||||
)
|
|
||||||
|
|
||||||
// order of magnitude (to a max order)
|
|
||||||
func oomm(n, b *big.Int, maxmag int) (float64, int) {
|
|
||||||
mag := 0
|
|
||||||
m := &big.Int{}
|
|
||||||
for n.Cmp(b) >= 0 {
|
|
||||||
n.DivMod(n, b, m)
|
|
||||||
mag++
|
|
||||||
if mag == maxmag && maxmag >= 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag
|
|
||||||
}
|
|
||||||
|
|
||||||
// total order of magnitude
|
|
||||||
// (same as above, but with no upper limit)
|
|
||||||
func oom(n, b *big.Int) (float64, int) {
|
|
||||||
mag := 0
|
|
||||||
m := &big.Int{}
|
|
||||||
for n.Cmp(b) >= 0 {
|
|
||||||
n.DivMod(n, b, m)
|
|
||||||
mag++
|
|
||||||
}
|
|
||||||
return float64(n.Int64()) + (float64(m.Int64()) / float64(b.Int64())), mag
|
|
||||||
}
|
|
173
vendor/github.com/dustin/go-humanize/bigbytes.go
generated
vendored
173
vendor/github.com/dustin/go-humanize/bigbytes.go
generated
vendored
@ -1,173 +0,0 @@
|
|||||||
package humanize
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math/big"
|
|
||||||
"strings"
|
|
||||||
"unicode"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
bigIECExp = big.NewInt(1024)
|
|
||||||
|
|
||||||
// BigByte is one byte in bit.Ints
|
|
||||||
BigByte = big.NewInt(1)
|
|
||||||
// BigKiByte is 1,024 bytes in bit.Ints
|
|
||||||
BigKiByte = (&big.Int{}).Mul(BigByte, bigIECExp)
|
|
||||||
// BigMiByte is 1,024 k bytes in bit.Ints
|
|
||||||
BigMiByte = (&big.Int{}).Mul(BigKiByte, bigIECExp)
|
|
||||||
// BigGiByte is 1,024 m bytes in bit.Ints
|
|
||||||
BigGiByte = (&big.Int{}).Mul(BigMiByte, bigIECExp)
|
|
||||||
// BigTiByte is 1,024 g bytes in bit.Ints
|
|
||||||
BigTiByte = (&big.Int{}).Mul(BigGiByte, bigIECExp)
|
|
||||||
// BigPiByte is 1,024 t bytes in bit.Ints
|
|
||||||
BigPiByte = (&big.Int{}).Mul(BigTiByte, bigIECExp)
|
|
||||||
// BigEiByte is 1,024 p bytes in bit.Ints
|
|
||||||
BigEiByte = (&big.Int{}).Mul(BigPiByte, bigIECExp)
|
|
||||||
// BigZiByte is 1,024 e bytes in bit.Ints
|
|
||||||
BigZiByte = (&big.Int{}).Mul(BigEiByte, bigIECExp)
|
|
||||||
// BigYiByte is 1,024 z bytes in bit.Ints
|
|
||||||
BigYiByte = (&big.Int{}).Mul(BigZiByte, bigIECExp)
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
bigSIExp = big.NewInt(1000)
|
|
||||||
|
|
||||||
// BigSIByte is one SI byte in big.Ints
|
|
||||||
BigSIByte = big.NewInt(1)
|
|
||||||
// BigKByte is 1,000 SI bytes in big.Ints
|
|
||||||
BigKByte = (&big.Int{}).Mul(BigSIByte, bigSIExp)
|
|
||||||
// BigMByte is 1,000 SI k bytes in big.Ints
|
|
||||||
BigMByte = (&big.Int{}).Mul(BigKByte, bigSIExp)
|
|
||||||
// BigGByte is 1,000 SI m bytes in big.Ints
|
|
||||||
BigGByte = (&big.Int{}).Mul(BigMByte, bigSIExp)
|
|
||||||
// BigTByte is 1,000 SI g bytes in big.Ints
|
|
||||||
BigTByte = (&big.Int{}).Mul(BigGByte, bigSIExp)
|
|
||||||
// BigPByte is 1,000 SI t bytes in big.Ints
|
|
||||||
BigPByte = (&big.Int{}).Mul(BigTByte, bigSIExp)
|
|
||||||
// BigEByte is 1,000 SI p bytes in big.Ints
|
|
||||||
BigEByte = (&big.Int{}).Mul(BigPByte, bigSIExp)
|
|
||||||
// BigZByte is 1,000 SI e bytes in big.Ints
|
|
||||||
BigZByte = (&big.Int{}).Mul(BigEByte, bigSIExp)
|
|
||||||
// BigYByte is 1,000 SI z bytes in big.Ints
|
|
||||||
BigYByte = (&big.Int{}).Mul(BigZByte, bigSIExp)
|
|
||||||
)
|
|
||||||
|
|
||||||
var bigBytesSizeTable = map[string]*big.Int{
|
|
||||||
"b": BigByte,
|
|
||||||
"kib": BigKiByte,
|
|
||||||
"kb": BigKByte,
|
|
||||||
"mib": BigMiByte,
|
|
||||||
"mb": BigMByte,
|
|
||||||
"gib": BigGiByte,
|
|
||||||
"gb": BigGByte,
|
|
||||||
"tib": BigTiByte,
|
|
||||||
"tb": BigTByte,
|
|
||||||
"pib": BigPiByte,
|
|
||||||
"pb": BigPByte,
|
|
||||||
"eib": BigEiByte,
|
|
||||||
"eb": BigEByte,
|
|
||||||
"zib": BigZiByte,
|
|
||||||
"zb": BigZByte,
|
|
||||||
"yib": BigYiByte,
|
|
||||||
"yb": BigYByte,
|
|
||||||
// Without suffix
|
|
||||||
"": BigByte,
|
|
||||||
"ki": BigKiByte,
|
|
||||||
"k": BigKByte,
|
|
||||||
"mi": BigMiByte,
|
|
||||||
"m": BigMByte,
|
|
||||||
"gi": BigGiByte,
|
|
||||||
"g": BigGByte,
|
|
||||||
"ti": BigTiByte,
|
|
||||||
"t": BigTByte,
|
|
||||||
"pi": BigPiByte,
|
|
||||||
"p": BigPByte,
|
|
||||||
"ei": BigEiByte,
|
|
||||||
"e": BigEByte,
|
|
||||||
"z": BigZByte,
|
|
||||||
"zi": BigZiByte,
|
|
||||||
"y": BigYByte,
|
|
||||||
"yi": BigYiByte,
|
|
||||||
}
|
|
||||||
|
|
||||||
var ten = big.NewInt(10)
|
|
||||||
|
|
||||||
func humanateBigBytes(s, base *big.Int, sizes []string) string {
|
|
||||||
if s.Cmp(ten) < 0 {
|
|
||||||
return fmt.Sprintf("%d B", s)
|
|
||||||
}
|
|
||||||
c := (&big.Int{}).Set(s)
|
|
||||||
val, mag := oomm(c, base, len(sizes)-1)
|
|
||||||
suffix := sizes[mag]
|
|
||||||
f := "%.0f %s"
|
|
||||||
if val < 10 {
|
|
||||||
f = "%.1f %s"
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf(f, val, suffix)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// BigBytes produces a human readable representation of an SI size.
|
|
||||||
//
|
|
||||||
// See also: ParseBigBytes.
|
|
||||||
//
|
|
||||||
// BigBytes(82854982) -> 83 MB
|
|
||||||
func BigBytes(s *big.Int) string {
|
|
||||||
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
|
|
||||||
return humanateBigBytes(s, bigSIExp, sizes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BigIBytes produces a human readable representation of an IEC size.
|
|
||||||
//
|
|
||||||
// See also: ParseBigBytes.
|
|
||||||
//
|
|
||||||
// BigIBytes(82854982) -> 79 MiB
|
|
||||||
func BigIBytes(s *big.Int) string {
|
|
||||||
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
|
|
||||||
return humanateBigBytes(s, bigIECExp, sizes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseBigBytes parses a string representation of bytes into the number
|
|
||||||
// of bytes it represents.
|
|
||||||
//
|
|
||||||
// See also: BigBytes, BigIBytes.
|
|
||||||
//
|
|
||||||
// ParseBigBytes("42 MB") -> 42000000, nil
|
|
||||||
// ParseBigBytes("42 mib") -> 44040192, nil
|
|
||||||
func ParseBigBytes(s string) (*big.Int, error) {
|
|
||||||
lastDigit := 0
|
|
||||||
hasComma := false
|
|
||||||
for _, r := range s {
|
|
||||||
if !(unicode.IsDigit(r) || r == '.' || r == ',') {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if r == ',' {
|
|
||||||
hasComma = true
|
|
||||||
}
|
|
||||||
lastDigit++
|
|
||||||
}
|
|
||||||
|
|
||||||
num := s[:lastDigit]
|
|
||||||
if hasComma {
|
|
||||||
num = strings.Replace(num, ",", "", -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
val := &big.Rat{}
|
|
||||||
_, err := fmt.Sscanf(num, "%f", val)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
extra := strings.ToLower(strings.TrimSpace(s[lastDigit:]))
|
|
||||||
if m, ok := bigBytesSizeTable[extra]; ok {
|
|
||||||
mv := (&big.Rat{}).SetInt(m)
|
|
||||||
val.Mul(val, mv)
|
|
||||||
rv := &big.Int{}
|
|
||||||
rv.Div(val.Num(), val.Denom())
|
|
||||||
return rv, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("unhandled size name: %v", extra)
|
|
||||||
}
|
|
143
vendor/github.com/dustin/go-humanize/bytes.go
generated
vendored
143
vendor/github.com/dustin/go-humanize/bytes.go
generated
vendored
@ -1,143 +0,0 @@
|
|||||||
package humanize
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"unicode"
|
|
||||||
)
|
|
||||||
|
|
||||||
// IEC Sizes.
|
|
||||||
// kibis of bits
|
|
||||||
const (
|
|
||||||
Byte = 1 << (iota * 10)
|
|
||||||
KiByte
|
|
||||||
MiByte
|
|
||||||
GiByte
|
|
||||||
TiByte
|
|
||||||
PiByte
|
|
||||||
EiByte
|
|
||||||
)
|
|
||||||
|
|
||||||
// SI Sizes.
|
|
||||||
const (
|
|
||||||
IByte = 1
|
|
||||||
KByte = IByte * 1000
|
|
||||||
MByte = KByte * 1000
|
|
||||||
GByte = MByte * 1000
|
|
||||||
TByte = GByte * 1000
|
|
||||||
PByte = TByte * 1000
|
|
||||||
EByte = PByte * 1000
|
|
||||||
)
|
|
||||||
|
|
||||||
var bytesSizeTable = map[string]uint64{
|
|
||||||
"b": Byte,
|
|
||||||
"kib": KiByte,
|
|
||||||
"kb": KByte,
|
|
||||||
"mib": MiByte,
|
|
||||||
"mb": MByte,
|
|
||||||
"gib": GiByte,
|
|
||||||
"gb": GByte,
|
|
||||||
"tib": TiByte,
|
|
||||||
"tb": TByte,
|
|
||||||
"pib": PiByte,
|
|
||||||
"pb": PByte,
|
|
||||||
"eib": EiByte,
|
|
||||||
"eb": EByte,
|
|
||||||
// Without suffix
|
|
||||||
"": Byte,
|
|
||||||
"ki": KiByte,
|
|
||||||
"k": KByte,
|
|
||||||
"mi": MiByte,
|
|
||||||
"m": MByte,
|
|
||||||
"gi": GiByte,
|
|
||||||
"g": GByte,
|
|
||||||
"ti": TiByte,
|
|
||||||
"t": TByte,
|
|
||||||
"pi": PiByte,
|
|
||||||
"p": PByte,
|
|
||||||
"ei": EiByte,
|
|
||||||
"e": EByte,
|
|
||||||
}
|
|
||||||
|
|
||||||
func logn(n, b float64) float64 {
|
|
||||||
return math.Log(n) / math.Log(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func humanateBytes(s uint64, base float64, sizes []string) string {
|
|
||||||
if s < 10 {
|
|
||||||
return fmt.Sprintf("%d B", s)
|
|
||||||
}
|
|
||||||
e := math.Floor(logn(float64(s), base))
|
|
||||||
suffix := sizes[int(e)]
|
|
||||||
val := math.Floor(float64(s)/math.Pow(base, e)*10+0.5) / 10
|
|
||||||
f := "%.0f %s"
|
|
||||||
if val < 10 {
|
|
||||||
f = "%.1f %s"
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf(f, val, suffix)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bytes produces a human readable representation of an SI size.
|
|
||||||
//
|
|
||||||
// See also: ParseBytes.
|
|
||||||
//
|
|
||||||
// Bytes(82854982) -> 83 MB
|
|
||||||
func Bytes(s uint64) string {
|
|
||||||
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"}
|
|
||||||
return humanateBytes(s, 1000, sizes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IBytes produces a human readable representation of an IEC size.
|
|
||||||
//
|
|
||||||
// See also: ParseBytes.
|
|
||||||
//
|
|
||||||
// IBytes(82854982) -> 79 MiB
|
|
||||||
func IBytes(s uint64) string {
|
|
||||||
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}
|
|
||||||
return humanateBytes(s, 1024, sizes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseBytes parses a string representation of bytes into the number
|
|
||||||
// of bytes it represents.
|
|
||||||
//
|
|
||||||
// See Also: Bytes, IBytes.
|
|
||||||
//
|
|
||||||
// ParseBytes("42 MB") -> 42000000, nil
|
|
||||||
// ParseBytes("42 mib") -> 44040192, nil
|
|
||||||
func ParseBytes(s string) (uint64, error) {
|
|
||||||
lastDigit := 0
|
|
||||||
hasComma := false
|
|
||||||
for _, r := range s {
|
|
||||||
if !(unicode.IsDigit(r) || r == '.' || r == ',') {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if r == ',' {
|
|
||||||
hasComma = true
|
|
||||||
}
|
|
||||||
lastDigit++
|
|
||||||
}
|
|
||||||
|
|
||||||
num := s[:lastDigit]
|
|
||||||
if hasComma {
|
|
||||||
num = strings.Replace(num, ",", "", -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := strconv.ParseFloat(num, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
extra := strings.ToLower(strings.TrimSpace(s[lastDigit:]))
|
|
||||||
if m, ok := bytesSizeTable[extra]; ok {
|
|
||||||
f *= float64(m)
|
|
||||||
if f >= math.MaxUint64 {
|
|
||||||
return 0, fmt.Errorf("too large: %v", s)
|
|
||||||
}
|
|
||||||
return uint64(f), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0, fmt.Errorf("unhandled size name: %v", extra)
|
|
||||||
}
|
|
108
vendor/github.com/dustin/go-humanize/comma.go
generated
vendored
108
vendor/github.com/dustin/go-humanize/comma.go
generated
vendored
@ -1,108 +0,0 @@
|
|||||||
package humanize
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"math"
|
|
||||||
"math/big"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Comma produces a string form of the given number in base 10 with
|
|
||||||
// commas after every three orders of magnitude.
|
|
||||||
//
|
|
||||||
// e.g. Comma(834142) -> 834,142
|
|
||||||
func Comma(v int64) string {
|
|
||||||
sign := ""
|
|
||||||
|
|
||||||
// Min int64 can't be negated to a usable value, so it has to be special cased.
|
|
||||||
if v == math.MinInt64 {
|
|
||||||
return "-9,223,372,036,854,775,808"
|
|
||||||
}
|
|
||||||
|
|
||||||
if v < 0 {
|
|
||||||
sign = "-"
|
|
||||||
v = 0 - v
|
|
||||||
}
|
|
||||||
|
|
||||||
parts := []string{"", "", "", "", "", "", ""}
|
|
||||||
j := len(parts) - 1
|
|
||||||
|
|
||||||
for v > 999 {
|
|
||||||
parts[j] = strconv.FormatInt(v%1000, 10)
|
|
||||||
switch len(parts[j]) {
|
|
||||||
case 2:
|
|
||||||
parts[j] = "0" + parts[j]
|
|
||||||
case 1:
|
|
||||||
parts[j] = "00" + parts[j]
|
|
||||||
}
|
|
||||||
v = v / 1000
|
|
||||||
j--
|
|
||||||
}
|
|
||||||
parts[j] = strconv.Itoa(int(v))
|
|
||||||
return sign + strings.Join(parts[j:], ",")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commaf produces a string form of the given number in base 10 with
|
|
||||||
// commas after every three orders of magnitude.
|
|
||||||
//
|
|
||||||
// e.g. Commaf(834142.32) -> 834,142.32
|
|
||||||
func Commaf(v float64) string {
|
|
||||||
buf := &bytes.Buffer{}
|
|
||||||
if v < 0 {
|
|
||||||
buf.Write([]byte{'-'})
|
|
||||||
v = 0 - v
|
|
||||||
}
|
|
||||||
|
|
||||||
comma := []byte{','}
|
|
||||||
|
|
||||||
parts := strings.Split(strconv.FormatFloat(v, 'f', -1, 64), ".")
|
|
||||||
pos := 0
|
|
||||||
if len(parts[0])%3 != 0 {
|
|
||||||
pos += len(parts[0]) % 3
|
|
||||||
buf.WriteString(parts[0][:pos])
|
|
||||||
buf.Write(comma)
|
|
||||||
}
|
|
||||||
for ; pos < len(parts[0]); pos += 3 {
|
|
||||||
buf.WriteString(parts[0][pos : pos+3])
|
|
||||||
buf.Write(comma)
|
|
||||||
}
|
|
||||||
buf.Truncate(buf.Len() - 1)
|
|
||||||
|
|
||||||
if len(parts) > 1 {
|
|
||||||
buf.Write([]byte{'.'})
|
|
||||||
buf.WriteString(parts[1])
|
|
||||||
}
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// BigComma produces a string form of the given big.Int in base 10
|
|
||||||
// with commas after every three orders of magnitude.
|
|
||||||
func BigComma(b *big.Int) string {
|
|
||||||
sign := ""
|
|
||||||
if b.Sign() < 0 {
|
|
||||||
sign = "-"
|
|
||||||
b.Abs(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
athousand := big.NewInt(1000)
|
|
||||||
c := (&big.Int{}).Set(b)
|
|
||||||
_, m := oom(c, athousand)
|
|
||||||
parts := make([]string, m+1)
|
|
||||||
j := len(parts) - 1
|
|
||||||
|
|
||||||
mod := &big.Int{}
|
|
||||||
for b.Cmp(athousand) >= 0 {
|
|
||||||
b.DivMod(b, athousand, mod)
|
|
||||||
parts[j] = strconv.FormatInt(mod.Int64(), 10)
|
|
||||||
switch len(parts[j]) {
|
|
||||||
case 2:
|
|
||||||
parts[j] = "0" + parts[j]
|
|
||||||
case 1:
|
|
||||||
parts[j] = "00" + parts[j]
|
|
||||||
}
|
|
||||||
j--
|
|
||||||
}
|
|
||||||
parts[j] = strconv.Itoa(int(b.Int64()))
|
|
||||||
return sign + strings.Join(parts[j:], ",")
|
|
||||||
}
|
|
40
vendor/github.com/dustin/go-humanize/commaf.go
generated
vendored
40
vendor/github.com/dustin/go-humanize/commaf.go
generated
vendored
@ -1,40 +0,0 @@
|
|||||||
// +build go1.6
|
|
||||||
|
|
||||||
package humanize
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"math/big"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// BigCommaf produces a string form of the given big.Float in base 10
|
|
||||||
// with commas after every three orders of magnitude.
|
|
||||||
func BigCommaf(v *big.Float) string {
|
|
||||||
buf := &bytes.Buffer{}
|
|
||||||
if v.Sign() < 0 {
|
|
||||||
buf.Write([]byte{'-'})
|
|
||||||
v.Abs(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
comma := []byte{','}
|
|
||||||
|
|
||||||
parts := strings.Split(v.Text('f', -1), ".")
|
|
||||||
pos := 0
|
|
||||||
if len(parts[0])%3 != 0 {
|
|
||||||
pos += len(parts[0]) % 3
|
|
||||||
buf.WriteString(parts[0][:pos])
|
|
||||||
buf.Write(comma)
|
|
||||||
}
|
|
||||||
for ; pos < len(parts[0]); pos += 3 {
|
|
||||||
buf.WriteString(parts[0][pos : pos+3])
|
|
||||||
buf.Write(comma)
|
|
||||||
}
|
|
||||||
buf.Truncate(buf.Len() - 1)
|
|
||||||
|
|
||||||
if len(parts) > 1 {
|
|
||||||
buf.Write([]byte{'.'})
|
|
||||||
buf.WriteString(parts[1])
|
|
||||||
}
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
96
vendor/github.com/dustin/go-humanize/english/words.go
generated
vendored
96
vendor/github.com/dustin/go-humanize/english/words.go
generated
vendored
@ -1,96 +0,0 @@
|
|||||||
// Package english provides utilities to generate more user-friendly English output.
|
|
||||||
package english
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// These are included because they are common technical terms.
|
|
||||||
var specialPlurals = map[string]string{
|
|
||||||
"index": "indices",
|
|
||||||
"matrix": "matrices",
|
|
||||||
"vertex": "vertices",
|
|
||||||
}
|
|
||||||
|
|
||||||
var sibilantEndings = []string{"s", "sh", "tch", "x"}
|
|
||||||
|
|
||||||
var isVowel = map[byte]bool{
|
|
||||||
'A': true, 'E': true, 'I': true, 'O': true, 'U': true,
|
|
||||||
'a': true, 'e': true, 'i': true, 'o': true, 'u': true,
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluralWord builds the plural form of an English word.
|
|
||||||
// The simple English rules of regular pluralization will be used
|
|
||||||
// if the plural form is an empty string (i.e. not explicitly given).
|
|
||||||
// The special cases are not guaranteed to work for strings outside ASCII.
|
|
||||||
func PluralWord(quantity int, singular, plural string) string {
|
|
||||||
if quantity == 1 {
|
|
||||||
return singular
|
|
||||||
}
|
|
||||||
if plural != "" {
|
|
||||||
return plural
|
|
||||||
}
|
|
||||||
if plural = specialPlurals[singular]; plural != "" {
|
|
||||||
return plural
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to guess what the English plural might be. Keep this
|
|
||||||
// function simple! It doesn't need to know about every possiblity;
|
|
||||||
// only regular rules and the most common special cases.
|
|
||||||
//
|
|
||||||
// Reference: http://en.wikipedia.org/wiki/English_plural
|
|
||||||
|
|
||||||
for _, ending := range sibilantEndings {
|
|
||||||
if strings.HasSuffix(singular, ending) {
|
|
||||||
return singular + "es"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
l := len(singular)
|
|
||||||
if l >= 2 && singular[l-1] == 'o' && !isVowel[singular[l-2]] {
|
|
||||||
return singular + "es"
|
|
||||||
}
|
|
||||||
if l >= 2 && singular[l-1] == 'y' && !isVowel[singular[l-2]] {
|
|
||||||
return singular[:l-1] + "ies"
|
|
||||||
}
|
|
||||||
|
|
||||||
return singular + "s"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Plural formats an integer and a string into a single pluralized string.
|
|
||||||
// The simple English rules of regular pluralization will be used
|
|
||||||
// if the plural form is an empty string (i.e. not explicitly given).
|
|
||||||
func Plural(quantity int, singular, plural string) string {
|
|
||||||
return fmt.Sprintf("%d %s", quantity, PluralWord(quantity, singular, plural))
|
|
||||||
}
|
|
||||||
|
|
||||||
// WordSeries converts a list of words into a word series in English.
|
|
||||||
// It returns a string containing all the given words separated by commas,
|
|
||||||
// the coordinating conjunction, and a serial comma, as appropriate.
|
|
||||||
func WordSeries(words []string, conjunction string) string {
|
|
||||||
switch len(words) {
|
|
||||||
case 0:
|
|
||||||
return ""
|
|
||||||
case 1:
|
|
||||||
return words[0]
|
|
||||||
default:
|
|
||||||
return fmt.Sprintf("%s %s %s", strings.Join(words[:len(words)-1], ", "), conjunction, words[len(words)-1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OxfordWordSeries converts a list of words into a word series in English,
|
|
||||||
// using an Oxford comma (https://en.wikipedia.org/wiki/Serial_comma). It
|
|
||||||
// returns a string containing all the given words separated by commas, the
|
|
||||||
// coordinating conjunction, and a serial comma, as appropriate.
|
|
||||||
func OxfordWordSeries(words []string, conjunction string) string {
|
|
||||||
switch len(words) {
|
|
||||||
case 0:
|
|
||||||
return ""
|
|
||||||
case 1:
|
|
||||||
return words[0]
|
|
||||||
case 2:
|
|
||||||
return strings.Join(words, fmt.Sprintf(" %s ", conjunction))
|
|
||||||
default:
|
|
||||||
return fmt.Sprintf("%s, %s %s", strings.Join(words[:len(words)-1], ", "), conjunction, words[len(words)-1])
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user