├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── api.go
├── examples
├── empty.yml
├── minimal.yml
└── override.yml
├── glide.lock
├── glide.yaml
├── gomake
├── gomake.cfg
├── main.go
├── scripts
├── glide-update
└── glide-vendor-cleanup.sh
├── storage.go
├── templates
└── index.html
├── vendor
├── github.com
│ ├── appc
│ │ └── spec
│ │ │ ├── LICENSE
│ │ │ ├── aci
│ │ │ ├── build.go
│ │ │ ├── doc.go
│ │ │ ├── file.go
│ │ │ ├── layout.go
│ │ │ └── writer.go
│ │ │ ├── pkg
│ │ │ ├── device
│ │ │ │ ├── device_linux.go
│ │ │ │ └── device_posix.go
│ │ │ └── tarheader
│ │ │ │ ├── doc.go
│ │ │ │ ├── pop_darwin.go
│ │ │ │ ├── pop_linux.go
│ │ │ │ ├── pop_posix.go
│ │ │ │ └── tarheader.go
│ │ │ └── schema
│ │ │ ├── common
│ │ │ └── common.go
│ │ │ ├── doc.go
│ │ │ ├── image.go
│ │ │ ├── kind.go
│ │ │ ├── pod.go
│ │ │ ├── types
│ │ │ ├── acidentifier.go
│ │ │ ├── ackind.go
│ │ │ ├── acname.go
│ │ │ ├── annotations.go
│ │ │ ├── app.go
│ │ │ ├── date.go
│ │ │ ├── dependencies.go
│ │ │ ├── doc.go
│ │ │ ├── environment.go
│ │ │ ├── errors.go
│ │ │ ├── event_handler.go
│ │ │ ├── exec.go
│ │ │ ├── hash.go
│ │ │ ├── isolator.go
│ │ │ ├── isolator_linux_specific.go
│ │ │ ├── isolator_resources.go
│ │ │ ├── isolator_unix.go
│ │ │ ├── labels.go
│ │ │ ├── mountpoint.go
│ │ │ ├── port.go
│ │ │ ├── semver.go
│ │ │ ├── url.go
│ │ │ ├── user_annotations.go
│ │ │ ├── user_labels.go
│ │ │ ├── uuid.go
│ │ │ └── volume.go
│ │ │ └── version.go
│ ├── coreos
│ │ └── go-semver
│ │ │ ├── LICENSE
│ │ │ ├── example.go
│ │ │ └── semver
│ │ │ ├── semver.go
│ │ │ └── sort.go
│ ├── ghodss
│ │ └── yaml
│ │ │ ├── LICENSE
│ │ │ ├── fields.go
│ │ │ └── yaml.go
│ ├── gogo
│ │ └── protobuf
│ │ │ ├── LICENSE
│ │ │ └── proto
│ │ │ ├── clone.go
│ │ │ ├── decode.go
│ │ │ ├── decode_gogo.go
│ │ │ ├── encode.go
│ │ │ ├── encode_gogo.go
│ │ │ ├── equal.go
│ │ │ ├── extensions.go
│ │ │ ├── extensions_gogo.go
│ │ │ ├── lib.go
│ │ │ ├── lib_gogo.go
│ │ │ ├── message_set.go
│ │ │ ├── pointer_reflect.go
│ │ │ ├── pointer_unsafe.go
│ │ │ ├── pointer_unsafe_gogo.go
│ │ │ ├── properties.go
│ │ │ ├── properties_gogo.go
│ │ │ ├── skip_gogo.go
│ │ │ ├── text.go
│ │ │ ├── text_gogo.go
│ │ │ └── text_parser.go
│ ├── gorilla
│ │ ├── context
│ │ │ ├── LICENSE
│ │ │ ├── context.go
│ │ │ └── doc.go
│ │ ├── handlers
│ │ │ ├── LICENSE
│ │ │ ├── canonical.go
│ │ │ ├── compress.go
│ │ │ ├── cors.go
│ │ │ ├── doc.go
│ │ │ ├── handlers.go
│ │ │ ├── proxy_headers.go
│ │ │ └── recovery.go
│ │ └── mux
│ │ │ ├── LICENSE
│ │ │ ├── doc.go
│ │ │ ├── mux.go
│ │ │ ├── regexp.go
│ │ │ └── route.go
│ ├── inconshreveable
│ │ └── mousetrap
│ │ │ ├── LICENSE
│ │ │ ├── trap_others.go
│ │ │ ├── trap_windows.go
│ │ │ └── trap_windows_1.4.go
│ ├── n0rad
│ │ └── go-erlog
│ │ │ ├── appender.go
│ │ │ ├── data
│ │ │ └── data.go
│ │ │ ├── errs
│ │ │ ├── entry.go
│ │ │ └── stackframe.go
│ │ │ ├── event.go
│ │ │ ├── formatter.go
│ │ │ ├── logger.go
│ │ │ └── logs
│ │ │ ├── default.go
│ │ │ ├── dummy.go
│ │ │ ├── entry.go
│ │ │ ├── levels.go
│ │ │ └── logger.go
│ └── spf13
│ │ ├── cobra
│ │ ├── LICENSE.txt
│ │ ├── bash_completions.go
│ │ ├── cobra.go
│ │ ├── command.go
│ │ └── md_docs.go
│ │ └── pflag
│ │ ├── LICENSE
│ │ ├── bool.go
│ │ ├── duration.go
│ │ ├── flag.go
│ │ ├── float32.go
│ │ ├── float64.go
│ │ ├── int.go
│ │ ├── int32.go
│ │ ├── int64.go
│ │ ├── int8.go
│ │ ├── int_slice.go
│ │ ├── ip.go
│ │ ├── ipmask.go
│ │ ├── string.go
│ │ ├── string_slice.go
│ │ ├── uint.go
│ │ ├── uint16.go
│ │ ├── uint32.go
│ │ ├── uint64.go
│ │ └── uint8.go
├── go4.org
│ ├── LICENSE
│ └── errorutil
│ │ └── highlight.go
├── gopkg.in
│ ├── inf.v0
│ │ ├── LICENSE
│ │ ├── dec.go
│ │ └── rounder.go
│ └── yaml.v2
│ │ ├── LICENSE
│ │ ├── LICENSE.libyaml
│ │ ├── apic.go
│ │ ├── decode.go
│ │ ├── emitterc.go
│ │ ├── encode.go
│ │ ├── parserc.go
│ │ ├── readerc.go
│ │ ├── resolve.go
│ │ ├── scannerc.go
│ │ ├── sorter.go
│ │ ├── writerc.go
│ │ ├── yaml.go
│ │ ├── yamlh.go
│ │ └── yamlprivateh.go
└── k8s.io
│ └── kubernetes
│ ├── LICENSE
│ └── pkg
│ └── api
│ └── resource
│ ├── amount.go
│ ├── generated.pb.go
│ ├── math.go
│ ├── quantity.go
│ ├── quantity_proto.go
│ ├── scale_int.go
│ └── suffix.go
├── version.go
└── version_test.go
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files, Static and Dynamic libs (Shared Objects)
2 | *.o
3 | *.a
4 | *.so
5 |
6 | # Folders
7 | _obj
8 | _test
9 |
10 | # Architecture specific extensions/prefixes
11 | *.[568vq]
12 | [568vq].out
13 |
14 | *.cgo1.go
15 | *.cgo2.c
16 | _cgo_defun.c
17 | _cgo_gotypes.go
18 | _cgo_export.*
19 |
20 | _testmain.go
21 |
22 | *.exe
23 | *.test
24 | *.prof
25 |
26 | bin/
27 | gopath/
28 | dist/
29 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## v0.1.0
2 |
3 | v0.1.0 is the initial release of acserver.
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # acserver - App Container Server
2 |
3 | acserver is a minimal implementation for a web server that supports having ACIs
4 | pushed to it, and serving those ACIs to clients via [meta
5 | discovery](https://github.com/appc/spec/blob/master/spec/discovery.md#meta-discovery).
6 |
7 |
8 | # Configuration file
9 |
10 | Configuration file is optional, acserver will use all default attributes if not provided
11 |
12 | ```yaml
13 | api:
14 | serverName: # if not provided, use dns of http requests
15 | port: 3000
16 | https: false
17 | username: # disable basic auth security if not provided
18 | password:
19 | storage:
20 | rootPath: # where to store acis
21 | unsigned: true # support unsigned acis
22 | allowOverride: true # allow overriding aci that already exists in store
23 | ```
24 |
25 | # public key
26 |
27 | public key file must be placed in storage root directory with name `pubkeys.gpg`
28 |
--------------------------------------------------------------------------------
/examples/empty.yml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/appc/acserver/eb43341ab912072b07a7ec7a12e24892449b3163/examples/empty.yml
--------------------------------------------------------------------------------
/examples/minimal.yml:
--------------------------------------------------------------------------------
1 | api:
2 | port: 80
3 | storage:
4 | rootPath: /tmp/acis
5 |
--------------------------------------------------------------------------------
/examples/override.yml:
--------------------------------------------------------------------------------
1 | api:
2 | port: 80
3 | storage:
4 | rootPath: /tmp/acis
5 | allowOverride: false
6 |
--------------------------------------------------------------------------------
/glide.lock:
--------------------------------------------------------------------------------
1 | hash: b9d457d678d907db4443e087f39e6caaa1c5b06751bfa26c11cd01c75b9dfc45
2 | updated: 2016-11-29T23:21:46.912864408+01:00
3 | imports:
4 | - name: github.com/appc/spec
5 | version: d7de4875ad542ca48f4ff1f1f0a487764a825fbd
6 | subpackages:
7 | - aci
8 | - pkg/device
9 | - pkg/tarheader
10 | - schema
11 | - schema/common
12 | - schema/types
13 | - name: github.com/coreos/go-semver
14 | version: 294930c1e79c64e7dbe360054274fdad492c8cf5
15 | subpackages:
16 | - semver
17 | - name: github.com/ghodss/yaml
18 | version: c3eb24aeea63668ebdac08d2e252f20df8b6b1ae
19 | - name: github.com/gogo/protobuf
20 | version: 4168943e65a2802828518e95310aeeed6d84c4e5
21 | subpackages:
22 | - proto
23 | - name: github.com/gorilla/context
24 | version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42
25 | - name: github.com/gorilla/handlers
26 | version: ee54c7b44cab12289237fb8631314790076e728b
27 | - name: github.com/gorilla/mux
28 | version: 0eeaf8392f5b04950925b8a69fe70f110fa7cbfc
29 | - name: github.com/inconshreveable/mousetrap
30 | version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
31 | - name: github.com/n0rad/go-erlog
32 | version: d2278035863763980c7e312c6b813293f2ba4892
33 | subpackages:
34 | - data
35 | - errs
36 | - logs
37 | - name: github.com/spf13/cobra
38 | version: 385fc87e4343efec233811d3d933509e8975d11a
39 | - name: github.com/spf13/pflag
40 | version: 67cbc198fd11dab704b214c1e629a97af392c085
41 | - name: go4.org
42 | version: 03efcb870d84809319ea509714dd6d19a1498483
43 | subpackages:
44 | - errorutil
45 | - name: gopkg.in/inf.v0
46 | version: 3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4
47 | - name: gopkg.in/yaml.v2
48 | version: 7ad95dd0798a40da1ccdff6dff35fd177b5edf40
49 | - name: k8s.io/kubernetes
50 | version: fd8fac83034df346529c6e11aabceea2db48d663
51 | subpackages:
52 | - pkg/api/resource
53 | testImports: []
54 |
--------------------------------------------------------------------------------
/glide.yaml:
--------------------------------------------------------------------------------
1 | package: github.com/appc/acserver
2 | import:
3 | - package: github.com/gorilla/handlers
4 | version: ~1.1.0
5 | - package: github.com/gorilla/mux
6 | version: ~1.1.0
7 | - package: github.com/appc/spec
8 | version: ^0.8.9
9 | subpackages:
10 | - aci
11 | - package: github.com/spf13/cobra
12 | - package: gopkg.in/yaml.v2
13 |
--------------------------------------------------------------------------------
/gomake.cfg:
--------------------------------------------------------------------------------
1 | errcheck=false
2 |
3 | pre-build() {
4 | cp -R templates/ ${work_path}/${target_name}/bindata/
5 | }
6 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package main
16 |
17 | import (
18 | "fmt"
19 | "io/ioutil"
20 | "os"
21 |
22 | "github.com/spf13/cobra"
23 | "gopkg.in/yaml.v2"
24 | )
25 |
26 | var BuildTime string
27 | var BuildVersion string
28 | var BuildCommit string
29 |
30 | type ACServer struct {
31 | Storage ACStorage `yaml:"storage"`
32 | Api ACApi `yaml:"api"`
33 | }
34 |
35 | func (acs *ACServer) init() error {
36 | if err := acs.Storage.init(); err != nil {
37 | return err
38 | }
39 | if err := acs.Api.init(&acs.Storage); err != nil {
40 | return err
41 | }
42 | return nil
43 | }
44 |
45 | func loadConfig(configPath string, acserver *ACServer) error {
46 | file, err := ioutil.ReadFile(configPath)
47 | if err != nil {
48 | return fmt.Errorf("Failed to read configuration file : %s, %v", configPath, err)
49 | }
50 |
51 | err = yaml.Unmarshal(file, acserver)
52 | if err != nil {
53 | return fmt.Errorf("Invalid configuration format : %s, %v", configPath, err)
54 | }
55 |
56 | return nil
57 | }
58 |
59 | func main() {
60 | var version bool
61 |
62 | rootCmd := &cobra.Command{
63 | Use: "acserver config.yml",
64 | PersistentPreRun: func(cmd *cobra.Command, args []string) {
65 | if version {
66 | fmt.Println("acserver")
67 | fmt.Println("Version :", BuildVersion+"-"+BuildCommit)
68 | fmt.Println("Build Time :", BuildTime)
69 | os.Exit(0)
70 | }
71 | },
72 | Run: func(cmd *cobra.Command, args []string) {
73 | var acserver ACServer
74 | if len(args) > 1 {
75 | fmt.Fprintf(os.Stderr, "acserver require only a configuration file as argument\n")
76 | os.Exit(1)
77 | } else if len(args) == 1 {
78 | if err := loadConfig(args[0], &acserver); err != nil {
79 | fmt.Fprintf(os.Stderr, "Cannot start, failed to load configuration\n")
80 | os.Exit(1)
81 | }
82 | } else {
83 | fmt.Fprintf(os.Stderr, "No configuration file set, using only default values\n")
84 | }
85 | acserver.init()
86 | acserver.Storage.start()
87 | acserver.Api.Start()
88 | },
89 | }
90 |
91 | rootCmd.PersistentFlags().BoolVarP(&version, "version", "V", false, "Display version")
92 |
93 | if err := rootCmd.Execute(); err != nil {
94 | fmt.Fprintf(os.Stderr, "Failed to process args\n")
95 | os.Exit(1)
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/scripts/glide-update:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 |
4 | if ! [[ "$0" =~ "scripts/glide-update" ]]; then
5 | echo "must be run from repository root"
6 | exit 255
7 | fi
8 |
9 | if [ ! $(command -v glide) ]; then
10 | echo "glide: command not found"
11 | exit 255
12 | fi
13 |
14 | if [ ! $(command -v glide-vc) ]; then
15 | echo "glide-vc: command not found"
16 | exit 255
17 | fi
18 |
19 | glide update --strip-vcs --strip-vendor --update-vendored --delete
20 | glide-vc --only-code --no-tests
21 |
--------------------------------------------------------------------------------
/scripts/glide-vendor-cleanup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -x
3 | set -e
4 | dir=$( dirname $0 )
5 |
6 | [ $(command -v glide-vc) ] || go get github.com/sgotti/glide-vc
7 | cd ${dir}/..
8 | glide-vc --only-code --no-tests --keep="**/*.json.in" --use-lock-file
9 |
--------------------------------------------------------------------------------
/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | {{.ServerName}}
24 | ACI images fetchable from here:
25 | {{range $i, $e := .ACIs}}
26 | {{$.ServerName}}/{{$e.Name}}
27 |
28 |
29 | Version |
30 | Operating System |
31 | Architecture |
32 | Signed |
33 | Last Modified |
34 |
35 | {{range $j, $d := $e.Details}}
36 |
37 | {{$d.Version}} |
38 | {{$d.OS}} |
39 | {{$d.Arch}} |
40 | {{$d.Signed}} |
41 | {{$d.LastMod}} |
42 |
43 | {{end}}
44 |
45 | {{end}}
46 |
47 |
48 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/aci/build.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package aci
16 |
17 | import (
18 | "archive/tar"
19 | "io"
20 | "os"
21 | "path/filepath"
22 |
23 | "github.com/appc/spec/pkg/tarheader"
24 | )
25 |
26 | // TarHeaderWalkFunc is the type of the function which allows setting tar
27 | // headers or filtering out tar entries when building an ACI. It will be
28 | // applied to every entry in the tar file.
29 | //
30 | // If true is returned, the entry will be included in the final ACI; if false,
31 | // the entry will not be included.
32 | type TarHeaderWalkFunc func(hdr *tar.Header) bool
33 |
34 | // BuildWalker creates a filepath.WalkFunc that walks over the given root
35 | // (which should represent an ACI layout on disk) and adds the files in the
36 | // rootfs/ subdirectory to the given ArchiveWriter
37 | func BuildWalker(root string, aw ArchiveWriter, cb TarHeaderWalkFunc) filepath.WalkFunc {
38 | // cache of inode -> filepath, used to leverage hard links in the archive
39 | inos := map[uint64]string{}
40 | return func(path string, info os.FileInfo, err error) error {
41 | if err != nil {
42 | return err
43 | }
44 | relpath, err := filepath.Rel(root, path)
45 | if err != nil {
46 | return err
47 | }
48 | if relpath == "." {
49 | return nil
50 | }
51 | if relpath == ManifestFile {
52 | // ignore; this will be written by the archive writer
53 | // TODO(jonboulle): does this make sense? maybe just remove from archivewriter?
54 | return nil
55 | }
56 |
57 | link := ""
58 | var r io.Reader
59 | switch info.Mode() & os.ModeType {
60 | case os.ModeSocket:
61 | return nil
62 | case os.ModeNamedPipe:
63 | case os.ModeCharDevice:
64 | case os.ModeDevice:
65 | case os.ModeDir:
66 | case os.ModeSymlink:
67 | target, err := os.Readlink(path)
68 | if err != nil {
69 | return err
70 | }
71 | link = target
72 | default:
73 | file, err := os.Open(path)
74 | if err != nil {
75 | return err
76 | }
77 | defer file.Close()
78 | r = file
79 | }
80 |
81 | hdr, err := tar.FileInfoHeader(info, link)
82 | if err != nil {
83 | panic(err)
84 | }
85 | // Because os.FileInfo's Name method returns only the base
86 | // name of the file it describes, it may be necessary to
87 | // modify the Name field of the returned header to provide the
88 | // full path name of the file.
89 | hdr.Name = relpath
90 | tarheader.Populate(hdr, info, inos)
91 | // If the file is a hard link to a file we've already seen, we
92 | // don't need the contents
93 | if hdr.Typeflag == tar.TypeLink {
94 | hdr.Size = 0
95 | r = nil
96 | }
97 |
98 | if cb != nil {
99 | if !cb(hdr) {
100 | return nil
101 | }
102 | }
103 |
104 | if err := aw.AddFile(hdr, r); err != nil {
105 | return err
106 | }
107 |
108 | return nil
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/aci/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package aci contains various functions for working with App Container Images.
16 | package aci
17 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/aci/writer.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package aci
16 |
17 | import (
18 | "archive/tar"
19 | "bytes"
20 | "encoding/json"
21 | "io"
22 | "time"
23 |
24 | "github.com/appc/spec/schema"
25 | )
26 |
27 | // ArchiveWriter writes App Container Images. Users wanting to create an ACI or
28 | // should create an ArchiveWriter and add files to it; the ACI will be written
29 | // to the underlying tar.Writer
30 | type ArchiveWriter interface {
31 | AddFile(hdr *tar.Header, r io.Reader) error
32 | Close() error
33 | }
34 |
35 | type imageArchiveWriter struct {
36 | *tar.Writer
37 | am *schema.ImageManifest
38 | }
39 |
40 | // NewImageWriter creates a new ArchiveWriter which will generate an App
41 | // Container Image based on the given manifest and write it to the given
42 | // tar.Writer
43 | func NewImageWriter(am schema.ImageManifest, w *tar.Writer) ArchiveWriter {
44 | aw := &imageArchiveWriter{
45 | w,
46 | &am,
47 | }
48 | return aw
49 | }
50 |
51 | func (aw *imageArchiveWriter) AddFile(hdr *tar.Header, r io.Reader) error {
52 | err := aw.Writer.WriteHeader(hdr)
53 | if err != nil {
54 | return err
55 | }
56 |
57 | if r != nil {
58 | _, err := io.Copy(aw.Writer, r)
59 | if err != nil {
60 | return err
61 | }
62 | }
63 |
64 | return nil
65 | }
66 |
67 | func (aw *imageArchiveWriter) addFileNow(path string, contents []byte) error {
68 | buf := bytes.NewBuffer(contents)
69 | now := time.Now()
70 | hdr := tar.Header{
71 | Name: path,
72 | Mode: 0644,
73 | Uid: 0,
74 | Gid: 0,
75 | Size: int64(buf.Len()),
76 | ModTime: now,
77 | Typeflag: tar.TypeReg,
78 | Uname: "root",
79 | Gname: "root",
80 | ChangeTime: now,
81 | }
82 | return aw.AddFile(&hdr, buf)
83 | }
84 |
85 | func (aw *imageArchiveWriter) addManifest(name string, m json.Marshaler) error {
86 | out, err := m.MarshalJSON()
87 | if err != nil {
88 | return err
89 | }
90 | return aw.addFileNow(name, out)
91 | }
92 |
93 | func (aw *imageArchiveWriter) Close() error {
94 | if err := aw.addManifest(ManifestFile, aw.am); err != nil {
95 | return err
96 | }
97 | return aw.Writer.Close()
98 | }
99 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/pkg/device/device_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build linux
16 |
17 | package device
18 |
19 | // with glibc/sysdeps/unix/sysv/linux/sys/sysmacros.h as reference
20 |
21 | func Major(rdev uint64) uint {
22 | return uint((rdev>>8)&0xfff) | (uint(rdev>>32) & ^uint(0xfff))
23 | }
24 |
25 | func Minor(rdev uint64) uint {
26 | return uint(rdev&0xff) | uint(uint32(rdev>>12) & ^uint32(0xff))
27 | }
28 |
29 | func Makedev(maj uint, min uint) uint64 {
30 | return uint64(min&0xff) | (uint64(maj&0xfff) << 8) |
31 | ((uint64(min) & ^uint64(0xff)) << 12) |
32 | ((uint64(maj) & ^uint64(0xfff)) << 32)
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/pkg/device/device_posix.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build freebsd netbsd openbsd darwin
16 |
17 | package device
18 |
19 | /*
20 | #define _BSD_SOURCE
21 | #define _DEFAULT_SOURCE
22 | #include
23 |
24 | unsigned int
25 | my_major(dev_t dev)
26 | {
27 | return major(dev);
28 | }
29 |
30 | unsigned int
31 | my_minor(dev_t dev)
32 | {
33 | return minor(dev);
34 | }
35 |
36 | dev_t
37 | my_makedev(unsigned int maj, unsigned int min)
38 | {
39 | return makedev(maj, min);
40 | }
41 | */
42 | import "C"
43 |
44 | func Major(rdev uint64) uint {
45 | major := C.my_major(C.dev_t(rdev))
46 | return uint(major)
47 | }
48 |
49 | func Minor(rdev uint64) uint {
50 | minor := C.my_minor(C.dev_t(rdev))
51 | return uint(minor)
52 | }
53 |
54 | func Makedev(maj uint, min uint) uint64 {
55 | dev := C.my_makedev(C.uint(maj), C.uint(min))
56 | return uint64(dev)
57 | }
58 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/pkg/tarheader/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package tarheader contains a simple abstraction to accurately create
16 | // tar.Headers on different operating systems.
17 | package tarheader
18 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/pkg/tarheader/pop_darwin.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | //+build darwin
16 |
17 | package tarheader
18 |
19 | import (
20 | "archive/tar"
21 | "os"
22 | "syscall"
23 | "time"
24 | )
25 |
26 | func init() {
27 | populateHeaderStat = append(populateHeaderStat, populateHeaderCtime)
28 | }
29 |
30 | func populateHeaderCtime(h *tar.Header, fi os.FileInfo, _ map[uint64]string) {
31 | st, ok := fi.Sys().(*syscall.Stat_t)
32 | if !ok {
33 | return
34 | }
35 |
36 | sec, nsec := st.Ctimespec.Unix()
37 | ctime := time.Unix(sec, nsec)
38 | h.ChangeTime = ctime
39 | }
40 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/pkg/tarheader/pop_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build linux
16 |
17 | package tarheader
18 |
19 | import (
20 | "archive/tar"
21 | "os"
22 | "syscall"
23 | "time"
24 | )
25 |
26 | func init() {
27 | populateHeaderStat = append(populateHeaderStat, populateHeaderCtime)
28 | }
29 |
30 | func populateHeaderCtime(h *tar.Header, fi os.FileInfo, _ map[uint64]string) {
31 | st, ok := fi.Sys().(*syscall.Stat_t)
32 | if !ok {
33 | return
34 | }
35 |
36 | sec, nsec := st.Ctim.Unix()
37 | ctime := time.Unix(sec, nsec)
38 | h.ChangeTime = ctime
39 | }
40 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/pkg/tarheader/pop_posix.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // +build linux freebsd netbsd openbsd
16 |
17 | package tarheader
18 |
19 | import (
20 | "archive/tar"
21 | "os"
22 | "syscall"
23 |
24 | "github.com/appc/spec/pkg/device"
25 | )
26 |
27 | func init() {
28 | populateHeaderStat = append(populateHeaderStat, populateHeaderUnix)
29 | }
30 |
31 | func populateHeaderUnix(h *tar.Header, fi os.FileInfo, seen map[uint64]string) {
32 | st, ok := fi.Sys().(*syscall.Stat_t)
33 | if !ok {
34 | return
35 | }
36 | h.Uid = int(st.Uid)
37 | h.Gid = int(st.Gid)
38 | if st.Mode&syscall.S_IFMT == syscall.S_IFBLK || st.Mode&syscall.S_IFMT == syscall.S_IFCHR {
39 | h.Devminor = int64(device.Minor(uint64(st.Rdev)))
40 | h.Devmajor = int64(device.Major(uint64(st.Rdev)))
41 | }
42 | // If we have already seen this inode, generate a hardlink
43 | p, ok := seen[uint64(st.Ino)]
44 | if ok {
45 | h.Linkname = p
46 | h.Typeflag = tar.TypeLink
47 | } else {
48 | seen[uint64(st.Ino)] = h.Name
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/pkg/tarheader/tarheader.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package tarheader
16 |
17 | import (
18 | "archive/tar"
19 | "os"
20 | )
21 |
22 | var populateHeaderStat []func(h *tar.Header, fi os.FileInfo, seen map[uint64]string)
23 |
24 | func Populate(h *tar.Header, fi os.FileInfo, seen map[uint64]string) {
25 | for _, pop := range populateHeaderStat {
26 | pop(h, fi, seen)
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/common/common.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package common
16 |
17 | import (
18 | "fmt"
19 | "net/url"
20 | "strings"
21 | )
22 |
23 | // MakeQueryString takes a comma-separated LABEL=VALUE string and returns an
24 | // "&"-separated string with URL escaped values.
25 | //
26 | // Examples:
27 | // version=1.0.0,label=v1+v2 -> version=1.0.0&label=v1%2Bv2
28 | // name=db,source=/tmp$1 -> name=db&source=%2Ftmp%241
29 | func MakeQueryString(app string) (string, error) {
30 | parts := strings.Split(app, ",")
31 | escapedParts := make([]string, len(parts))
32 | for i, s := range parts {
33 | p := strings.SplitN(s, "=", 2)
34 | if len(p) != 2 {
35 | return "", fmt.Errorf("malformed string %q - has a label without a value: %s", app, p[0])
36 | }
37 | escapedParts[i] = fmt.Sprintf("%s=%s", p[0], url.QueryEscape(p[1]))
38 | }
39 | return strings.Join(escapedParts, "&"), nil
40 | }
41 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package schema provides definitions for the JSON schema of the different
16 | // manifests in the App Container Specification. The manifests are canonically
17 | // represented in their respective structs:
18 | // - `ImageManifest`
19 | // - `PodManifest`
20 | //
21 | // Validation is performed through serialization: if a blob of JSON data will
22 | // unmarshal to one of the *Manifests, it is considered a valid implementation
23 | // of the standard. Similarly, if a constructed *Manifest struct marshals
24 | // successfully to JSON, it must be valid.
25 | package schema
26 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/image.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package schema
16 |
17 | import (
18 | "bytes"
19 | "encoding/json"
20 | "errors"
21 | "fmt"
22 |
23 | "github.com/appc/spec/schema/types"
24 |
25 | "go4.org/errorutil"
26 | )
27 |
28 | const (
29 | ACIExtension = ".aci"
30 | ImageManifestKind = types.ACKind("ImageManifest")
31 | )
32 |
33 | type ImageManifest struct {
34 | ACKind types.ACKind `json:"acKind"`
35 | ACVersion types.SemVer `json:"acVersion"`
36 | Name types.ACIdentifier `json:"name"`
37 | Labels types.Labels `json:"labels,omitempty"`
38 | App *types.App `json:"app,omitempty"`
39 | Annotations types.Annotations `json:"annotations,omitempty"`
40 | Dependencies types.Dependencies `json:"dependencies,omitempty"`
41 | PathWhitelist []string `json:"pathWhitelist,omitempty"`
42 | }
43 |
44 | // imageManifest is a model to facilitate extra validation during the
45 | // unmarshalling of the ImageManifest
46 | type imageManifest ImageManifest
47 |
48 | func BlankImageManifest() *ImageManifest {
49 | return &ImageManifest{ACKind: ImageManifestKind, ACVersion: AppContainerVersion}
50 | }
51 |
52 | func (im *ImageManifest) UnmarshalJSON(data []byte) error {
53 | a := imageManifest(*im)
54 | err := json.Unmarshal(data, &a)
55 | if err != nil {
56 | if serr, ok := err.(*json.SyntaxError); ok {
57 | line, col, highlight := errorutil.HighlightBytePosition(bytes.NewReader(data), serr.Offset)
58 | return fmt.Errorf("\nError at line %d, column %d\n%s%v", line, col, highlight, err)
59 | }
60 | return err
61 | }
62 | nim := ImageManifest(a)
63 | if err := nim.assertValid(); err != nil {
64 | return err
65 | }
66 | *im = nim
67 | return nil
68 | }
69 |
70 | func (im ImageManifest) MarshalJSON() ([]byte, error) {
71 | if err := im.assertValid(); err != nil {
72 | return nil, err
73 | }
74 | return json.Marshal(imageManifest(im))
75 | }
76 |
77 | var imKindError = types.InvalidACKindError(ImageManifestKind)
78 |
79 | // assertValid performs extra assertions on an ImageManifest to ensure that
80 | // fields are set appropriately, etc. It is used exclusively when marshalling
81 | // and unmarshalling an ImageManifest. Most field-specific validation is
82 | // performed through the individual types being marshalled; assertValid()
83 | // should only deal with higher-level validation.
84 | func (im *ImageManifest) assertValid() error {
85 | if im.ACKind != ImageManifestKind {
86 | return imKindError
87 | }
88 | if im.ACVersion.Empty() {
89 | return errors.New(`acVersion must be set`)
90 | }
91 | if im.Name.Empty() {
92 | return errors.New(`name must be set`)
93 | }
94 | return nil
95 | }
96 |
97 | func (im *ImageManifest) GetLabel(name string) (val string, ok bool) {
98 | return im.Labels.Get(name)
99 | }
100 |
101 | func (im *ImageManifest) GetAnnotation(name string) (val string, ok bool) {
102 | return im.Annotations.Get(name)
103 | }
104 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/kind.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package schema
16 |
17 | import (
18 | "encoding/json"
19 |
20 | "github.com/appc/spec/schema/types"
21 | )
22 |
23 | type Kind struct {
24 | ACVersion types.SemVer `json:"acVersion"`
25 | ACKind types.ACKind `json:"acKind"`
26 | }
27 |
28 | type kind Kind
29 |
30 | func (k *Kind) UnmarshalJSON(data []byte) error {
31 | nk := kind{}
32 | err := json.Unmarshal(data, &nk)
33 | if err != nil {
34 | return err
35 | }
36 | *k = Kind(nk)
37 | return nil
38 | }
39 |
40 | func (k Kind) MarshalJSON() ([]byte, error) {
41 | return json.Marshal(kind(k))
42 | }
43 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/ackind.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "fmt"
20 | )
21 |
22 | var (
23 | ErrNoACKind = ACKindError("ACKind must be set")
24 | )
25 |
26 | // ACKind wraps a string to define a field which must be set with one of
27 | // several ACKind values. If it is unset, or has an invalid value, the field
28 | // will refuse to marshal/unmarshal.
29 | type ACKind string
30 |
31 | func (a ACKind) String() string {
32 | return string(a)
33 | }
34 |
35 | func (a ACKind) assertValid() error {
36 | s := a.String()
37 | switch s {
38 | case "ImageManifest", "PodManifest":
39 | return nil
40 | case "":
41 | return ErrNoACKind
42 | default:
43 | msg := fmt.Sprintf("bad ACKind: %s", s)
44 | return ACKindError(msg)
45 | }
46 | }
47 |
48 | func (a ACKind) MarshalJSON() ([]byte, error) {
49 | if err := a.assertValid(); err != nil {
50 | return nil, err
51 | }
52 | return json.Marshal(a.String())
53 | }
54 |
55 | func (a *ACKind) UnmarshalJSON(data []byte) error {
56 | var s string
57 | err := json.Unmarshal(data, &s)
58 | if err != nil {
59 | return err
60 | }
61 | na := ACKind(s)
62 | if err := na.assertValid(); err != nil {
63 | return err
64 | }
65 | *a = na
66 | return nil
67 | }
68 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/annotations.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "fmt"
20 | )
21 |
22 | type Annotations []Annotation
23 |
24 | type annotations Annotations
25 |
26 | type Annotation struct {
27 | Name ACIdentifier `json:"name"`
28 | Value string `json:"value"`
29 | }
30 |
31 | func (a Annotations) assertValid() error {
32 | seen := map[ACIdentifier]string{}
33 | for _, anno := range a {
34 | _, ok := seen[anno.Name]
35 | if ok {
36 | return fmt.Errorf(`duplicate annotations of name %q`, anno.Name)
37 | }
38 | seen[anno.Name] = anno.Value
39 | }
40 | if c, ok := seen["created"]; ok {
41 | if _, err := NewDate(c); err != nil {
42 | return err
43 | }
44 | }
45 | if h, ok := seen["homepage"]; ok {
46 | if _, err := NewURL(h); err != nil {
47 | return err
48 | }
49 | }
50 | if d, ok := seen["documentation"]; ok {
51 | if _, err := NewURL(d); err != nil {
52 | return err
53 | }
54 | }
55 |
56 | return nil
57 | }
58 |
59 | func (a Annotations) MarshalJSON() ([]byte, error) {
60 | if err := a.assertValid(); err != nil {
61 | return nil, err
62 | }
63 | return json.Marshal(annotations(a))
64 | }
65 |
66 | func (a *Annotations) UnmarshalJSON(data []byte) error {
67 | var ja annotations
68 | if err := json.Unmarshal(data, &ja); err != nil {
69 | return err
70 | }
71 | na := Annotations(ja)
72 | if err := na.assertValid(); err != nil {
73 | return err
74 | }
75 | *a = na
76 | return nil
77 | }
78 |
79 | // Retrieve the value of an annotation by the given name from Annotations, if
80 | // it exists.
81 | func (a Annotations) Get(name string) (val string, ok bool) {
82 | for _, anno := range a {
83 | if anno.Name.String() == name {
84 | return anno.Value, true
85 | }
86 | }
87 | return "", false
88 | }
89 |
90 | // Set sets the value of an annotation by the given name, overwriting if one already exists.
91 | func (a *Annotations) Set(name ACIdentifier, value string) {
92 | for i, anno := range *a {
93 | if anno.Name.Equals(name) {
94 | (*a)[i] = Annotation{
95 | Name: name,
96 | Value: value,
97 | }
98 | return
99 | }
100 | }
101 | anno := Annotation{
102 | Name: name,
103 | Value: value,
104 | }
105 | *a = append(*a, anno)
106 | }
107 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/app.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "errors"
20 | "fmt"
21 | "path"
22 | )
23 |
24 | type App struct {
25 | Exec Exec `json:"exec"`
26 | EventHandlers []EventHandler `json:"eventHandlers,omitempty"`
27 | User string `json:"user"`
28 | Group string `json:"group"`
29 | SupplementaryGIDs []int `json:"supplementaryGIDs,omitempty"`
30 | WorkingDirectory string `json:"workingDirectory,omitempty"`
31 | Environment Environment `json:"environment,omitempty"`
32 | MountPoints []MountPoint `json:"mountPoints,omitempty"`
33 | Ports []Port `json:"ports,omitempty"`
34 | Isolators Isolators `json:"isolators,omitempty"`
35 | UserAnnotations UserAnnotations `json:"userAnnotations,omitempty"`
36 | UserLabels UserLabels `json:"userLabels,omitempty"`
37 | }
38 |
39 | // app is a model to facilitate extra validation during the
40 | // unmarshalling of the App
41 | type app App
42 |
43 | func (a *App) UnmarshalJSON(data []byte) error {
44 | ja := app(*a)
45 | err := json.Unmarshal(data, &ja)
46 | if err != nil {
47 | return err
48 | }
49 | na := App(ja)
50 | if err := na.assertValid(); err != nil {
51 | return err
52 | }
53 | if na.Environment == nil {
54 | na.Environment = make(Environment, 0)
55 | }
56 | *a = na
57 | return nil
58 | }
59 |
60 | func (a App) MarshalJSON() ([]byte, error) {
61 | if err := a.assertValid(); err != nil {
62 | return nil, err
63 | }
64 | return json.Marshal(app(a))
65 | }
66 |
67 | func (a *App) assertValid() error {
68 | if err := a.Exec.assertValid(); err != nil {
69 | return err
70 | }
71 | if a.User == "" {
72 | return errors.New(`user is required`)
73 | }
74 | if a.Group == "" {
75 | return errors.New(`group is required`)
76 | }
77 | if !path.IsAbs(a.WorkingDirectory) && a.WorkingDirectory != "" {
78 | return errors.New("workingDirectory must be an absolute path")
79 | }
80 | eh := make(map[string]bool)
81 | for _, e := range a.EventHandlers {
82 | name := e.Name
83 | if eh[name] {
84 | return fmt.Errorf("Only one eventHandler of name %q allowed", name)
85 | }
86 | eh[name] = true
87 | }
88 | if err := a.Environment.assertValid(); err != nil {
89 | return err
90 | }
91 | if err := a.Isolators.assertValid(); err != nil {
92 | return err
93 | }
94 | return nil
95 | }
96 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/date.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "fmt"
20 | "time"
21 | )
22 |
23 | // Date wraps time.Time to marshal/unmarshal to/from JSON strings in strict
24 | // accordance with RFC3339
25 | // TODO(jonboulle): golang's implementation seems slightly buggy here;
26 | // according to http://tools.ietf.org/html/rfc3339#section-5.6 , applications
27 | // may choose to separate the date and time with a space instead of a T
28 | // character (for example, `date --rfc-3339` on GNU coreutils) - but this is
29 | // considered an error by go's parser. File a bug?
30 | type Date time.Time
31 |
32 | func NewDate(s string) (*Date, error) {
33 | t, err := time.Parse(time.RFC3339, s)
34 | if err != nil {
35 | return nil, fmt.Errorf("bad Date: %v", err)
36 | }
37 | d := Date(t)
38 | return &d, nil
39 | }
40 |
41 | func (d Date) String() string {
42 | return time.Time(d).Format(time.RFC3339)
43 | }
44 |
45 | func (d *Date) UnmarshalJSON(data []byte) error {
46 | var s string
47 | if err := json.Unmarshal(data, &s); err != nil {
48 | return err
49 | }
50 | nd, err := NewDate(s)
51 | if err != nil {
52 | return err
53 | }
54 | *d = *nd
55 | return nil
56 | }
57 |
58 | func (d Date) MarshalJSON() ([]byte, error) {
59 | return json.Marshal(d.String())
60 | }
61 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/dependencies.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "errors"
20 | )
21 |
22 | type Dependencies []Dependency
23 |
24 | type Dependency struct {
25 | ImageName ACIdentifier `json:"imageName"`
26 | ImageID *Hash `json:"imageID,omitempty"`
27 | Labels Labels `json:"labels,omitempty"`
28 | Size uint `json:"size,omitempty"`
29 | }
30 |
31 | type dependency Dependency
32 |
33 | func (d Dependency) assertValid() error {
34 | if len(d.ImageName) < 1 {
35 | return errors.New(`imageName cannot be empty`)
36 | }
37 | return nil
38 | }
39 |
40 | func (d Dependency) MarshalJSON() ([]byte, error) {
41 | if err := d.assertValid(); err != nil {
42 | return nil, err
43 | }
44 | return json.Marshal(dependency(d))
45 | }
46 |
47 | func (d *Dependency) UnmarshalJSON(data []byte) error {
48 | var jd dependency
49 | if err := json.Unmarshal(data, &jd); err != nil {
50 | return err
51 | }
52 | nd := Dependency(jd)
53 | if err := nd.assertValid(); err != nil {
54 | return err
55 | }
56 | *d = nd
57 | return nil
58 | }
59 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Package types contains structs representing the various types in the app
16 | // container specification. It is used by the [schema manifest types](../)
17 | // to enforce validation.
18 | package types
19 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/environment.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "fmt"
20 | "regexp"
21 | )
22 |
23 | var (
24 | envPattern = regexp.MustCompile("^[A-Za-z_][A-Za-z_0-9]*$")
25 | )
26 |
27 | type Environment []EnvironmentVariable
28 |
29 | type environment Environment
30 |
31 | type EnvironmentVariable struct {
32 | Name string `json:"name"`
33 | Value string `json:"value"`
34 | }
35 |
36 | func (ev EnvironmentVariable) assertValid() error {
37 | if len(ev.Name) == 0 {
38 | return fmt.Errorf(`environment variable name must not be empty`)
39 | }
40 | if !envPattern.MatchString(ev.Name) {
41 | return fmt.Errorf(`environment variable does not have valid identifier %q`, ev.Name)
42 | }
43 | return nil
44 | }
45 |
46 | func (e Environment) assertValid() error {
47 | seen := map[string]bool{}
48 | for _, env := range e {
49 | if err := env.assertValid(); err != nil {
50 | return err
51 | }
52 | _, ok := seen[env.Name]
53 | if ok {
54 | return fmt.Errorf(`duplicate environment variable of name %q`, env.Name)
55 | }
56 | seen[env.Name] = true
57 | }
58 |
59 | return nil
60 | }
61 |
62 | func (e Environment) MarshalJSON() ([]byte, error) {
63 | if err := e.assertValid(); err != nil {
64 | return nil, err
65 | }
66 | return json.Marshal(environment(e))
67 | }
68 |
69 | func (e *Environment) UnmarshalJSON(data []byte) error {
70 | var je environment
71 | if err := json.Unmarshal(data, &je); err != nil {
72 | return err
73 | }
74 | ne := Environment(je)
75 | if err := ne.assertValid(); err != nil {
76 | return err
77 | }
78 | *e = ne
79 | return nil
80 | }
81 |
82 | // Retrieve the value of an environment variable by the given name from
83 | // Environment, if it exists.
84 | func (e Environment) Get(name string) (value string, ok bool) {
85 | for _, env := range e {
86 | if env.Name == name {
87 | return env.Value, true
88 | }
89 | }
90 | return "", false
91 | }
92 |
93 | // Set sets the value of an environment variable by the given name,
94 | // overwriting if one already exists.
95 | func (e *Environment) Set(name string, value string) {
96 | for i, env := range *e {
97 | if env.Name == name {
98 | (*e)[i] = EnvironmentVariable{
99 | Name: name,
100 | Value: value,
101 | }
102 | return
103 | }
104 | }
105 | env := EnvironmentVariable{
106 | Name: name,
107 | Value: value,
108 | }
109 | *e = append(*e, env)
110 | }
111 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/errors.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import "fmt"
18 |
19 | // An ACKindError is returned when the wrong ACKind is set in a manifest
20 | type ACKindError string
21 |
22 | func (e ACKindError) Error() string {
23 | return string(e)
24 | }
25 |
26 | func InvalidACKindError(kind ACKind) ACKindError {
27 | return ACKindError(fmt.Sprintf("missing or bad ACKind (must be %#v)", kind))
28 | }
29 |
30 | // An ACVersionError is returned when a bad ACVersion is set in a manifest
31 | type ACVersionError string
32 |
33 | func (e ACVersionError) Error() string {
34 | return string(e)
35 | }
36 |
37 | // An ACIdentifierError is returned when a bad value is used for an ACIdentifier
38 | type ACIdentifierError string
39 |
40 | func (e ACIdentifierError) Error() string {
41 | return string(e)
42 | }
43 |
44 | // An ACNameError is returned when a bad value is used for an ACName
45 | type ACNameError string
46 |
47 | func (e ACNameError) Error() string {
48 | return string(e)
49 | }
50 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/event_handler.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "errors"
20 | "fmt"
21 | )
22 |
23 | type EventHandler struct {
24 | Name string `json:"name"`
25 | Exec Exec `json:"exec"`
26 | }
27 |
28 | type eventHandler EventHandler
29 |
30 | func (e EventHandler) assertValid() error {
31 | s := e.Name
32 | switch s {
33 | case "pre-start", "post-stop":
34 | return nil
35 | case "":
36 | return errors.New(`eventHandler "name" cannot be empty`)
37 | default:
38 | return fmt.Errorf(`bad eventHandler "name": %q`, s)
39 | }
40 | }
41 |
42 | func (e EventHandler) MarshalJSON() ([]byte, error) {
43 | if err := e.assertValid(); err != nil {
44 | return nil, err
45 | }
46 | return json.Marshal(eventHandler(e))
47 | }
48 |
49 | func (e *EventHandler) UnmarshalJSON(data []byte) error {
50 | var je eventHandler
51 | err := json.Unmarshal(data, &je)
52 | if err != nil {
53 | return err
54 | }
55 | ne := EventHandler(je)
56 | if err := ne.assertValid(); err != nil {
57 | return err
58 | }
59 | *e = ne
60 | return nil
61 | }
62 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/exec.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import "encoding/json"
18 |
19 | type Exec []string
20 |
21 | type exec Exec
22 |
23 | func (e Exec) assertValid() error {
24 | return nil
25 | }
26 |
27 | func (e Exec) MarshalJSON() ([]byte, error) {
28 | if err := e.assertValid(); err != nil {
29 | return nil, err
30 | }
31 | return json.Marshal(exec(e))
32 | }
33 |
34 | func (e *Exec) UnmarshalJSON(data []byte) error {
35 | var je exec
36 | err := json.Unmarshal(data, &je)
37 | if err != nil {
38 | return err
39 | }
40 | ne := Exec(je)
41 | if err := ne.assertValid(); err != nil {
42 | return err
43 | }
44 | *e = ne
45 | return nil
46 | }
47 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/hash.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "crypto/sha512"
19 | "encoding/json"
20 | "errors"
21 | "fmt"
22 | "reflect"
23 | "strings"
24 | )
25 |
26 | const (
27 | maxHashSize = (sha512.Size / 2) + len("sha512-")
28 | )
29 |
30 | // Hash encodes a hash specified in a string of the form:
31 | // "-"
32 | // for example
33 | // "sha512-06c733b1838136838e6d2d3e8fa5aea4c7905e92[...]"
34 | // Valid types are currently:
35 | // * sha512
36 | type Hash struct {
37 | typ string
38 | Val string
39 | }
40 |
41 | func NewHash(s string) (*Hash, error) {
42 | elems := strings.Split(s, "-")
43 | if len(elems) != 2 {
44 | return nil, errors.New("badly formatted hash string")
45 | }
46 | nh := Hash{
47 | typ: elems[0],
48 | Val: elems[1],
49 | }
50 | if err := nh.assertValid(); err != nil {
51 | return nil, err
52 | }
53 | return &nh, nil
54 | }
55 |
56 | func (h Hash) String() string {
57 | return fmt.Sprintf("%s-%s", h.typ, h.Val)
58 | }
59 |
60 | func (h *Hash) Set(s string) error {
61 | nh, err := NewHash(s)
62 | if err == nil {
63 | *h = *nh
64 | }
65 | return err
66 | }
67 |
68 | func (h Hash) Empty() bool {
69 | return reflect.DeepEqual(h, Hash{})
70 | }
71 |
72 | func (h Hash) assertValid() error {
73 | switch h.typ {
74 | case "sha512":
75 | case "":
76 | return fmt.Errorf("unexpected empty hash type")
77 | default:
78 | return fmt.Errorf("unrecognized hash type: %v", h.typ)
79 | }
80 | if h.Val == "" {
81 | return fmt.Errorf("unexpected empty hash value")
82 | }
83 | return nil
84 | }
85 |
86 | func (h *Hash) UnmarshalJSON(data []byte) error {
87 | var s string
88 | if err := json.Unmarshal(data, &s); err != nil {
89 | return err
90 | }
91 | nh, err := NewHash(s)
92 | if err != nil {
93 | return err
94 | }
95 | *h = *nh
96 | return nil
97 | }
98 |
99 | func (h Hash) MarshalJSON() ([]byte, error) {
100 | if err := h.assertValid(); err != nil {
101 | return nil, err
102 | }
103 | return json.Marshal(h.String())
104 | }
105 |
106 | func NewHashSHA512(b []byte) *Hash {
107 | h := sha512.New()
108 | h.Write(b)
109 | nh, _ := NewHash(fmt.Sprintf("sha512-%x", h.Sum(nil)))
110 | return nh
111 | }
112 |
113 | func ShortHash(hash string) string {
114 | if len(hash) > maxHashSize {
115 | return hash[:maxHashSize]
116 | }
117 | return hash
118 | }
119 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/isolator_unix.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | )
20 |
21 | var (
22 | UnixIsolatorNames = make(map[ACIdentifier]struct{})
23 | )
24 |
25 | const (
26 | //TODO(lucab): add "ulimit" isolators
27 | UnixSysctlName = "os/unix/sysctl"
28 | )
29 |
30 | func init() {
31 | for name, con := range map[ACIdentifier]IsolatorValueConstructor{
32 | UnixSysctlName: func() IsolatorValue { return &UnixSysctl{} },
33 | } {
34 | AddIsolatorName(name, UnixIsolatorNames)
35 | AddIsolatorValueConstructor(name, con)
36 | }
37 | }
38 |
39 | type UnixSysctl map[string]string
40 |
41 | func (s *UnixSysctl) UnmarshalJSON(b []byte) error {
42 | var v map[string]string
43 | err := json.Unmarshal(b, &v)
44 | if err != nil {
45 | return err
46 | }
47 | *s = UnixSysctl(v)
48 | return err
49 | }
50 |
51 | func (s UnixSysctl) AssertValid() error {
52 | return nil
53 | }
54 |
55 | func (s UnixSysctl) multipleAllowed() bool {
56 | return false
57 | }
58 | func (s UnixSysctl) Conflicts() []ACIdentifier {
59 | return nil
60 | }
61 |
62 | func (s UnixSysctl) AsIsolator() Isolator {
63 | isol := isolatorMap[UnixSysctlName]()
64 |
65 | b, err := json.Marshal(s)
66 | if err != nil {
67 | panic(err)
68 | }
69 | valRaw := json.RawMessage(b)
70 | return Isolator{
71 | Name: UnixSysctlName,
72 | ValueRaw: &valRaw,
73 | value: isol,
74 | }
75 | }
76 |
77 | func NewUnixSysctlIsolator(cfg map[string]string) (*UnixSysctl, error) {
78 | s := UnixSysctl(cfg)
79 | if err := s.AssertValid(); err != nil {
80 | return nil, err
81 | }
82 | return &s, nil
83 | }
84 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/mountpoint.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "errors"
19 | "fmt"
20 | "net/url"
21 | "strconv"
22 |
23 | "github.com/appc/spec/schema/common"
24 | )
25 |
26 | // MountPoint is the application-side manifestation of a Volume.
27 | type MountPoint struct {
28 | Name ACName `json:"name"`
29 | Path string `json:"path"`
30 | ReadOnly bool `json:"readOnly,omitempty"`
31 | }
32 |
33 | func (mount MountPoint) assertValid() error {
34 | if mount.Name.Empty() {
35 | return errors.New("name must be set")
36 | }
37 | if len(mount.Path) == 0 {
38 | return errors.New("path must be set")
39 | }
40 | return nil
41 | }
42 |
43 | // MountPointFromString takes a command line mountpoint parameter and returns a mountpoint
44 | //
45 | // It is useful for actool patch-manifest --mounts
46 | //
47 | // Example mountpoint parameters:
48 | // database,path=/tmp,readOnly=true
49 | func MountPointFromString(mp string) (*MountPoint, error) {
50 | var mount MountPoint
51 |
52 | mp = "name=" + mp
53 | mpQuery, err := common.MakeQueryString(mp)
54 | if err != nil {
55 | return nil, err
56 | }
57 |
58 | v, err := url.ParseQuery(mpQuery)
59 | if err != nil {
60 | return nil, err
61 | }
62 | for key, val := range v {
63 | if len(val) > 1 {
64 | return nil, fmt.Errorf("label %s with multiple values %q", key, val)
65 | }
66 |
67 | switch key {
68 | case "name":
69 | acn, err := NewACName(val[0])
70 | if err != nil {
71 | return nil, err
72 | }
73 | mount.Name = *acn
74 | case "path":
75 | mount.Path = val[0]
76 | case "readOnly":
77 | ro, err := strconv.ParseBool(val[0])
78 | if err != nil {
79 | return nil, err
80 | }
81 | mount.ReadOnly = ro
82 | default:
83 | return nil, fmt.Errorf("unknown mountpoint parameter %q", key)
84 | }
85 | }
86 | err = mount.assertValid()
87 | if err != nil {
88 | return nil, err
89 | }
90 |
91 | return &mount, nil
92 | }
93 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/semver.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 |
20 | "github.com/coreos/go-semver/semver"
21 | )
22 |
23 | var (
24 | ErrNoZeroSemVer = ACVersionError("SemVer cannot be zero")
25 | ErrBadSemVer = ACVersionError("SemVer is bad")
26 | )
27 |
28 | // SemVer implements the Unmarshaler interface to define a field that must be
29 | // a semantic version string
30 | // TODO(jonboulle): extend upstream instead of wrapping?
31 | type SemVer semver.Version
32 |
33 | // NewSemVer generates a new SemVer from a string. If the given string does
34 | // not represent a valid SemVer, nil and an error are returned.
35 | func NewSemVer(s string) (*SemVer, error) {
36 | nsv, err := semver.NewVersion(s)
37 | if err != nil {
38 | return nil, ErrBadSemVer
39 | }
40 | v := SemVer(*nsv)
41 | if v.Empty() {
42 | return nil, ErrNoZeroSemVer
43 | }
44 | return &v, nil
45 | }
46 |
47 | func (sv SemVer) LessThanMajor(versionB SemVer) bool {
48 | majorA := semver.Version(sv).Major
49 | majorB := semver.Version(versionB).Major
50 | if majorA < majorB {
51 | return true
52 | }
53 | return false
54 | }
55 |
56 | func (sv SemVer) LessThanExact(versionB SemVer) bool {
57 | vA := semver.Version(sv)
58 | vB := semver.Version(versionB)
59 | return vA.LessThan(vB)
60 | }
61 |
62 | func (sv SemVer) String() string {
63 | s := semver.Version(sv)
64 | return s.String()
65 | }
66 |
67 | func (sv SemVer) Empty() bool {
68 | return semver.Version(sv) == semver.Version{}
69 | }
70 |
71 | // UnmarshalJSON implements the json.Unmarshaler interface
72 | func (sv *SemVer) UnmarshalJSON(data []byte) error {
73 | var s string
74 | if err := json.Unmarshal(data, &s); err != nil {
75 | return err
76 | }
77 | v, err := NewSemVer(s)
78 | if err != nil {
79 | return err
80 | }
81 | *sv = *v
82 | return nil
83 | }
84 |
85 | // MarshalJSON implements the json.Marshaler interface
86 | func (sv SemVer) MarshalJSON() ([]byte, error) {
87 | if sv.Empty() {
88 | return nil, ErrNoZeroSemVer
89 | }
90 | return json.Marshal(sv.String())
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/url.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/json"
19 | "fmt"
20 | "net/url"
21 | )
22 |
23 | // URL wraps url.URL to marshal/unmarshal to/from JSON strings and enforce
24 | // that the scheme is HTTP/HTTPS only
25 | type URL url.URL
26 |
27 | func NewURL(s string) (*URL, error) {
28 | uu, err := url.Parse(s)
29 | if err != nil {
30 | return nil, fmt.Errorf("bad URL: %v", err)
31 | }
32 | nu := URL(*uu)
33 | if err := nu.assertValidScheme(); err != nil {
34 | return nil, err
35 | }
36 | return &nu, nil
37 | }
38 |
39 | func (u URL) String() string {
40 | uu := url.URL(u)
41 | return uu.String()
42 | }
43 |
44 | func (u URL) assertValidScheme() error {
45 | switch u.Scheme {
46 | case "http", "https":
47 | return nil
48 | default:
49 | return fmt.Errorf("bad URL scheme, must be http/https")
50 | }
51 | }
52 |
53 | func (u *URL) UnmarshalJSON(data []byte) error {
54 | var s string
55 | if err := json.Unmarshal(data, &s); err != nil {
56 | return err
57 | }
58 | nu, err := NewURL(s)
59 | if err != nil {
60 | return err
61 | }
62 | *u = *nu
63 | return nil
64 | }
65 |
66 | func (u URL) MarshalJSON() ([]byte, error) {
67 | if err := u.assertValidScheme(); err != nil {
68 | return nil, err
69 | }
70 | return json.Marshal(u.String())
71 | }
72 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/user_annotations.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | // UserAnnotations are arbitrary key-value pairs, to be supplied and interpreted by the user
18 | type UserAnnotations map[string]string
19 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/user_labels.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | // UserLabels are arbitrary key-value pairs, to be supplied and interpreted by the user
18 | type UserLabels map[string]string
19 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/types/uuid.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package types
16 |
17 | import (
18 | "encoding/hex"
19 | "encoding/json"
20 | "errors"
21 | "fmt"
22 | "reflect"
23 | "strings"
24 | )
25 |
26 | var (
27 | ErrNoEmptyUUID = errors.New("UUID cannot be empty")
28 | )
29 |
30 | // UUID encodes an RFC4122-compliant UUID, marshaled to/from a string
31 | // TODO(jonboulle): vendor a package for this?
32 | // TODO(jonboulle): consider more flexibility in input string formats.
33 | // Right now, we only accept:
34 | // "6733C088-A507-4694-AABF-EDBE4FC5266F"
35 | // "6733C088A5074694AABFEDBE4FC5266F"
36 | type UUID [16]byte
37 |
38 | func (u UUID) String() string {
39 | return fmt.Sprintf("%x-%x-%x-%x-%x", u[0:4], u[4:6], u[6:8], u[8:10], u[10:16])
40 | }
41 |
42 | func (u *UUID) Set(s string) error {
43 | nu, err := NewUUID(s)
44 | if err == nil {
45 | *u = *nu
46 | }
47 | return err
48 | }
49 |
50 | // NewUUID generates a new UUID from the given string. If the string does not
51 | // represent a valid UUID, nil and an error are returned.
52 | func NewUUID(s string) (*UUID, error) {
53 | s = strings.Replace(s, "-", "", -1)
54 | if len(s) != 32 {
55 | return nil, errors.New("bad UUID length != 32")
56 | }
57 | dec, err := hex.DecodeString(s)
58 | if err != nil {
59 | return nil, err
60 | }
61 | var u UUID
62 | for i, b := range dec {
63 | u[i] = b
64 | }
65 | return &u, nil
66 | }
67 |
68 | func (u UUID) Empty() bool {
69 | return reflect.DeepEqual(u, UUID{})
70 | }
71 |
72 | func (u *UUID) UnmarshalJSON(data []byte) error {
73 | var s string
74 | if err := json.Unmarshal(data, &s); err != nil {
75 | return err
76 | }
77 | uu, err := NewUUID(s)
78 | if uu.Empty() {
79 | return ErrNoEmptyUUID
80 | }
81 | if err == nil {
82 | *u = *uu
83 | }
84 | return err
85 | }
86 |
87 | func (u UUID) MarshalJSON() ([]byte, error) {
88 | if u.Empty() {
89 | return nil, ErrNoEmptyUUID
90 | }
91 | return json.Marshal(u.String())
92 | }
93 |
--------------------------------------------------------------------------------
/vendor/github.com/appc/spec/schema/version.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The appc Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package schema
16 |
17 | import (
18 | "github.com/appc/spec/schema/types"
19 | )
20 |
21 | const (
22 | // version represents the canonical version of the appc spec and tooling.
23 | // For now, the schema and tooling is coupled with the spec itself, so
24 | // this must be kept in sync with the VERSION file in the root of the repo.
25 | version string = "0.8.9"
26 | )
27 |
28 | var (
29 | // AppContainerVersion is the SemVer representation of version
30 | AppContainerVersion types.SemVer
31 | )
32 |
33 | func init() {
34 | v, err := types.NewSemVer(version)
35 | if err != nil {
36 | panic(err)
37 | }
38 | AppContainerVersion = *v
39 | }
40 |
--------------------------------------------------------------------------------
/vendor/github.com/coreos/go-semver/example.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "github.com/coreos/go-semver/semver"
6 | "os"
7 | )
8 |
9 | func main() {
10 | vA, err := semver.NewVersion(os.Args[1])
11 | if err != nil {
12 | fmt.Println(err.Error())
13 | }
14 | vB, err := semver.NewVersion(os.Args[2])
15 | if err != nil {
16 | fmt.Println(err.Error())
17 | }
18 |
19 | fmt.Printf("%s < %s == %t\n", vA, vB, vA.LessThan(*vB))
20 | }
21 |
--------------------------------------------------------------------------------
/vendor/github.com/coreos/go-semver/semver/sort.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013-2015 CoreOS, Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package semver
16 |
17 | import (
18 | "sort"
19 | )
20 |
21 | type Versions []*Version
22 |
23 | func (s Versions) Len() int {
24 | return len(s)
25 | }
26 |
27 | func (s Versions) Swap(i, j int) {
28 | s[i], s[j] = s[j], s[i]
29 | }
30 |
31 | func (s Versions) Less(i, j int) bool {
32 | return s[i].LessThan(*s[j])
33 | }
34 |
35 | // Sort sorts the given slice of Version
36 | func Sort(versions []*Version) {
37 | sort.Sort(Versions(versions))
38 | }
39 |
--------------------------------------------------------------------------------
/vendor/github.com/ghodss/yaml/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Sam Ghods
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
24 | Copyright (c) 2012 The Go Authors. All rights reserved.
25 |
26 | Redistribution and use in source and binary forms, with or without
27 | modification, are permitted provided that the following conditions are
28 | met:
29 |
30 | * Redistributions of source code must retain the above copyright
31 | notice, this list of conditions and the following disclaimer.
32 | * Redistributions in binary form must reproduce the above
33 | copyright notice, this list of conditions and the following disclaimer
34 | in the documentation and/or other materials provided with the
35 | distribution.
36 | * Neither the name of Google Inc. nor the names of its
37 | contributors may be used to endorse or promote products derived from
38 | this software without specific prior written permission.
39 |
40 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 |
--------------------------------------------------------------------------------
/vendor/github.com/gogo/protobuf/LICENSE:
--------------------------------------------------------------------------------
1 | Extensions for Protocol Buffers to create more go like structures.
2 |
3 | Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4 | http://github.com/gogo/protobuf/gogoproto
5 |
6 | Go support for Protocol Buffers - Google's data interchange format
7 |
8 | Copyright 2010 The Go Authors. All rights reserved.
9 | https://github.com/golang/protobuf
10 |
11 | Redistribution and use in source and binary forms, with or without
12 | modification, are permitted provided that the following conditions are
13 | met:
14 |
15 | * Redistributions of source code must retain the above copyright
16 | notice, this list of conditions and the following disclaimer.
17 | * Redistributions in binary form must reproduce the above
18 | copyright notice, this list of conditions and the following disclaimer
19 | in the documentation and/or other materials provided with the
20 | distribution.
21 | * Neither the name of Google Inc. nor the names of its
22 | contributors may be used to endorse or promote products derived from
23 | this software without specific prior written permission.
24 |
25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 |
37 |
--------------------------------------------------------------------------------
/vendor/github.com/gogo/protobuf/proto/lib_gogo.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2 | // http://github.com/gogo/protobuf/gogoproto
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | //
15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | package proto
28 |
29 | import (
30 | "encoding/json"
31 | "strconv"
32 | )
33 |
34 | func MarshalJSONEnum(m map[int32]string, value int32) ([]byte, error) {
35 | s, ok := m[value]
36 | if !ok {
37 | s = strconv.Itoa(int(value))
38 | }
39 | return json.Marshal(s)
40 | }
41 |
--------------------------------------------------------------------------------
/vendor/github.com/gogo/protobuf/proto/properties_gogo.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2 | // http://github.com/gogo/protobuf/gogoproto
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | //
15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | package proto
28 |
29 | import (
30 | "fmt"
31 | "os"
32 | "reflect"
33 | )
34 |
35 | func (p *Properties) setCustomEncAndDec(typ reflect.Type) {
36 | p.ctype = typ
37 | if p.Repeated {
38 | p.enc = (*Buffer).enc_custom_slice_bytes
39 | p.dec = (*Buffer).dec_custom_slice_bytes
40 | p.size = size_custom_slice_bytes
41 | } else if typ.Kind() == reflect.Ptr {
42 | p.enc = (*Buffer).enc_custom_bytes
43 | p.dec = (*Buffer).dec_custom_bytes
44 | p.size = size_custom_bytes
45 | } else {
46 | p.enc = (*Buffer).enc_custom_ref_bytes
47 | p.dec = (*Buffer).dec_custom_ref_bytes
48 | p.size = size_custom_ref_bytes
49 | }
50 | }
51 |
52 | func (p *Properties) setSliceOfNonPointerStructs(typ reflect.Type) {
53 | t2 := typ.Elem()
54 | p.sstype = typ
55 | p.stype = t2
56 | p.isMarshaler = isMarshaler(t2)
57 | p.isUnmarshaler = isUnmarshaler(t2)
58 | p.enc = (*Buffer).enc_slice_ref_struct_message
59 | p.dec = (*Buffer).dec_slice_ref_struct_message
60 | p.size = size_slice_ref_struct_message
61 | if p.Wire != "bytes" {
62 | fmt.Fprintf(os.Stderr, "proto: no ptr oenc for %T -> %T \n", typ, t2)
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/vendor/github.com/gogo/protobuf/proto/skip_gogo.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2 | // http://github.com/gogo/protobuf/gogoproto
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | //
15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | package proto
28 |
29 | import (
30 | "fmt"
31 | "io"
32 | )
33 |
34 | func Skip(data []byte) (n int, err error) {
35 | l := len(data)
36 | index := 0
37 | for index < l {
38 | var wire uint64
39 | for shift := uint(0); ; shift += 7 {
40 | if index >= l {
41 | return 0, io.ErrUnexpectedEOF
42 | }
43 | b := data[index]
44 | index++
45 | wire |= (uint64(b) & 0x7F) << shift
46 | if b < 0x80 {
47 | break
48 | }
49 | }
50 | wireType := int(wire & 0x7)
51 | switch wireType {
52 | case 0:
53 | for {
54 | if index >= l {
55 | return 0, io.ErrUnexpectedEOF
56 | }
57 | index++
58 | if data[index-1] < 0x80 {
59 | break
60 | }
61 | }
62 | return index, nil
63 | case 1:
64 | index += 8
65 | return index, nil
66 | case 2:
67 | var length int
68 | for shift := uint(0); ; shift += 7 {
69 | if index >= l {
70 | return 0, io.ErrUnexpectedEOF
71 | }
72 | b := data[index]
73 | index++
74 | length |= (int(b) & 0x7F) << shift
75 | if b < 0x80 {
76 | break
77 | }
78 | }
79 | index += length
80 | return index, nil
81 | case 3:
82 | for {
83 | var innerWire uint64
84 | var start int = index
85 | for shift := uint(0); ; shift += 7 {
86 | if index >= l {
87 | return 0, io.ErrUnexpectedEOF
88 | }
89 | b := data[index]
90 | index++
91 | innerWire |= (uint64(b) & 0x7F) << shift
92 | if b < 0x80 {
93 | break
94 | }
95 | }
96 | innerWireType := int(innerWire & 0x7)
97 | if innerWireType == 4 {
98 | break
99 | }
100 | next, err := Skip(data[start:])
101 | if err != nil {
102 | return 0, err
103 | }
104 | index = start + next
105 | }
106 | return index, nil
107 | case 4:
108 | return index, nil
109 | case 5:
110 | index += 4
111 | return index, nil
112 | default:
113 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
114 | }
115 | }
116 | panic("unreachable")
117 | }
118 |
--------------------------------------------------------------------------------
/vendor/github.com/gogo/protobuf/proto/text_gogo.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2 | // http://github.com/gogo/protobuf/gogoproto
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | //
15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | package proto
28 |
29 | import (
30 | "fmt"
31 | "reflect"
32 | )
33 |
34 | func writeEnum(w *textWriter, v reflect.Value, props *Properties) error {
35 | m, ok := enumStringMaps[props.Enum]
36 | if !ok {
37 | if err := writeAny(w, v, props); err != nil {
38 | return err
39 | }
40 | }
41 | key := int32(0)
42 | if v.Kind() == reflect.Ptr {
43 | key = int32(v.Elem().Int())
44 | } else {
45 | key = int32(v.Int())
46 | }
47 | s, ok := m[key]
48 | if !ok {
49 | if err := writeAny(w, v, props); err != nil {
50 | return err
51 | }
52 | }
53 | _, err := fmt.Fprint(w, s)
54 | return err
55 | }
56 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/context/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/context/context.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Gorilla Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package context
6 |
7 | import (
8 | "net/http"
9 | "sync"
10 | "time"
11 | )
12 |
13 | var (
14 | mutex sync.RWMutex
15 | data = make(map[*http.Request]map[interface{}]interface{})
16 | datat = make(map[*http.Request]int64)
17 | )
18 |
19 | // Set stores a value for a given key in a given request.
20 | func Set(r *http.Request, key, val interface{}) {
21 | mutex.Lock()
22 | if data[r] == nil {
23 | data[r] = make(map[interface{}]interface{})
24 | datat[r] = time.Now().Unix()
25 | }
26 | data[r][key] = val
27 | mutex.Unlock()
28 | }
29 |
30 | // Get returns a value stored for a given key in a given request.
31 | func Get(r *http.Request, key interface{}) interface{} {
32 | mutex.RLock()
33 | if ctx := data[r]; ctx != nil {
34 | value := ctx[key]
35 | mutex.RUnlock()
36 | return value
37 | }
38 | mutex.RUnlock()
39 | return nil
40 | }
41 |
42 | // GetOk returns stored value and presence state like multi-value return of map access.
43 | func GetOk(r *http.Request, key interface{}) (interface{}, bool) {
44 | mutex.RLock()
45 | if _, ok := data[r]; ok {
46 | value, ok := data[r][key]
47 | mutex.RUnlock()
48 | return value, ok
49 | }
50 | mutex.RUnlock()
51 | return nil, false
52 | }
53 |
54 | // GetAll returns all stored values for the request as a map. Nil is returned for invalid requests.
55 | func GetAll(r *http.Request) map[interface{}]interface{} {
56 | mutex.RLock()
57 | if context, ok := data[r]; ok {
58 | result := make(map[interface{}]interface{}, len(context))
59 | for k, v := range context {
60 | result[k] = v
61 | }
62 | mutex.RUnlock()
63 | return result
64 | }
65 | mutex.RUnlock()
66 | return nil
67 | }
68 |
69 | // GetAllOk returns all stored values for the request as a map and a boolean value that indicates if
70 | // the request was registered.
71 | func GetAllOk(r *http.Request) (map[interface{}]interface{}, bool) {
72 | mutex.RLock()
73 | context, ok := data[r]
74 | result := make(map[interface{}]interface{}, len(context))
75 | for k, v := range context {
76 | result[k] = v
77 | }
78 | mutex.RUnlock()
79 | return result, ok
80 | }
81 |
82 | // Delete removes a value stored for a given key in a given request.
83 | func Delete(r *http.Request, key interface{}) {
84 | mutex.Lock()
85 | if data[r] != nil {
86 | delete(data[r], key)
87 | }
88 | mutex.Unlock()
89 | }
90 |
91 | // Clear removes all values stored for a given request.
92 | //
93 | // This is usually called by a handler wrapper to clean up request
94 | // variables at the end of a request lifetime. See ClearHandler().
95 | func Clear(r *http.Request) {
96 | mutex.Lock()
97 | clear(r)
98 | mutex.Unlock()
99 | }
100 |
101 | // clear is Clear without the lock.
102 | func clear(r *http.Request) {
103 | delete(data, r)
104 | delete(datat, r)
105 | }
106 |
107 | // Purge removes request data stored for longer than maxAge, in seconds.
108 | // It returns the amount of requests removed.
109 | //
110 | // If maxAge <= 0, all request data is removed.
111 | //
112 | // This is only used for sanity check: in case context cleaning was not
113 | // properly set some request data can be kept forever, consuming an increasing
114 | // amount of memory. In case this is detected, Purge() must be called
115 | // periodically until the problem is fixed.
116 | func Purge(maxAge int) int {
117 | mutex.Lock()
118 | count := 0
119 | if maxAge <= 0 {
120 | count = len(data)
121 | data = make(map[*http.Request]map[interface{}]interface{})
122 | datat = make(map[*http.Request]int64)
123 | } else {
124 | min := time.Now().Unix() - int64(maxAge)
125 | for r := range data {
126 | if datat[r] < min {
127 | clear(r)
128 | count++
129 | }
130 | }
131 | }
132 | mutex.Unlock()
133 | return count
134 | }
135 |
136 | // ClearHandler wraps an http.Handler and clears request values at the end
137 | // of a request lifetime.
138 | func ClearHandler(h http.Handler) http.Handler {
139 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
140 | defer Clear(r)
141 | h.ServeHTTP(w, r)
142 | })
143 | }
144 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/context/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Gorilla Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | /*
6 | Package context stores values shared during a request lifetime.
7 |
8 | Note: gorilla/context, having been born well before `context.Context` existed,
9 | does not play well > with the shallow copying of the request that
10 | [`http.Request.WithContext`](https://golang.org/pkg/net/http/#Request.WithContext)
11 | (added to net/http Go 1.7 onwards) performs. You should either use *just*
12 | gorilla/context, or moving forward, the new `http.Request.Context()`.
13 |
14 | For example, a router can set variables extracted from the URL and later
15 | application handlers can access those values, or it can be used to store
16 | sessions values to be saved at the end of a request. There are several
17 | others common uses.
18 |
19 | The idea was posted by Brad Fitzpatrick to the go-nuts mailing list:
20 |
21 | http://groups.google.com/group/golang-nuts/msg/e2d679d303aa5d53
22 |
23 | Here's the basic usage: first define the keys that you will need. The key
24 | type is interface{} so a key can be of any type that supports equality.
25 | Here we define a key using a custom int type to avoid name collisions:
26 |
27 | package foo
28 |
29 | import (
30 | "github.com/gorilla/context"
31 | )
32 |
33 | type key int
34 |
35 | const MyKey key = 0
36 |
37 | Then set a variable. Variables are bound to an http.Request object, so you
38 | need a request instance to set a value:
39 |
40 | context.Set(r, MyKey, "bar")
41 |
42 | The application can later access the variable using the same key you provided:
43 |
44 | func MyHandler(w http.ResponseWriter, r *http.Request) {
45 | // val is "bar".
46 | val := context.Get(r, foo.MyKey)
47 |
48 | // returns ("bar", true)
49 | val, ok := context.GetOk(r, foo.MyKey)
50 | // ...
51 | }
52 |
53 | And that's all about the basic usage. We discuss some other ideas below.
54 |
55 | Any type can be stored in the context. To enforce a given type, make the key
56 | private and wrap Get() and Set() to accept and return values of a specific
57 | type:
58 |
59 | type key int
60 |
61 | const mykey key = 0
62 |
63 | // GetMyKey returns a value for this package from the request values.
64 | func GetMyKey(r *http.Request) SomeType {
65 | if rv := context.Get(r, mykey); rv != nil {
66 | return rv.(SomeType)
67 | }
68 | return nil
69 | }
70 |
71 | // SetMyKey sets a value for this package in the request values.
72 | func SetMyKey(r *http.Request, val SomeType) {
73 | context.Set(r, mykey, val)
74 | }
75 |
76 | Variables must be cleared at the end of a request, to remove all values
77 | that were stored. This can be done in an http.Handler, after a request was
78 | served. Just call Clear() passing the request:
79 |
80 | context.Clear(r)
81 |
82 | ...or use ClearHandler(), which conveniently wraps an http.Handler to clear
83 | variables at the end of a request lifetime.
84 |
85 | The Routers from the packages gorilla/mux and gorilla/pat call Clear()
86 | so if you are using either of them you don't need to clear the context manually.
87 | */
88 | package context
89 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/handlers/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 The Gorilla Handlers Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are met:
5 |
6 | Redistributions of source code must retain the above copyright notice, this
7 | list of conditions and the following disclaimer.
8 |
9 | Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 |
13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/handlers/canonical.go:
--------------------------------------------------------------------------------
1 | package handlers
2 |
3 | import (
4 | "net/http"
5 | "net/url"
6 | "strings"
7 | )
8 |
9 | type canonical struct {
10 | h http.Handler
11 | domain string
12 | code int
13 | }
14 |
15 | // CanonicalHost is HTTP middleware that re-directs requests to the canonical
16 | // domain. It accepts a domain and a status code (e.g. 301 or 302) and
17 | // re-directs clients to this domain. The existing request path is maintained.
18 | //
19 | // Note: If the provided domain is considered invalid by url.Parse or otherwise
20 | // returns an empty scheme or host, clients are not re-directed.
21 | //
22 | // Example:
23 | //
24 | // r := mux.NewRouter()
25 | // canonical := handlers.CanonicalHost("http://www.gorillatoolkit.org", 302)
26 | // r.HandleFunc("/route", YourHandler)
27 | //
28 | // log.Fatal(http.ListenAndServe(":7000", canonical(r)))
29 | //
30 | func CanonicalHost(domain string, code int) func(h http.Handler) http.Handler {
31 | fn := func(h http.Handler) http.Handler {
32 | return canonical{h, domain, code}
33 | }
34 |
35 | return fn
36 | }
37 |
38 | func (c canonical) ServeHTTP(w http.ResponseWriter, r *http.Request) {
39 | dest, err := url.Parse(c.domain)
40 | if err != nil {
41 | // Call the next handler if the provided domain fails to parse.
42 | c.h.ServeHTTP(w, r)
43 | return
44 | }
45 |
46 | if dest.Scheme == "" || dest.Host == "" {
47 | // Call the next handler if the scheme or host are empty.
48 | // Note that url.Parse won't fail on in this case.
49 | c.h.ServeHTTP(w, r)
50 | return
51 | }
52 |
53 | if !strings.EqualFold(cleanHost(r.Host), dest.Host) {
54 | // Re-build the destination URL
55 | dest := dest.Scheme + "://" + dest.Host + r.URL.Path
56 | if r.URL.RawQuery != "" {
57 | dest += "?" + r.URL.RawQuery
58 | }
59 | http.Redirect(w, r, dest, c.code)
60 | return
61 | }
62 |
63 | c.h.ServeHTTP(w, r)
64 | }
65 |
66 | // cleanHost cleans invalid Host headers by stripping anything after '/' or ' '.
67 | // This is backported from Go 1.5 (in response to issue #11206) and attempts to
68 | // mitigate malformed Host headers that do not match the format in RFC7230.
69 | func cleanHost(in string) string {
70 | if i := strings.IndexAny(in, " /"); i != -1 {
71 | return in[:i]
72 | }
73 | return in
74 | }
75 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/handlers/compress.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Gorilla Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package handlers
6 |
7 | import (
8 | "compress/flate"
9 | "compress/gzip"
10 | "io"
11 | "net/http"
12 | "strings"
13 | )
14 |
15 | type compressResponseWriter struct {
16 | io.Writer
17 | http.ResponseWriter
18 | http.Hijacker
19 | http.Flusher
20 | http.CloseNotifier
21 | }
22 |
23 | func (w *compressResponseWriter) WriteHeader(c int) {
24 | w.ResponseWriter.Header().Del("Content-Length")
25 | w.ResponseWriter.WriteHeader(c)
26 | }
27 |
28 | func (w *compressResponseWriter) Header() http.Header {
29 | return w.ResponseWriter.Header()
30 | }
31 |
32 | func (w *compressResponseWriter) Write(b []byte) (int, error) {
33 | h := w.ResponseWriter.Header()
34 | if h.Get("Content-Type") == "" {
35 | h.Set("Content-Type", http.DetectContentType(b))
36 | }
37 | h.Del("Content-Length")
38 |
39 | return w.Writer.Write(b)
40 | }
41 |
42 | type flusher interface {
43 | Flush() error
44 | }
45 |
46 | func (w *compressResponseWriter) Flush() {
47 | // Flush compressed data if compressor supports it.
48 | if f, ok := w.Writer.(flusher); ok {
49 | f.Flush()
50 | }
51 | // Flush HTTP response.
52 | if w.Flusher != nil {
53 | w.Flusher.Flush()
54 | }
55 | }
56 |
57 | // CompressHandler gzip compresses HTTP responses for clients that support it
58 | // via the 'Accept-Encoding' header.
59 | func CompressHandler(h http.Handler) http.Handler {
60 | return CompressHandlerLevel(h, gzip.DefaultCompression)
61 | }
62 |
63 | // CompressHandlerLevel gzip compresses HTTP responses with specified compression level
64 | // for clients that support it via the 'Accept-Encoding' header.
65 | //
66 | // The compression level should be gzip.DefaultCompression, gzip.NoCompression,
67 | // or any integer value between gzip.BestSpeed and gzip.BestCompression inclusive.
68 | // gzip.DefaultCompression is used in case of invalid compression level.
69 | func CompressHandlerLevel(h http.Handler, level int) http.Handler {
70 | if level < gzip.DefaultCompression || level > gzip.BestCompression {
71 | level = gzip.DefaultCompression
72 | }
73 |
74 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
75 | L:
76 | for _, enc := range strings.Split(r.Header.Get("Accept-Encoding"), ",") {
77 | switch strings.TrimSpace(enc) {
78 | case "gzip":
79 | w.Header().Set("Content-Encoding", "gzip")
80 | w.Header().Add("Vary", "Accept-Encoding")
81 |
82 | gw, _ := gzip.NewWriterLevel(w, level)
83 | defer gw.Close()
84 |
85 | h, hok := w.(http.Hijacker)
86 | if !hok { /* w is not Hijacker... oh well... */
87 | h = nil
88 | }
89 |
90 | f, fok := w.(http.Flusher)
91 | if !fok {
92 | f = nil
93 | }
94 |
95 | cn, cnok := w.(http.CloseNotifier)
96 | if !cnok {
97 | cn = nil
98 | }
99 |
100 | w = &compressResponseWriter{
101 | Writer: gw,
102 | ResponseWriter: w,
103 | Hijacker: h,
104 | Flusher: f,
105 | CloseNotifier: cn,
106 | }
107 |
108 | break L
109 | case "deflate":
110 | w.Header().Set("Content-Encoding", "deflate")
111 | w.Header().Add("Vary", "Accept-Encoding")
112 |
113 | fw, _ := flate.NewWriter(w, level)
114 | defer fw.Close()
115 |
116 | h, hok := w.(http.Hijacker)
117 | if !hok { /* w is not Hijacker... oh well... */
118 | h = nil
119 | }
120 |
121 | f, fok := w.(http.Flusher)
122 | if !fok {
123 | f = nil
124 | }
125 |
126 | cn, cnok := w.(http.CloseNotifier)
127 | if !cnok {
128 | cn = nil
129 | }
130 |
131 | w = &compressResponseWriter{
132 | Writer: fw,
133 | ResponseWriter: w,
134 | Hijacker: h,
135 | Flusher: f,
136 | CloseNotifier: cn,
137 | }
138 |
139 | break L
140 | }
141 | }
142 |
143 | h.ServeHTTP(w, r)
144 | })
145 | }
146 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/handlers/doc.go:
--------------------------------------------------------------------------------
1 | /*
2 | Package handlers is a collection of handlers (aka "HTTP middleware") for use
3 | with Go's net/http package (or any framework supporting http.Handler).
4 |
5 | The package includes handlers for logging in standardised formats, compressing
6 | HTTP responses, validating content types and other useful tools for manipulating
7 | requests and responses.
8 | */
9 | package handlers
10 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/handlers/recovery.go:
--------------------------------------------------------------------------------
1 | package handlers
2 |
3 | import (
4 | "log"
5 | "net/http"
6 | "runtime/debug"
7 | )
8 |
9 | type recoveryHandler struct {
10 | handler http.Handler
11 | logger *log.Logger
12 | printStack bool
13 | }
14 |
15 | // RecoveryOption provides a functional approach to define
16 | // configuration for a handler; such as setting the logging
17 | // whether or not to print strack traces on panic.
18 | type RecoveryOption func(http.Handler)
19 |
20 | func parseRecoveryOptions(h http.Handler, opts ...RecoveryOption) http.Handler {
21 | for _, option := range opts {
22 | option(h)
23 | }
24 |
25 | return h
26 | }
27 |
28 | // RecoveryHandler is HTTP middleware that recovers from a panic,
29 | // logs the panic, writes http.StatusInternalServerError, and
30 | // continues to the next handler.
31 | //
32 | // Example:
33 | //
34 | // r := mux.NewRouter()
35 | // r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
36 | // panic("Unexpected error!")
37 | // })
38 | //
39 | // http.ListenAndServe(":1123", handlers.RecoveryHandler()(r))
40 | func RecoveryHandler(opts ...RecoveryOption) func(h http.Handler) http.Handler {
41 | return func(h http.Handler) http.Handler {
42 | r := &recoveryHandler{handler: h}
43 | return parseRecoveryOptions(r, opts...)
44 | }
45 | }
46 |
47 | // RecoveryLogger is a functional option to override
48 | // the default logger
49 | func RecoveryLogger(logger *log.Logger) RecoveryOption {
50 | return func(h http.Handler) {
51 | r := h.(*recoveryHandler)
52 | r.logger = logger
53 | }
54 | }
55 |
56 | // PrintRecoveryStack is a functional option to enable
57 | // or disable printing stack traces on panic.
58 | func PrintRecoveryStack(print bool) RecoveryOption {
59 | return func(h http.Handler) {
60 | r := h.(*recoveryHandler)
61 | r.printStack = print
62 | }
63 | }
64 |
65 | func (h recoveryHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
66 | defer func() {
67 | if err := recover(); err != nil {
68 | w.WriteHeader(http.StatusInternalServerError)
69 | h.log(err)
70 | }
71 | }()
72 |
73 | h.handler.ServeHTTP(w, req)
74 | }
75 |
76 | func (h recoveryHandler) log(message interface{}) {
77 | if h.logger != nil {
78 | h.logger.Println(message)
79 | } else {
80 | log.Println(message)
81 | }
82 |
83 | if h.printStack {
84 | debug.PrintStack()
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/vendor/github.com/gorilla/mux/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/github.com/inconshreveable/mousetrap/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2014 Alan Shreve
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/vendor/github.com/inconshreveable/mousetrap/trap_others.go:
--------------------------------------------------------------------------------
1 | // +build !windows
2 |
3 | package mousetrap
4 |
5 | // StartedByExplorer returns true if the program was invoked by the user
6 | // double-clicking on the executable from explorer.exe
7 | //
8 | // It is conservative and returns false if any of the internal calls fail.
9 | // It does not guarantee that the program was run from a terminal. It only can tell you
10 | // whether it was launched from explorer.exe
11 | //
12 | // On non-Windows platforms, it always returns false.
13 | func StartedByExplorer() bool {
14 | return false
15 | }
16 |
--------------------------------------------------------------------------------
/vendor/github.com/inconshreveable/mousetrap/trap_windows.go:
--------------------------------------------------------------------------------
1 | // +build windows
2 | // +build !go1.4
3 |
4 | package mousetrap
5 |
6 | import (
7 | "fmt"
8 | "os"
9 | "syscall"
10 | "unsafe"
11 | )
12 |
13 | const (
14 | // defined by the Win32 API
15 | th32cs_snapprocess uintptr = 0x2
16 | )
17 |
18 | var (
19 | kernel = syscall.MustLoadDLL("kernel32.dll")
20 | CreateToolhelp32Snapshot = kernel.MustFindProc("CreateToolhelp32Snapshot")
21 | Process32First = kernel.MustFindProc("Process32FirstW")
22 | Process32Next = kernel.MustFindProc("Process32NextW")
23 | )
24 |
25 | // ProcessEntry32 structure defined by the Win32 API
26 | type processEntry32 struct {
27 | dwSize uint32
28 | cntUsage uint32
29 | th32ProcessID uint32
30 | th32DefaultHeapID int
31 | th32ModuleID uint32
32 | cntThreads uint32
33 | th32ParentProcessID uint32
34 | pcPriClassBase int32
35 | dwFlags uint32
36 | szExeFile [syscall.MAX_PATH]uint16
37 | }
38 |
39 | func getProcessEntry(pid int) (pe *processEntry32, err error) {
40 | snapshot, _, e1 := CreateToolhelp32Snapshot.Call(th32cs_snapprocess, uintptr(0))
41 | if snapshot == uintptr(syscall.InvalidHandle) {
42 | err = fmt.Errorf("CreateToolhelp32Snapshot: %v", e1)
43 | return
44 | }
45 | defer syscall.CloseHandle(syscall.Handle(snapshot))
46 |
47 | var processEntry processEntry32
48 | processEntry.dwSize = uint32(unsafe.Sizeof(processEntry))
49 | ok, _, e1 := Process32First.Call(snapshot, uintptr(unsafe.Pointer(&processEntry)))
50 | if ok == 0 {
51 | err = fmt.Errorf("Process32First: %v", e1)
52 | return
53 | }
54 |
55 | for {
56 | if processEntry.th32ProcessID == uint32(pid) {
57 | pe = &processEntry
58 | return
59 | }
60 |
61 | ok, _, e1 = Process32Next.Call(snapshot, uintptr(unsafe.Pointer(&processEntry)))
62 | if ok == 0 {
63 | err = fmt.Errorf("Process32Next: %v", e1)
64 | return
65 | }
66 | }
67 | }
68 |
69 | func getppid() (pid int, err error) {
70 | pe, err := getProcessEntry(os.Getpid())
71 | if err != nil {
72 | return
73 | }
74 |
75 | pid = int(pe.th32ParentProcessID)
76 | return
77 | }
78 |
79 | // StartedByExplorer returns true if the program was invoked by the user double-clicking
80 | // on the executable from explorer.exe
81 | //
82 | // It is conservative and returns false if any of the internal calls fail.
83 | // It does not guarantee that the program was run from a terminal. It only can tell you
84 | // whether it was launched from explorer.exe
85 | func StartedByExplorer() bool {
86 | ppid, err := getppid()
87 | if err != nil {
88 | return false
89 | }
90 |
91 | pe, err := getProcessEntry(ppid)
92 | if err != nil {
93 | return false
94 | }
95 |
96 | name := syscall.UTF16ToString(pe.szExeFile[:])
97 | return name == "explorer.exe"
98 | }
99 |
--------------------------------------------------------------------------------
/vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go:
--------------------------------------------------------------------------------
1 | // +build windows
2 | // +build go1.4
3 |
4 | package mousetrap
5 |
6 | import (
7 | "os"
8 | "syscall"
9 | "unsafe"
10 | )
11 |
12 | func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) {
13 | snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0)
14 | if err != nil {
15 | return nil, err
16 | }
17 | defer syscall.CloseHandle(snapshot)
18 | var procEntry syscall.ProcessEntry32
19 | procEntry.Size = uint32(unsafe.Sizeof(procEntry))
20 | if err = syscall.Process32First(snapshot, &procEntry); err != nil {
21 | return nil, err
22 | }
23 | for {
24 | if procEntry.ProcessID == uint32(pid) {
25 | return &procEntry, nil
26 | }
27 | err = syscall.Process32Next(snapshot, &procEntry)
28 | if err != nil {
29 | return nil, err
30 | }
31 | }
32 | }
33 |
34 | // StartedByExplorer returns true if the program was invoked by the user double-clicking
35 | // on the executable from explorer.exe
36 | //
37 | // It is conservative and returns false if any of the internal calls fail.
38 | // It does not guarantee that the program was run from a terminal. It only can tell you
39 | // whether it was launched from explorer.exe
40 | func StartedByExplorer() bool {
41 | pe, err := getProcessEntry(os.Getppid())
42 | if err != nil {
43 | return false
44 | }
45 | return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:])
46 | }
47 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/appender.go:
--------------------------------------------------------------------------------
1 | package erlog
2 |
3 | import (
4 | "github.com/n0rad/go-erlog/logs"
5 | )
6 |
7 | type Appender interface {
8 | Fire(event *LogEvent)
9 | GetLevel() logs.Level
10 | SetLevel(level logs.Level)
11 | }
12 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/data/data.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | type Fields map[string]interface{}
4 |
5 | type FieldsConverter interface {
6 | ToFields() Fields
7 | }
8 |
9 | func WithField(key string, value interface{}) Fields {
10 | i := make(Fields, 3)
11 | return i.WithField(key, value)
12 | }
13 |
14 | func WithFields(fields FieldsConverter) Fields {
15 | return fields.ToFields()
16 | }
17 |
18 | func (f Fields) WithField(key string, value interface{}) Fields {
19 | n := f.copy()
20 | n[key] = value
21 | return n
22 | }
23 |
24 | func (f Fields) WithFields(data Fields) Fields {
25 | n := f.copy()
26 | for k, v := range data {
27 | n[k] = v
28 | }
29 | return n
30 | }
31 |
32 | func (f Fields) copy() Fields {
33 | data := Fields{}
34 | for k, v := range f {
35 | data[k] = v
36 | }
37 | return data
38 | }
39 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/errs/entry.go:
--------------------------------------------------------------------------------
1 | package errs
2 |
3 | import (
4 | "bytes"
5 | "fmt"
6 | "github.com/n0rad/go-erlog/data"
7 | "runtime"
8 | )
9 |
10 | var MaxStackDepth = 50
11 |
12 | type EntryError struct {
13 | Fields data.Fields
14 | Message string
15 | Errs []error
16 | Stack []uintptr
17 | frames []StackFrame
18 | }
19 |
20 | func With(message string) *EntryError {
21 | return fill(&EntryError{
22 | Message: message,
23 | })
24 | }
25 |
26 | func WithF(fields data.Fields, msg string) *EntryError {
27 | return fill(&EntryError{
28 | Fields: fields,
29 | Message: msg,
30 | })
31 | }
32 |
33 | func WithE(err error, msg string) *EntryError {
34 | return fill(&EntryError{
35 | Errs: []error{err},
36 | Message: msg,
37 | })
38 | }
39 |
40 | func WithEF(err error, fields data.Fields, msg string) *EntryError {
41 | return fill(&EntryError{
42 | Errs: []error{err},
43 | Fields: fields,
44 | Message: msg,
45 | })
46 | }
47 |
48 | func fill(entry *EntryError) *EntryError {
49 | stack := make([]uintptr, MaxStackDepth)
50 | length := runtime.Callers(2, stack[:])
51 | entry.Stack = stack[:length]
52 | return entry
53 | }
54 |
55 | ///////////////////////////////////////////////
56 |
57 | func Is(e1 error, e2 error) bool {
58 | if e1 == e2 {
59 | return true
60 | }
61 |
62 | ee1, ok1 := e1.(*EntryError)
63 | ee2, ok2 := e2.(*EntryError)
64 | if ok1 && ok2 && ee1.Message == ee2.Message {
65 | return true
66 | }
67 |
68 | if e1.Error() == e2.Error() {
69 | return true
70 | }
71 |
72 | return false
73 | }
74 |
75 | //////////////////////////////////////////////
76 |
77 | func (e *EntryError) WithFields(data data.Fields) *EntryError {
78 | e.Fields = data
79 | return e
80 | }
81 |
82 | func (e *EntryError) WithErr(err error) *EntryError {
83 | if err != nil {
84 | e.Errs = append(e.Errs, err)
85 | }
86 | return e
87 | }
88 |
89 | func (e *EntryError) WithErrs(errs ...error) *EntryError {
90 | for _, err := range errs {
91 | if err != nil {
92 | e.Errs = append(e.Errs, err)
93 | }
94 | }
95 | return e
96 | }
97 |
98 | func (e *EntryError) WithField(name string, value interface{}) *EntryError {
99 | if e.Fields == nil {
100 | e.Fields = data.WithField(name, value)
101 | } else {
102 | e.Fields = e.Fields.WithField(name, value)
103 | }
104 | return e
105 | }
106 |
107 | func (e *EntryError) WithMessage(msg string) *EntryError {
108 | e.Message = msg
109 | return e
110 | }
111 |
112 | func (e *EntryError) Error() string {
113 | var buffer bytes.Buffer
114 | buffer.WriteString(e.Message)
115 | if e.Fields != nil {
116 | for key := range e.Fields {
117 | buffer.WriteString(" ")
118 | buffer.WriteString(key)
119 | buffer.WriteString("=")
120 | buffer.WriteString(fmt.Sprintf("%+v", e.Fields[key]))
121 | }
122 | }
123 | buffer.WriteString("\n")
124 | if e.Errs != nil {
125 | buffer.WriteString("Caused by : ")
126 | for i, err := range e.Errs {
127 | if err == nil {
128 | continue
129 | }
130 | if i > 0 {
131 | buffer.WriteString("And\n")
132 | }
133 | buffer.WriteString(err.Error())
134 | buffer.WriteString("\n")
135 | }
136 | }
137 | return buffer.String()
138 | }
139 |
140 | func (e *EntryError) String() string {
141 | return e.Error()
142 | }
143 |
144 | //
145 | //func (e *EntryError) Stack() []byte {
146 | // buf := bytes.Buffer{}
147 | //
148 | // for _, frame := range e.StackFrames() {
149 | // buf.WriteString(frame.String())
150 | // }
151 | //
152 | // return buf.Bytes()
153 | //}
154 | //
155 | //func (e *EntryError) StackFrames() []StackFrame {
156 | // if e.frames == nil {
157 | // e.frames = make([]StackFrame, len(e.stack))
158 | // for i, pc := range e.stack {
159 | // e.frames[i] = NewStackFrame(pc)
160 | // }
161 | // }
162 | // return e.frames
163 | //}
164 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/errs/stackframe.go:
--------------------------------------------------------------------------------
1 | package errs
2 |
3 | import (
4 | "bytes"
5 | "fmt"
6 | "io/ioutil"
7 | "runtime"
8 | "strings"
9 | )
10 |
11 | // A StackFrame contains all necessary information about to generate a line
12 | // in a callstack.
13 | type StackFrame struct {
14 | // The path to the file containing this ProgramCounter
15 | File string
16 | // The LineNumber in that file
17 | LineNumber int
18 | // The Name of the function that contains this ProgramCounter
19 | Name string
20 | // The Package that contains this function
21 | Package string
22 | // The underlying ProgramCounter
23 | ProgramCounter uintptr
24 | }
25 |
26 | // NewStackFrame popoulates a stack frame object from the program counter.
27 | func NewStackFrame(pc uintptr) (frame StackFrame) {
28 |
29 | frame = StackFrame{ProgramCounter: pc}
30 | if frame.Func() == nil {
31 | return
32 | }
33 | frame.Package, frame.Name = packageAndName(frame.Func())
34 |
35 | // pc -1 because the program counters we use are usually return addresses,
36 | // and we want to show the line that corresponds to the function call
37 | frame.File, frame.LineNumber = frame.Func().FileLine(pc - 1)
38 | return
39 |
40 | }
41 |
42 | // Func returns the function that contained this frame.
43 | func (frame *StackFrame) Func() *runtime.Func {
44 | if frame.ProgramCounter == 0 {
45 | return nil
46 | }
47 | return runtime.FuncForPC(frame.ProgramCounter)
48 | }
49 |
50 | // String returns the stackframe formatted in the same way as go does
51 | // in runtime/debug.Stack()
52 | func (frame *StackFrame) String() string {
53 | str := fmt.Sprintf("%s:%d (0x%x)\n", frame.File, frame.LineNumber, frame.ProgramCounter)
54 |
55 | source, err := frame.SourceLine()
56 | if err != nil {
57 | return str
58 | }
59 |
60 | return str + fmt.Sprintf("\t%s: %s\n", frame.Name, source)
61 | }
62 |
63 | // SourceLine gets the line of code (from File and Line) of the original source if possible.
64 | func (frame *StackFrame) SourceLine() (string, error) {
65 | data, err := ioutil.ReadFile(frame.File)
66 |
67 | if err != nil {
68 | return "", With("Cannot read source line").WithErr(err)
69 | }
70 |
71 | lines := bytes.Split(data, []byte{'\n'})
72 | if frame.LineNumber <= 0 || frame.LineNumber >= len(lines) {
73 | return "???", nil
74 | }
75 | // -1 because line-numbers are 1 based, but our array is 0 based
76 | return string(bytes.Trim(lines[frame.LineNumber-1], " \t")), nil
77 | }
78 |
79 | func packageAndName(fn *runtime.Func) (string, string) {
80 | name := fn.Name()
81 | pkg := ""
82 |
83 | // The name includes the path name to the package, which is unnecessary
84 | // since the file name is already included. Plus, it has center dots.
85 | // That is, we see
86 | // runtime/debug.*T·ptrmethod
87 | // and want
88 | // *T.ptrmethod
89 | // Since the package path might contains dots (e.g. code.google.com/...),
90 | // we first remove the path prefix if there is one.
91 | if lastslash := strings.LastIndex(name, "/"); lastslash >= 0 {
92 | pkg += name[:lastslash] + "/"
93 | name = name[lastslash+1:]
94 | }
95 | if period := strings.Index(name, "."); period >= 0 {
96 | pkg += name[:period]
97 | name = name[period+1:]
98 | }
99 |
100 | name = strings.Replace(name, "·", ".", -1)
101 | return pkg, name
102 | }
103 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/event.go:
--------------------------------------------------------------------------------
1 | package erlog
2 |
3 | import (
4 | "github.com/n0rad/go-erlog/logs"
5 | "runtime"
6 | "strings"
7 | "time"
8 | )
9 |
10 | type LogEvent struct {
11 | logs.Entry
12 | Depth int
13 | Time time.Time
14 | File string
15 | Line int
16 | }
17 |
18 | func NewLogEvent(entry *logs.Entry) *LogEvent {
19 | var file string
20 | var line int
21 | var ok bool
22 | for i := 2; ; i++ {
23 | _, file, line, ok = runtime.Caller(i)
24 | if !ok {
25 | file = "???"
26 | line = 0
27 | }
28 | if !strings.Contains(file, "n0rad/go-erlog") {
29 | break
30 | }
31 | if strings.Contains(file, "n0rad/go-erlog/examples") { // TODO what to do with that ?
32 | break
33 | }
34 | }
35 |
36 | return &LogEvent{
37 | Entry: *entry,
38 | File: file,
39 | Line: line,
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/logs/default.go:
--------------------------------------------------------------------------------
1 | package logs
2 |
3 | func GetDefaultLog() Log { return factory.GetLog("") }
4 | func GetLog(name string) Log { return factory.GetLog(name) }
5 |
6 | func SetLevel(lvl Level) { GetDefaultLog().SetLevel(lvl) }
7 | func GetLevel() Level { return GetDefaultLog().GetLevel() }
8 |
9 | func Trace(msg ...string) { GetDefaultLog().Trace(msg...) }
10 | func Debug(msg ...string) { GetDefaultLog().Debug(msg...) }
11 | func Info(msg ...string) { GetDefaultLog().Info(msg...) }
12 | func Warn(msg ...string) { GetDefaultLog().Warn(msg...) }
13 | func Error(msg ...string) { GetDefaultLog().Error(msg...) }
14 | func Panic(msg ...string) { GetDefaultLog().Panic(msg...) }
15 | func Fatal(msg ...string) { GetDefaultLog().Fatal(msg...) }
16 |
17 | func Tracef(format string, msg ...interface{}) { GetDefaultLog().Tracef(format, msg...) }
18 | func Debugf(format string, msg ...interface{}) { GetDefaultLog().Debugf(format, msg...) }
19 | func Infof(format string, msg ...interface{}) { GetDefaultLog().Infof(format, msg...) }
20 | func Warnf(format string, msg ...interface{}) { GetDefaultLog().Warnf(format, msg...) }
21 | func Errorf(format string, msg ...interface{}) { GetDefaultLog().Errorf(format, msg...) }
22 | func Panicf(format string, msg ...interface{}) { GetDefaultLog().Panicf(format, msg...) }
23 | func Fatalf(format string, msg ...interface{}) { GetDefaultLog().Fatalf(format, msg...) }
24 |
25 | func LogEntry(entry *Entry) { GetDefaultLog().LogEntry(entry) }
26 |
27 | func IsLevelEnabled(lvl Level) bool { return GetDefaultLog().IsLevelEnabled(lvl) }
28 | func IsTraceEnabled() bool { return GetDefaultLog().IsTraceEnabled() }
29 | func IsDebugEnabled() bool { return GetDefaultLog().IsDebugEnabled() }
30 | func IsInfoEnabled() bool { return GetDefaultLog().IsInfoEnabled() }
31 | func IsWarnEnabled() bool { return GetDefaultLog().IsWarnEnabled() }
32 | func IsErrorEnabled() bool { return GetDefaultLog().IsErrorEnabled() }
33 | func IsPanicEnabled() bool { return GetDefaultLog().IsPanicEnabled() }
34 | func IsFatalEnabled() bool { return GetDefaultLog().IsFatalEnabled() }
35 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/logs/dummy.go:
--------------------------------------------------------------------------------
1 | package logs
2 |
3 | import (
4 | "fmt"
5 | "io"
6 | "os"
7 | "strings"
8 | )
9 |
10 | type DummyLog struct {
11 | Out io.Writer
12 | }
13 |
14 | func (d *DummyLog) GetLog(name string) Log { return d }
15 |
16 | func (d *DummyLog) Tracef(format string, msg ...interface{}) {
17 | d.log(TRACE, fmt.Sprintf(format, msg...))
18 | }
19 | func (d *DummyLog) Debugf(format string, msg ...interface{}) {
20 | d.log(DEBUG, fmt.Sprintf(format, msg...))
21 | }
22 | func (d *DummyLog) Infof(format string, msg ...interface{}) {
23 | d.log(INFO, fmt.Sprintf(format, msg...))
24 | }
25 | func (d *DummyLog) Warnf(format string, msg ...interface{}) {
26 | d.log(WARN, fmt.Sprintf(format, msg...))
27 | }
28 | func (d *DummyLog) Errorf(format string, msg ...interface{}) {
29 | d.log(ERROR, fmt.Sprintf(format, msg...))
30 | }
31 | func (d *DummyLog) Panicf(format string, msg ...interface{}) {
32 | d.log(PANIC, fmt.Sprintf(format, msg...))
33 | }
34 | func (d *DummyLog) Fatalf(format string, msg ...interface{}) {
35 | d.log(FATAL, fmt.Sprintf(format, msg...))
36 | }
37 |
38 | func (d *DummyLog) Trace(msg ...string) { d.log(TRACE, msg...) }
39 | func (d *DummyLog) Debug(msg ...string) { d.log(DEBUG, msg...) }
40 | func (d *DummyLog) Info(msg ...string) { d.log(INFO, msg...) }
41 | func (d *DummyLog) Warn(msg ...string) { d.log(WARN, msg...) }
42 | func (d *DummyLog) Error(msg ...string) { d.log(ERROR, msg...) }
43 | func (d *DummyLog) Panic(msg ...string) { d.log(PANIC, msg...); panic(msg) }
44 | func (d *DummyLog) Fatal(msg ...string) { d.log(FATAL, msg...); os.Exit(1) }
45 | func (d *DummyLog) log(level Level, msg ...string) {
46 | d.LogEntry(&Entry{Level: level, Message: strings.Join(msg, " ")})
47 | }
48 | func (d *DummyLog) LogEntry(entry *Entry) { fmt.Fprintf(d.Out, "%s: %s\n", entry.Level, entry.Message) }
49 | func (d *DummyLog) GetLevel() Level { return TRACE }
50 | func (d *DummyLog) SetLevel(lvl Level) { d.Error("Dummy log cannot set level") }
51 | func (d *DummyLog) IsLevelEnabled(lvl Level) bool { return true }
52 | func (d *DummyLog) IsTraceEnabled() bool { return true }
53 | func (d *DummyLog) IsDebugEnabled() bool { return true }
54 | func (d *DummyLog) IsInfoEnabled() bool { return true }
55 | func (d *DummyLog) IsWarnEnabled() bool { return true }
56 | func (d *DummyLog) IsErrorEnabled() bool { return true }
57 | func (d *DummyLog) IsPanicEnabled() bool { return true }
58 | func (d *DummyLog) IsFatalEnabled() bool { return true }
59 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/logs/entry.go:
--------------------------------------------------------------------------------
1 | package logs
2 |
3 | import (
4 | "github.com/n0rad/go-erlog/data"
5 | )
6 |
7 | type Entry struct {
8 | Logger Log
9 | Level Level
10 | Fields data.Fields
11 | Message string
12 | Err error
13 | }
14 |
15 | func WithError(err error) *Entry {
16 | return &Entry{
17 | Logger: GetDefaultLog(),
18 | Err: err,
19 | }
20 | }
21 |
22 | func WithField(name string, value interface{}) *Entry {
23 | return &Entry{
24 | Logger: GetDefaultLog(),
25 | Fields: data.WithField(name, value),
26 | }
27 | }
28 |
29 | func WithFields(fields data.Fields) *Entry {
30 | return &Entry{
31 | Logger: GetDefaultLog(),
32 | Fields: fields,
33 | }
34 | }
35 |
36 | func WithEF(err error, fields data.Fields) *Entry {
37 | return &Entry{
38 | Logger: GetDefaultLog(),
39 | Err: err,
40 | Fields: fields,
41 | }
42 | }
43 |
44 | func WithF(fields data.Fields) *Entry {
45 | return WithFields(fields)
46 | }
47 |
48 | func WithE(err error) *Entry {
49 | return WithError(err)
50 | }
51 |
52 |
53 | ///////////////////////////////////
54 |
55 | func (e *Entry) WithFields(data data.Fields) *Entry {
56 | e.Fields = data
57 | return e
58 | }
59 |
60 | func (e *Entry) WithField(name string, value interface{}) *Entry {
61 | if e.Fields == nil {
62 | e.Fields = data.WithField(name, value)
63 | } else {
64 | e.Fields = e.Fields.WithField(name, value)
65 | }
66 | return e
67 | }
68 |
69 | func (e *Entry) WithLog(logger Log) *Entry {
70 | e.Logger = logger
71 | return e
72 | }
73 |
74 | func (e *Entry) Trace(msg string) {
75 | e.Level = TRACE
76 | e.Message = msg
77 | e.Logger.LogEntry(e)
78 | }
79 |
80 | func (e *Entry) Debug(msg string) {
81 | e.Level = DEBUG
82 | e.Message = msg
83 | e.Logger.LogEntry(e)
84 | }
85 |
86 | func (e *Entry) Info(msg string) {
87 | e.Level = INFO
88 | e.Message = msg
89 | e.Logger.LogEntry(e)
90 | }
91 |
92 | func (e *Entry) Warn(msg string) {
93 | e.Level = WARN
94 | e.Message = msg
95 | e.Logger.LogEntry(e)
96 | }
97 |
98 | func (e *Entry) Error(msg string) {
99 | e.Level = ERROR
100 | e.Message = msg
101 | e.Logger.LogEntry(e)
102 | }
103 |
104 | func (e *Entry) Panic(msg string) {
105 | e.Level = PANIC
106 | e.Message = msg
107 | e.Logger.LogEntry(e)
108 | }
109 |
110 | func (e *Entry) Fatal(msg string) {
111 | e.Level = FATAL
112 | e.Message = msg
113 | e.Logger.LogEntry(e)
114 | }
115 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/logs/levels.go:
--------------------------------------------------------------------------------
1 | package logs
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 | "encoding/json"
7 | )
8 |
9 | type Level uint8
10 |
11 | const (
12 | // the program cannot continue. will log and exit(1)
13 | FATAL Level = iota
14 | // the routine cannot continue. will log and call go panic function
15 | PANIC
16 | // program continue but caller have received error or data lost or similar
17 | ERROR
18 | // recovered problem or non critical
19 | WARN
20 | // general info
21 | INFO
22 | // tell what is going on step by step
23 | DEBUG
24 | // log data content
25 | TRACE
26 | )
27 |
28 | func (r *Level) UnmarshalJSON(b []byte) error {
29 | var str string
30 | if err := json.Unmarshal(b, &str); err != nil {
31 | return err
32 | }
33 |
34 | lvl, err := ParseLevel(str)
35 | if err != nil {
36 | return err
37 | }
38 | *r = lvl
39 | return nil
40 | }
41 |
42 | func (level Level) String() string {
43 | switch level {
44 | case TRACE:
45 | return "TRACE"
46 | case DEBUG:
47 | return "DEBUG"
48 | case INFO:
49 | return "INFO"
50 | case WARN:
51 | return "WARN"
52 | case ERROR:
53 | return "ERROR"
54 | case FATAL:
55 | return "FATAL"
56 | case PANIC:
57 | return "PANIC"
58 | }
59 | return "UNKNOWN"
60 | }
61 |
62 | func ParseLevel(lvl string) (Level, error) {
63 | lvl2 := strings.ToUpper(lvl)
64 | switch lvl2 {
65 | case "PANIC":
66 | return PANIC, nil
67 | case "FATAL":
68 | return FATAL, nil
69 | case "ERROR":
70 | return ERROR, nil
71 | case "WARN", "WARNING":
72 | return WARN, nil
73 | case "INFO":
74 | return INFO, nil
75 | case "DEBUG":
76 | return DEBUG, nil
77 | case "TRACE":
78 | return TRACE, nil
79 | }
80 | var l Level
81 | return l, fmt.Errorf("Not a valid log level: %s", lvl) // not using errs to prevent cycle dep
82 | }
83 |
84 | func (l Level) IsEnableFor(level Level) bool {
85 | return level >= l
86 | }
87 |
--------------------------------------------------------------------------------
/vendor/github.com/n0rad/go-erlog/logs/logger.go:
--------------------------------------------------------------------------------
1 | package logs
2 |
3 | import (
4 | "fmt"
5 | "os"
6 | "reflect"
7 | "runtime"
8 | "sync"
9 | )
10 |
11 | type LogFactory interface {
12 | GetLog(name string) Log
13 | }
14 |
15 | type Log interface {
16 | Trace(msg ...string)
17 | Debug(msg ...string)
18 | Info(msg ...string)
19 | Warn(msg ...string)
20 | Error(msg ...string)
21 | Panic(msg ...string)
22 | Fatal(msg ...string)
23 |
24 | Tracef(format string, msg ...interface{})
25 | Debugf(format string, msg ...interface{})
26 | Infof(format string, msg ...interface{})
27 | Warnf(format string, msg ...interface{})
28 | Errorf(format string, msg ...interface{})
29 | Panicf(format string, msg ...interface{})
30 | Fatalf(format string, msg ...interface{})
31 |
32 | LogEntry(entry *Entry)
33 |
34 | GetLevel() Level
35 | SetLevel(lvl Level)
36 |
37 | IsLevelEnabled(lvl Level) bool
38 | IsTraceEnabled() bool
39 | IsDebugEnabled() bool
40 | IsInfoEnabled() bool
41 | IsWarnEnabled() bool
42 | IsErrorEnabled() bool
43 | IsPanicEnabled() bool
44 | IsFatalEnabled() bool
45 | }
46 |
47 | var factory LogFactory = &DummyLog{Out: os.Stderr}
48 | var mu sync.Mutex
49 |
50 | func RegisterLoggerFactory(f LogFactory) {
51 | mu.Lock()
52 | if f == factory {
53 | return
54 | }
55 |
56 | if _, ok := factory.(*DummyLog); !ok {
57 | _, file, line, _ := runtime.Caller(1)
58 | fmt.Fprintf(os.Stderr, "Re-Registering the logger factory : %s:%d. There is already one registered : %s\n", file, line, reflect.TypeOf(factory))
59 | }
60 | factory = f
61 | mu.Unlock()
62 | }
63 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/cobra.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2013 Steve Francia .
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | // http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // Unless required by applicable law or agreed to in writing, software
9 | // distributed under the License is distributed on an "AS IS" BASIS,
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | // See the License for the specific language governing permissions and
12 | // limitations under the License.
13 |
14 | // Commands similar to git, go tools and other modern CLI tools
15 | // inspired by go, go-Commander, gh and subcommand
16 |
17 | package cobra
18 |
19 | import (
20 | "fmt"
21 | "io"
22 | "reflect"
23 | "strconv"
24 | "strings"
25 | "text/template"
26 | )
27 |
28 | var initializers []func()
29 |
30 | // automatic prefix matching can be a dangerous thing to automatically enable in CLI tools.
31 | // Set this to true to enable it
32 | var EnablePrefixMatching bool = false
33 |
34 | // enables an information splash screen on Windows if the CLI is started from explorer.exe.
35 | var EnableWindowsMouseTrap bool = true
36 |
37 | var MousetrapHelpText string = `This is a command line tool
38 |
39 | You need to open cmd.exe and run it from there.
40 | `
41 |
42 | //OnInitialize takes a series of func() arguments and appends them to a slice of func().
43 | func OnInitialize(y ...func()) {
44 | for _, x := range y {
45 | initializers = append(initializers, x)
46 | }
47 | }
48 |
49 | //Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans,
50 | //Maps and Slices, Gt will compare their lengths. Ints are compared directly while strings are first parsed as
51 | //ints and then compared.
52 | func Gt(a interface{}, b interface{}) bool {
53 | var left, right int64
54 | av := reflect.ValueOf(a)
55 |
56 | switch av.Kind() {
57 | case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:
58 | left = int64(av.Len())
59 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
60 | left = av.Int()
61 | case reflect.String:
62 | left, _ = strconv.ParseInt(av.String(), 10, 64)
63 | }
64 |
65 | bv := reflect.ValueOf(b)
66 |
67 | switch bv.Kind() {
68 | case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:
69 | right = int64(bv.Len())
70 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
71 | right = bv.Int()
72 | case reflect.String:
73 | right, _ = strconv.ParseInt(bv.String(), 10, 64)
74 | }
75 |
76 | return left > right
77 | }
78 |
79 | //Eq takes two types and checks whether they are equal. Supported types are int and string. Unsupported types will panic.
80 | func Eq(a interface{}, b interface{}) bool {
81 | av := reflect.ValueOf(a)
82 | bv := reflect.ValueOf(b)
83 |
84 | switch av.Kind() {
85 | case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:
86 | panic("Eq called on unsupported type")
87 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
88 | return av.Int() == bv.Int()
89 | case reflect.String:
90 | return av.String() == bv.String()
91 | }
92 | return false
93 | }
94 |
95 | //rpad adds padding to the right of a string
96 | func rpad(s string, padding int) string {
97 | template := fmt.Sprintf("%%-%ds", padding)
98 | return fmt.Sprintf(template, s)
99 | }
100 |
101 | // tmpl executes the given template text on data, writing the result to w.
102 | func tmpl(w io.Writer, text string, data interface{}) error {
103 | t := template.New("top")
104 | t.Funcs(template.FuncMap{
105 | "trim": strings.TrimSpace,
106 | "rpad": rpad,
107 | "gt": Gt,
108 | "eq": Eq,
109 | })
110 | template.Must(t.Parse(text))
111 | return t.Execute(w, data)
112 | }
113 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Alex Ogier. All rights reserved.
2 | Copyright (c) 2012 The Go Authors. All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above
11 | copyright notice, this list of conditions and the following disclaimer
12 | in the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Google Inc. nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/bool.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // optional interface to indicate boolean flags that can be
9 | // supplied without "=value" text
10 | type boolFlag interface {
11 | Value
12 | IsBoolFlag() bool
13 | }
14 |
15 | // -- bool Value
16 | type boolValue bool
17 |
18 | func newBoolValue(val bool, p *bool) *boolValue {
19 | *p = val
20 | return (*boolValue)(p)
21 | }
22 |
23 | func (b *boolValue) Set(s string) error {
24 | v, err := strconv.ParseBool(s)
25 | *b = boolValue(v)
26 | return err
27 | }
28 |
29 | func (b *boolValue) Type() string {
30 | return "bool"
31 | }
32 |
33 | func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }
34 |
35 | func (b *boolValue) IsBoolFlag() bool { return true }
36 |
37 | func boolConv(sval string) (interface{}, error) {
38 | return strconv.ParseBool(sval)
39 | }
40 |
41 | // GetBool return the bool value of a flag with the given name
42 | func (f *FlagSet) GetBool(name string) (bool, error) {
43 | val, err := f.getFlagType(name, "bool", boolConv)
44 | if err != nil {
45 | return false, err
46 | }
47 | return val.(bool), nil
48 | }
49 |
50 | // BoolVar defines a bool flag with specified name, default value, and usage string.
51 | // The argument p points to a bool variable in which to store the value of the flag.
52 | func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) {
53 | f.BoolVarP(p, name, "", value, usage)
54 | }
55 |
56 | // Like BoolVar, but accepts a shorthand letter that can be used after a single dash.
57 | func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
58 | flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage)
59 | flag.NoOptDefVal = "true"
60 | }
61 |
62 | // BoolVar defines a bool flag with specified name, default value, and usage string.
63 | // The argument p points to a bool variable in which to store the value of the flag.
64 | func BoolVar(p *bool, name string, value bool, usage string) {
65 | BoolVarP(p, name, "", value, usage)
66 | }
67 |
68 | // Like BoolVar, but accepts a shorthand letter that can be used after a single dash.
69 | func BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
70 | flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage)
71 | flag.NoOptDefVal = "true"
72 | }
73 |
74 | // Bool defines a bool flag with specified name, default value, and usage string.
75 | // The return value is the address of a bool variable that stores the value of the flag.
76 | func (f *FlagSet) Bool(name string, value bool, usage string) *bool {
77 | return f.BoolP(name, "", value, usage)
78 | }
79 |
80 | // Like Bool, but accepts a shorthand letter that can be used after a single dash.
81 | func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool {
82 | p := new(bool)
83 | f.BoolVarP(p, name, shorthand, value, usage)
84 | return p
85 | }
86 |
87 | // Bool defines a bool flag with specified name, default value, and usage string.
88 | // The return value is the address of a bool variable that stores the value of the flag.
89 | func Bool(name string, value bool, usage string) *bool {
90 | return BoolP(name, "", value, usage)
91 | }
92 |
93 | // Like Bool, but accepts a shorthand letter that can be used after a single dash.
94 | func BoolP(name, shorthand string, value bool, usage string) *bool {
95 | b := CommandLine.BoolP(name, shorthand, value, usage)
96 | return b
97 | }
98 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/duration.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "time"
5 | )
6 |
7 | // -- time.Duration Value
8 | type durationValue time.Duration
9 |
10 | func newDurationValue(val time.Duration, p *time.Duration) *durationValue {
11 | *p = val
12 | return (*durationValue)(p)
13 | }
14 |
15 | func (d *durationValue) Set(s string) error {
16 | v, err := time.ParseDuration(s)
17 | *d = durationValue(v)
18 | return err
19 | }
20 |
21 | func (d *durationValue) Type() string {
22 | return "duration"
23 | }
24 |
25 | func (d *durationValue) String() string { return (*time.Duration)(d).String() }
26 |
27 | func durationConv(sval string) (interface{}, error) {
28 | return time.ParseDuration(sval)
29 | }
30 |
31 | // GetDuration return the duration value of a flag with the given name
32 | func (f *FlagSet) GetDuration(name string) (time.Duration, error) {
33 | val, err := f.getFlagType(name, "duration", durationConv)
34 | if err != nil {
35 | return 0, err
36 | }
37 | return val.(time.Duration), nil
38 | }
39 |
40 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string.
41 | // The argument p points to a time.Duration variable in which to store the value of the flag.
42 | func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
43 | f.VarP(newDurationValue(value, p), name, "", usage)
44 | }
45 |
46 | // Like DurationVar, but accepts a shorthand letter that can be used after a single dash.
47 | func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
48 | f.VarP(newDurationValue(value, p), name, shorthand, usage)
49 | }
50 |
51 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string.
52 | // The argument p points to a time.Duration variable in which to store the value of the flag.
53 | func DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
54 | CommandLine.VarP(newDurationValue(value, p), name, "", usage)
55 | }
56 |
57 | // Like DurationVar, but accepts a shorthand letter that can be used after a single dash.
58 | func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
59 | CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage)
60 | }
61 |
62 | // Duration defines a time.Duration flag with specified name, default value, and usage string.
63 | // The return value is the address of a time.Duration variable that stores the value of the flag.
64 | func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration {
65 | p := new(time.Duration)
66 | f.DurationVarP(p, name, "", value, usage)
67 | return p
68 | }
69 |
70 | // Like Duration, but accepts a shorthand letter that can be used after a single dash.
71 | func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration {
72 | p := new(time.Duration)
73 | f.DurationVarP(p, name, shorthand, value, usage)
74 | return p
75 | }
76 |
77 | // Duration defines a time.Duration flag with specified name, default value, and usage string.
78 | // The return value is the address of a time.Duration variable that stores the value of the flag.
79 | func Duration(name string, value time.Duration, usage string) *time.Duration {
80 | return CommandLine.DurationP(name, "", value, usage)
81 | }
82 |
83 | // Like Duration, but accepts a shorthand letter that can be used after a single dash.
84 | func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration {
85 | return CommandLine.DurationP(name, shorthand, value, usage)
86 | }
87 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/float32.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- float32 Value
9 | type float32Value float32
10 |
11 | func newFloat32Value(val float32, p *float32) *float32Value {
12 | *p = val
13 | return (*float32Value)(p)
14 | }
15 |
16 | func (f *float32Value) Set(s string) error {
17 | v, err := strconv.ParseFloat(s, 32)
18 | *f = float32Value(v)
19 | return err
20 | }
21 |
22 | func (f *float32Value) Type() string {
23 | return "float32"
24 | }
25 |
26 | func (f *float32Value) String() string { return fmt.Sprintf("%v", *f) }
27 |
28 | func float32Conv(sval string) (interface{}, error) {
29 | v, err := strconv.ParseFloat(sval, 32)
30 | if err != nil {
31 | return 0, err
32 | }
33 | return float32(v), nil
34 | }
35 |
36 | // GetFloat32 return the float32 value of a flag with the given name
37 | func (f *FlagSet) GetFloat32(name string) (float32, error) {
38 | val, err := f.getFlagType(name, "float32", float32Conv)
39 | if err != nil {
40 | return 0, err
41 | }
42 | return val.(float32), nil
43 | }
44 |
45 | // Float32Var defines a float32 flag with specified name, default value, and usage string.
46 | // The argument p points to a float32 variable in which to store the value of the flag.
47 | func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) {
48 | f.VarP(newFloat32Value(value, p), name, "", usage)
49 | }
50 |
51 | // Like Float32Var, but accepts a shorthand letter that can be used after a single dash.
52 | func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
53 | f.VarP(newFloat32Value(value, p), name, shorthand, usage)
54 | }
55 |
56 | // Float32Var defines a float32 flag with specified name, default value, and usage string.
57 | // The argument p points to a float32 variable in which to store the value of the flag.
58 | func Float32Var(p *float32, name string, value float32, usage string) {
59 | CommandLine.VarP(newFloat32Value(value, p), name, "", usage)
60 | }
61 |
62 | // Like Float32Var, but accepts a shorthand letter that can be used after a single dash.
63 | func Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
64 | CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage)
65 | }
66 |
67 | // Float32 defines a float32 flag with specified name, default value, and usage string.
68 | // The return value is the address of a float32 variable that stores the value of the flag.
69 | func (f *FlagSet) Float32(name string, value float32, usage string) *float32 {
70 | p := new(float32)
71 | f.Float32VarP(p, name, "", value, usage)
72 | return p
73 | }
74 |
75 | // Like Float32, but accepts a shorthand letter that can be used after a single dash.
76 | func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 {
77 | p := new(float32)
78 | f.Float32VarP(p, name, shorthand, value, usage)
79 | return p
80 | }
81 |
82 | // Float32 defines a float32 flag with specified name, default value, and usage string.
83 | // The return value is the address of a float32 variable that stores the value of the flag.
84 | func Float32(name string, value float32, usage string) *float32 {
85 | return CommandLine.Float32P(name, "", value, usage)
86 | }
87 |
88 | // Like Float32, but accepts a shorthand letter that can be used after a single dash.
89 | func Float32P(name, shorthand string, value float32, usage string) *float32 {
90 | return CommandLine.Float32P(name, shorthand, value, usage)
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/float64.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- float64 Value
9 | type float64Value float64
10 |
11 | func newFloat64Value(val float64, p *float64) *float64Value {
12 | *p = val
13 | return (*float64Value)(p)
14 | }
15 |
16 | func (f *float64Value) Set(s string) error {
17 | v, err := strconv.ParseFloat(s, 64)
18 | *f = float64Value(v)
19 | return err
20 | }
21 |
22 | func (f *float64Value) Type() string {
23 | return "float64"
24 | }
25 |
26 | func (f *float64Value) String() string { return fmt.Sprintf("%v", *f) }
27 |
28 | func float64Conv(sval string) (interface{}, error) {
29 | return strconv.ParseFloat(sval, 64)
30 | }
31 |
32 | // GetFloat64 return the float64 value of a flag with the given name
33 | func (f *FlagSet) GetFloat64(name string) (float64, error) {
34 | val, err := f.getFlagType(name, "float64", float64Conv)
35 | if err != nil {
36 | return 0, err
37 | }
38 | return val.(float64), nil
39 | }
40 |
41 | // Float64Var defines a float64 flag with specified name, default value, and usage string.
42 | // The argument p points to a float64 variable in which to store the value of the flag.
43 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) {
44 | f.VarP(newFloat64Value(value, p), name, "", usage)
45 | }
46 |
47 | // Like Float64Var, but accepts a shorthand letter that can be used after a single dash.
48 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
49 | f.VarP(newFloat64Value(value, p), name, shorthand, usage)
50 | }
51 |
52 | // Float64Var defines a float64 flag with specified name, default value, and usage string.
53 | // The argument p points to a float64 variable in which to store the value of the flag.
54 | func Float64Var(p *float64, name string, value float64, usage string) {
55 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage)
56 | }
57 |
58 | // Like Float64Var, but accepts a shorthand letter that can be used after a single dash.
59 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
60 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage)
61 | }
62 |
63 | // Float64 defines a float64 flag with specified name, default value, and usage string.
64 | // The return value is the address of a float64 variable that stores the value of the flag.
65 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 {
66 | p := new(float64)
67 | f.Float64VarP(p, name, "", value, usage)
68 | return p
69 | }
70 |
71 | // Like Float64, but accepts a shorthand letter that can be used after a single dash.
72 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 {
73 | p := new(float64)
74 | f.Float64VarP(p, name, shorthand, value, usage)
75 | return p
76 | }
77 |
78 | // Float64 defines a float64 flag with specified name, default value, and usage string.
79 | // The return value is the address of a float64 variable that stores the value of the flag.
80 | func Float64(name string, value float64, usage string) *float64 {
81 | return CommandLine.Float64P(name, "", value, usage)
82 | }
83 |
84 | // Like Float64, but accepts a shorthand letter that can be used after a single dash.
85 | func Float64P(name, shorthand string, value float64, usage string) *float64 {
86 | return CommandLine.Float64P(name, shorthand, value, usage)
87 | }
88 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/int.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- int Value
9 | type intValue int
10 |
11 | func newIntValue(val int, p *int) *intValue {
12 | *p = val
13 | return (*intValue)(p)
14 | }
15 |
16 | func (i *intValue) Set(s string) error {
17 | v, err := strconv.ParseInt(s, 0, 64)
18 | *i = intValue(v)
19 | return err
20 | }
21 |
22 | func (i *intValue) Type() string {
23 | return "int"
24 | }
25 |
26 | func (i *intValue) String() string { return fmt.Sprintf("%v", *i) }
27 |
28 | func intConv(sval string) (interface{}, error) {
29 | return strconv.Atoi(sval)
30 | }
31 |
32 | // GetInt return the int value of a flag with the given name
33 | func (f *FlagSet) GetInt(name string) (int, error) {
34 | val, err := f.getFlagType(name, "int", intConv)
35 | if err != nil {
36 | return 0, err
37 | }
38 | return val.(int), nil
39 | }
40 |
41 | // IntVar defines an int flag with specified name, default value, and usage string.
42 | // The argument p points to an int variable in which to store the value of the flag.
43 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) {
44 | f.VarP(newIntValue(value, p), name, "", usage)
45 | }
46 |
47 | // Like IntVar, but accepts a shorthand letter that can be used after a single dash.
48 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) {
49 | f.VarP(newIntValue(value, p), name, shorthand, usage)
50 | }
51 |
52 | // IntVar defines an int flag with specified name, default value, and usage string.
53 | // The argument p points to an int variable in which to store the value of the flag.
54 | func IntVar(p *int, name string, value int, usage string) {
55 | CommandLine.VarP(newIntValue(value, p), name, "", usage)
56 | }
57 |
58 | // Like IntVar, but accepts a shorthand letter that can be used after a single dash.
59 | func IntVarP(p *int, name, shorthand string, value int, usage string) {
60 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage)
61 | }
62 |
63 | // Int defines an int flag with specified name, default value, and usage string.
64 | // The return value is the address of an int variable that stores the value of the flag.
65 | func (f *FlagSet) Int(name string, value int, usage string) *int {
66 | p := new(int)
67 | f.IntVarP(p, name, "", value, usage)
68 | return p
69 | }
70 |
71 | // Like Int, but accepts a shorthand letter that can be used after a single dash.
72 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int {
73 | p := new(int)
74 | f.IntVarP(p, name, shorthand, value, usage)
75 | return p
76 | }
77 |
78 | // Int defines an int flag with specified name, default value, and usage string.
79 | // The return value is the address of an int variable that stores the value of the flag.
80 | func Int(name string, value int, usage string) *int {
81 | return CommandLine.IntP(name, "", value, usage)
82 | }
83 |
84 | // Like Int, but accepts a shorthand letter that can be used after a single dash.
85 | func IntP(name, shorthand string, value int, usage string) *int {
86 | return CommandLine.IntP(name, shorthand, value, usage)
87 | }
88 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/int32.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- int32 Value
9 | type int32Value int32
10 |
11 | func newInt32Value(val int32, p *int32) *int32Value {
12 | *p = val
13 | return (*int32Value)(p)
14 | }
15 |
16 | func (i *int32Value) Set(s string) error {
17 | v, err := strconv.ParseInt(s, 0, 32)
18 | *i = int32Value(v)
19 | return err
20 | }
21 |
22 | func (i *int32Value) Type() string {
23 | return "int32"
24 | }
25 |
26 | func (i *int32Value) String() string { return fmt.Sprintf("%v", *i) }
27 |
28 | func int32Conv(sval string) (interface{}, error) {
29 | v, err := strconv.ParseInt(sval, 0, 32)
30 | if err != nil {
31 | return 0, err
32 | }
33 | return int32(v), nil
34 | }
35 |
36 | // GetInt32 return the int32 value of a flag with the given name
37 | func (f *FlagSet) GetInt32(name string) (int32, error) {
38 | val, err := f.getFlagType(name, "int32", int32Conv)
39 | if err != nil {
40 | return 0, err
41 | }
42 | return val.(int32), nil
43 | }
44 |
45 | // Int32Var defines an int32 flag with specified name, default value, and usage string.
46 | // The argument p points to an int32 variable in which to store the value of the flag.
47 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) {
48 | f.VarP(newInt32Value(value, p), name, "", usage)
49 | }
50 |
51 | // Like Int32Var, but accepts a shorthand letter that can be used after a single dash.
52 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) {
53 | f.VarP(newInt32Value(value, p), name, shorthand, usage)
54 | }
55 |
56 | // Int32Var defines an int32 flag with specified name, default value, and usage string.
57 | // The argument p points to an int32 variable in which to store the value of the flag.
58 | func Int32Var(p *int32, name string, value int32, usage string) {
59 | CommandLine.VarP(newInt32Value(value, p), name, "", usage)
60 | }
61 |
62 | // Like Int32Var, but accepts a shorthand letter that can be used after a single dash.
63 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) {
64 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage)
65 | }
66 |
67 | // Int32 defines an int32 flag with specified name, default value, and usage string.
68 | // The return value is the address of an int32 variable that stores the value of the flag.
69 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 {
70 | p := new(int32)
71 | f.Int32VarP(p, name, "", value, usage)
72 | return p
73 | }
74 |
75 | // Like Int32, but accepts a shorthand letter that can be used after a single dash.
76 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 {
77 | p := new(int32)
78 | f.Int32VarP(p, name, shorthand, value, usage)
79 | return p
80 | }
81 |
82 | // Int32 defines an int32 flag with specified name, default value, and usage string.
83 | // The return value is the address of an int32 variable that stores the value of the flag.
84 | func Int32(name string, value int32, usage string) *int32 {
85 | return CommandLine.Int32P(name, "", value, usage)
86 | }
87 |
88 | // Like Int32, but accepts a shorthand letter that can be used after a single dash.
89 | func Int32P(name, shorthand string, value int32, usage string) *int32 {
90 | return CommandLine.Int32P(name, shorthand, value, usage)
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/int64.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- int64 Value
9 | type int64Value int64
10 |
11 | func newInt64Value(val int64, p *int64) *int64Value {
12 | *p = val
13 | return (*int64Value)(p)
14 | }
15 |
16 | func (i *int64Value) Set(s string) error {
17 | v, err := strconv.ParseInt(s, 0, 64)
18 | *i = int64Value(v)
19 | return err
20 | }
21 |
22 | func (i *int64Value) Type() string {
23 | return "int64"
24 | }
25 |
26 | func (i *int64Value) String() string { return fmt.Sprintf("%v", *i) }
27 |
28 | func int64Conv(sval string) (interface{}, error) {
29 | return strconv.ParseInt(sval, 0, 64)
30 | }
31 |
32 | // GetInt64 return the int64 value of a flag with the given name
33 | func (f *FlagSet) GetInt64(name string) (int64, error) {
34 | val, err := f.getFlagType(name, "int64", int64Conv)
35 | if err != nil {
36 | return 0, err
37 | }
38 | return val.(int64), nil
39 | }
40 |
41 | // Int64Var defines an int64 flag with specified name, default value, and usage string.
42 | // The argument p points to an int64 variable in which to store the value of the flag.
43 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) {
44 | f.VarP(newInt64Value(value, p), name, "", usage)
45 | }
46 |
47 | // Like Int64Var, but accepts a shorthand letter that can be used after a single dash.
48 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) {
49 | f.VarP(newInt64Value(value, p), name, shorthand, usage)
50 | }
51 |
52 | // Int64Var defines an int64 flag with specified name, default value, and usage string.
53 | // The argument p points to an int64 variable in which to store the value of the flag.
54 | func Int64Var(p *int64, name string, value int64, usage string) {
55 | CommandLine.VarP(newInt64Value(value, p), name, "", usage)
56 | }
57 |
58 | // Like Int64Var, but accepts a shorthand letter that can be used after a single dash.
59 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) {
60 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage)
61 | }
62 |
63 | // Int64 defines an int64 flag with specified name, default value, and usage string.
64 | // The return value is the address of an int64 variable that stores the value of the flag.
65 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 {
66 | p := new(int64)
67 | f.Int64VarP(p, name, "", value, usage)
68 | return p
69 | }
70 |
71 | // Like Int64, but accepts a shorthand letter that can be used after a single dash.
72 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 {
73 | p := new(int64)
74 | f.Int64VarP(p, name, shorthand, value, usage)
75 | return p
76 | }
77 |
78 | // Int64 defines an int64 flag with specified name, default value, and usage string.
79 | // The return value is the address of an int64 variable that stores the value of the flag.
80 | func Int64(name string, value int64, usage string) *int64 {
81 | return CommandLine.Int64P(name, "", value, usage)
82 | }
83 |
84 | // Like Int64, but accepts a shorthand letter that can be used after a single dash.
85 | func Int64P(name, shorthand string, value int64, usage string) *int64 {
86 | return CommandLine.Int64P(name, shorthand, value, usage)
87 | }
88 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/int8.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- int8 Value
9 | type int8Value int8
10 |
11 | func newInt8Value(val int8, p *int8) *int8Value {
12 | *p = val
13 | return (*int8Value)(p)
14 | }
15 |
16 | func (i *int8Value) Set(s string) error {
17 | v, err := strconv.ParseInt(s, 0, 8)
18 | *i = int8Value(v)
19 | return err
20 | }
21 |
22 | func (i *int8Value) Type() string {
23 | return "int8"
24 | }
25 |
26 | func (i *int8Value) String() string { return fmt.Sprintf("%v", *i) }
27 |
28 | func int8Conv(sval string) (interface{}, error) {
29 | v, err := strconv.ParseInt(sval, 0, 8)
30 | if err != nil {
31 | return 0, err
32 | }
33 | return int8(v), nil
34 | }
35 |
36 | // GetInt8 return the int8 value of a flag with the given name
37 | func (f *FlagSet) GetInt8(name string) (int8, error) {
38 | val, err := f.getFlagType(name, "int8", int8Conv)
39 | if err != nil {
40 | return 0, err
41 | }
42 | return val.(int8), nil
43 | }
44 |
45 | // Int8Var defines an int8 flag with specified name, default value, and usage string.
46 | // The argument p points to an int8 variable in which to store the value of the flag.
47 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) {
48 | f.VarP(newInt8Value(value, p), name, "", usage)
49 | }
50 |
51 | // Like Int8Var, but accepts a shorthand letter that can be used after a single dash.
52 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
53 | f.VarP(newInt8Value(value, p), name, shorthand, usage)
54 | }
55 |
56 | // Int8Var defines an int8 flag with specified name, default value, and usage string.
57 | // The argument p points to an int8 variable in which to store the value of the flag.
58 | func Int8Var(p *int8, name string, value int8, usage string) {
59 | CommandLine.VarP(newInt8Value(value, p), name, "", usage)
60 | }
61 |
62 | // Like Int8Var, but accepts a shorthand letter that can be used after a single dash.
63 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
64 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage)
65 | }
66 |
67 | // Int8 defines an int8 flag with specified name, default value, and usage string.
68 | // The return value is the address of an int8 variable that stores the value of the flag.
69 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 {
70 | p := new(int8)
71 | f.Int8VarP(p, name, "", value, usage)
72 | return p
73 | }
74 |
75 | // Like Int8, but accepts a shorthand letter that can be used after a single dash.
76 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 {
77 | p := new(int8)
78 | f.Int8VarP(p, name, shorthand, value, usage)
79 | return p
80 | }
81 |
82 | // Int8 defines an int8 flag with specified name, default value, and usage string.
83 | // The return value is the address of an int8 variable that stores the value of the flag.
84 | func Int8(name string, value int8, usage string) *int8 {
85 | return CommandLine.Int8P(name, "", value, usage)
86 | }
87 |
88 | // Like Int8, but accepts a shorthand letter that can be used after a single dash.
89 | func Int8P(name, shorthand string, value int8, usage string) *int8 {
90 | return CommandLine.Int8P(name, shorthand, value, usage)
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/int_slice.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | "strings"
7 | )
8 |
9 | // -- intSlice Value
10 | type intSliceValue []int
11 |
12 | func newIntSliceValue(val []int, p *[]int) *intSliceValue {
13 | *p = val
14 | return (*intSliceValue)(p)
15 | }
16 |
17 | func (s *intSliceValue) Set(val string) error {
18 | ss := strings.Split(val, ",")
19 | out := make([]int, len(ss))
20 | for i, d := range ss {
21 | var err error
22 | out[i], err = strconv.Atoi(d)
23 | if err != nil {
24 | return err
25 | }
26 |
27 | }
28 | *s = intSliceValue(out)
29 | return nil
30 | }
31 |
32 | func (s *intSliceValue) Type() string {
33 | return "intSlice"
34 | }
35 |
36 | func (s *intSliceValue) String() string {
37 | out := make([]string, len(*s))
38 | for i, d := range *s {
39 | out[i] = fmt.Sprintf("%d", d)
40 | }
41 | return strings.Join(out, ",")
42 | }
43 |
44 | func intSliceConv(val string) (interface{}, error) {
45 | ss := strings.Split(val, ",")
46 | out := make([]int, len(ss))
47 | for i, d := range ss {
48 | var err error
49 | out[i], err = strconv.Atoi(d)
50 | if err != nil {
51 | return nil, err
52 | }
53 |
54 | }
55 | return out, nil
56 | }
57 |
58 | // GetIntSlice return the []int value of a flag with the given name
59 | func (f *FlagSet) GetIntSlice(name string) ([]int, error) {
60 | val, err := f.getFlagType(name, "intSlice", intSliceConv)
61 | if err != nil {
62 | return []int{}, err
63 | }
64 | return val.([]int), nil
65 | }
66 |
67 | // IntSliceVar defines a intSlice flag with specified name, default value, and usage string.
68 | // The argument p points to a []int variable in which to store the value of the flag.
69 | func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string) {
70 | f.VarP(newIntSliceValue(value, p), name, "", usage)
71 | }
72 |
73 | // Like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
74 | func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) {
75 | f.VarP(newIntSliceValue(value, p), name, shorthand, usage)
76 | }
77 |
78 | // IntSliceVar defines a int[] flag with specified name, default value, and usage string.
79 | // The argument p points to a int[] variable in which to store the value of the flag.
80 | func IntSliceVar(p *[]int, name string, value []int, usage string) {
81 | CommandLine.VarP(newIntSliceValue(value, p), name, "", usage)
82 | }
83 |
84 | // Like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
85 | func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) {
86 | CommandLine.VarP(newIntSliceValue(value, p), name, shorthand, usage)
87 | }
88 |
89 | // IntSlice defines a []int flag with specified name, default value, and usage string.
90 | // The return value is the address of a []int variable that stores the value of the flag.
91 | func (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int {
92 | p := make([]int, 0)
93 | f.IntSliceVarP(&p, name, "", value, usage)
94 | return &p
95 | }
96 |
97 | // Like IntSlice, but accepts a shorthand letter that can be used after a single dash.
98 | func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int {
99 | p := make([]int, 0)
100 | f.IntSliceVarP(&p, name, shorthand, value, usage)
101 | return &p
102 | }
103 |
104 | // IntSlice defines a []int flag with specified name, default value, and usage string.
105 | // The return value is the address of a []int variable that stores the value of the flag.
106 | func IntSlice(name string, value []int, usage string) *[]int {
107 | return CommandLine.IntSliceP(name, "", value, usage)
108 | }
109 |
110 | // Like IntSlice, but accepts a shorthand letter that can be used after a single dash.
111 | func IntSliceP(name, shorthand string, value []int, usage string) *[]int {
112 | return CommandLine.IntSliceP(name, shorthand, value, usage)
113 | }
114 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/ip.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "net"
6 | )
7 |
8 | // -- net.IP value
9 | type ipValue net.IP
10 |
11 | func newIPValue(val net.IP, p *net.IP) *ipValue {
12 | *p = val
13 | return (*ipValue)(p)
14 | }
15 |
16 | func (i *ipValue) String() string { return net.IP(*i).String() }
17 | func (i *ipValue) Set(s string) error {
18 | ip := net.ParseIP(s)
19 | if ip == nil {
20 | return fmt.Errorf("failed to parse IP: %q", s)
21 | }
22 | *i = ipValue(ip)
23 | return nil
24 | }
25 |
26 | func (i *ipValue) Type() string {
27 | return "ip"
28 | }
29 |
30 | func ipConv(sval string) (interface{}, error) {
31 | ip := net.ParseIP(sval)
32 | if ip != nil {
33 | return ip, nil
34 | }
35 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval)
36 | }
37 |
38 | // GetIP return the net.IP value of a flag with the given name
39 | func (f *FlagSet) GetIP(name string) (net.IP, error) {
40 | val, err := f.getFlagType(name, "ip", ipConv)
41 | if err != nil {
42 | return nil, err
43 | }
44 | return val.(net.IP), nil
45 | }
46 |
47 | // IPVar defines an net.IP flag with specified name, default value, and usage string.
48 | // The argument p points to an net.IP variable in which to store the value of the flag.
49 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) {
50 | f.VarP(newIPValue(value, p), name, "", usage)
51 | }
52 |
53 | // Like IPVar, but accepts a shorthand letter that can be used after a single dash.
54 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
55 | f.VarP(newIPValue(value, p), name, shorthand, usage)
56 | }
57 |
58 | // IPVar defines an net.IP flag with specified name, default value, and usage string.
59 | // The argument p points to an net.IP variable in which to store the value of the flag.
60 | func IPVar(p *net.IP, name string, value net.IP, usage string) {
61 | CommandLine.VarP(newIPValue(value, p), name, "", usage)
62 | }
63 |
64 | // Like IPVar, but accepts a shorthand letter that can be used after a single dash.
65 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
66 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage)
67 | }
68 |
69 | // IP defines an net.IP flag with specified name, default value, and usage string.
70 | // The return value is the address of an net.IP variable that stores the value of the flag.
71 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP {
72 | p := new(net.IP)
73 | f.IPVarP(p, name, "", value, usage)
74 | return p
75 | }
76 |
77 | // Like IP, but accepts a shorthand letter that can be used after a single dash.
78 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP {
79 | p := new(net.IP)
80 | f.IPVarP(p, name, shorthand, value, usage)
81 | return p
82 | }
83 |
84 | // IP defines an net.IP flag with specified name, default value, and usage string.
85 | // The return value is the address of an net.IP variable that stores the value of the flag.
86 | func IP(name string, value net.IP, usage string) *net.IP {
87 | return CommandLine.IPP(name, "", value, usage)
88 | }
89 |
90 | // Like IP, but accepts a shorthand letter that can be used after a single dash.
91 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP {
92 | return CommandLine.IPP(name, shorthand, value, usage)
93 | }
94 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/string.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "fmt"
4 |
5 | // -- string Value
6 | type stringValue string
7 |
8 | func newStringValue(val string, p *string) *stringValue {
9 | *p = val
10 | return (*stringValue)(p)
11 | }
12 |
13 | func (s *stringValue) Set(val string) error {
14 | *s = stringValue(val)
15 | return nil
16 | }
17 | func (s *stringValue) Type() string {
18 | return "string"
19 | }
20 |
21 | func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }
22 |
23 | func stringConv(sval string) (interface{}, error) {
24 | return sval, nil
25 | }
26 |
27 | // GetString return the string value of a flag with the given name
28 | func (f *FlagSet) GetString(name string) (string, error) {
29 | val, err := f.getFlagType(name, "string", stringConv)
30 | if err != nil {
31 | return "", err
32 | }
33 | return val.(string), nil
34 | }
35 |
36 | // StringVar defines a string flag with specified name, default value, and usage string.
37 | // The argument p points to a string variable in which to store the value of the flag.
38 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) {
39 | f.VarP(newStringValue(value, p), name, "", usage)
40 | }
41 |
42 | // Like StringVar, but accepts a shorthand letter that can be used after a single dash.
43 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) {
44 | f.VarP(newStringValue(value, p), name, shorthand, usage)
45 | }
46 |
47 | // StringVar defines a string flag with specified name, default value, and usage string.
48 | // The argument p points to a string variable in which to store the value of the flag.
49 | func StringVar(p *string, name string, value string, usage string) {
50 | CommandLine.VarP(newStringValue(value, p), name, "", usage)
51 | }
52 |
53 | // Like StringVar, but accepts a shorthand letter that can be used after a single dash.
54 | func StringVarP(p *string, name, shorthand string, value string, usage string) {
55 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage)
56 | }
57 |
58 | // String defines a string flag with specified name, default value, and usage string.
59 | // The return value is the address of a string variable that stores the value of the flag.
60 | func (f *FlagSet) String(name string, value string, usage string) *string {
61 | p := new(string)
62 | f.StringVarP(p, name, "", value, usage)
63 | return p
64 | }
65 |
66 | // Like String, but accepts a shorthand letter that can be used after a single dash.
67 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string {
68 | p := new(string)
69 | f.StringVarP(p, name, shorthand, value, usage)
70 | return p
71 | }
72 |
73 | // String defines a string flag with specified name, default value, and usage string.
74 | // The return value is the address of a string variable that stores the value of the flag.
75 | func String(name string, value string, usage string) *string {
76 | return CommandLine.StringP(name, "", value, usage)
77 | }
78 |
79 | // Like String, but accepts a shorthand letter that can be used after a single dash.
80 | func StringP(name, shorthand string, value string, usage string) *string {
81 | return CommandLine.StringP(name, shorthand, value, usage)
82 | }
83 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/string_slice.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "strings"
5 | )
6 |
7 | // -- stringSlice Value
8 | type stringSliceValue []string
9 |
10 | func newStringSliceValue(val []string, p *[]string) *stringSliceValue {
11 | *p = val
12 | return (*stringSliceValue)(p)
13 | }
14 |
15 | func (s *stringSliceValue) Set(val string) error {
16 | v := strings.Split(val, ",")
17 | *s = stringSliceValue(v)
18 | return nil
19 | }
20 | func (s *stringSliceValue) Type() string {
21 | return "stringSlice"
22 | }
23 |
24 | func (s *stringSliceValue) String() string { return strings.Join(*s, ",") }
25 |
26 | func stringSliceConv(sval string) (interface{}, error) {
27 | v := strings.Split(sval, ",")
28 | return v, nil
29 | }
30 |
31 | // GetStringSlice return the []string value of a flag with the given name
32 | func (f *FlagSet) GetStringSlice(name string) ([]string, error) {
33 | val, err := f.getFlagType(name, "stringSlice", stringSliceConv)
34 | if err != nil {
35 | return []string{}, err
36 | }
37 | return val.([]string), nil
38 | }
39 |
40 | // StringSliceVar defines a string flag with specified name, default value, and usage string.
41 | // The argument p points to a []string variable in which to store the value of the flag.
42 | func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) {
43 | f.VarP(newStringSliceValue(value, p), name, "", usage)
44 | }
45 |
46 | // Like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
47 | func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) {
48 | f.VarP(newStringSliceValue(value, p), name, shorthand, usage)
49 | }
50 |
51 | // StringSliceVar defines a string flag with specified name, default value, and usage string.
52 | // The argument p points to a []string variable in which to store the value of the flag.
53 | func StringSliceVar(p *[]string, name string, value []string, usage string) {
54 | CommandLine.VarP(newStringSliceValue(value, p), name, "", usage)
55 | }
56 |
57 | // Like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
58 | func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) {
59 | CommandLine.VarP(newStringSliceValue(value, p), name, shorthand, usage)
60 | }
61 |
62 | // StringSlice defines a string flag with specified name, default value, and usage string.
63 | // The return value is the address of a []string variable that stores the value of the flag.
64 | func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string {
65 | p := make([]string, 0)
66 | f.StringSliceVarP(&p, name, "", value, usage)
67 | return &p
68 | }
69 |
70 | // Like StringSlice, but accepts a shorthand letter that can be used after a single dash.
71 | func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage string) *[]string {
72 | p := make([]string, 0)
73 | f.StringSliceVarP(&p, name, shorthand, value, usage)
74 | return &p
75 | }
76 |
77 | // StringSlice defines a string flag with specified name, default value, and usage string.
78 | // The return value is the address of a []string variable that stores the value of the flag.
79 | func StringSlice(name string, value []string, usage string) *[]string {
80 | return CommandLine.StringSliceP(name, "", value, usage)
81 | }
82 |
83 | // Like StringSlice, but accepts a shorthand letter that can be used after a single dash.
84 | func StringSliceP(name, shorthand string, value []string, usage string) *[]string {
85 | return CommandLine.StringSliceP(name, shorthand, value, usage)
86 | }
87 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- uint Value
9 | type uintValue uint
10 |
11 | func newUintValue(val uint, p *uint) *uintValue {
12 | *p = val
13 | return (*uintValue)(p)
14 | }
15 |
16 | func (i *uintValue) Set(s string) error {
17 | v, err := strconv.ParseUint(s, 0, 64)
18 | *i = uintValue(v)
19 | return err
20 | }
21 |
22 | func (i *uintValue) Type() string {
23 | return "uint"
24 | }
25 |
26 | func (i *uintValue) String() string { return fmt.Sprintf("%v", *i) }
27 |
28 | func uintConv(sval string) (interface{}, error) {
29 | v, err := strconv.ParseUint(sval, 0, 0)
30 | if err != nil {
31 | return 0, err
32 | }
33 | return uint(v), nil
34 | }
35 |
36 | // GetUint return the uint value of a flag with the given name
37 | func (f *FlagSet) GetUint(name string) (uint, error) {
38 | val, err := f.getFlagType(name, "uint", uintConv)
39 | if err != nil {
40 | return 0, err
41 | }
42 | return val.(uint), nil
43 | }
44 |
45 | // UintVar defines a uint flag with specified name, default value, and usage string.
46 | // The argument p points to a uint variable in which to store the value of the flag.
47 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) {
48 | f.VarP(newUintValue(value, p), name, "", usage)
49 | }
50 |
51 | // Like UintVar, but accepts a shorthand letter that can be used after a single dash.
52 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) {
53 | f.VarP(newUintValue(value, p), name, shorthand, usage)
54 | }
55 |
56 | // UintVar defines a uint flag with specified name, default value, and usage string.
57 | // The argument p points to a uint variable in which to store the value of the flag.
58 | func UintVar(p *uint, name string, value uint, usage string) {
59 | CommandLine.VarP(newUintValue(value, p), name, "", usage)
60 | }
61 |
62 | // Like UintVar, but accepts a shorthand letter that can be used after a single dash.
63 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) {
64 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage)
65 | }
66 |
67 | // Uint defines a uint flag with specified name, default value, and usage string.
68 | // The return value is the address of a uint variable that stores the value of the flag.
69 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint {
70 | p := new(uint)
71 | f.UintVarP(p, name, "", value, usage)
72 | return p
73 | }
74 |
75 | // Like Uint, but accepts a shorthand letter that can be used after a single dash.
76 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint {
77 | p := new(uint)
78 | f.UintVarP(p, name, shorthand, value, usage)
79 | return p
80 | }
81 |
82 | // Uint defines a uint flag with specified name, default value, and usage string.
83 | // The return value is the address of a uint variable that stores the value of the flag.
84 | func Uint(name string, value uint, usage string) *uint {
85 | return CommandLine.UintP(name, "", value, usage)
86 | }
87 |
88 | // Like Uint, but accepts a shorthand letter that can be used after a single dash.
89 | func UintP(name, shorthand string, value uint, usage string) *uint {
90 | return CommandLine.UintP(name, shorthand, value, usage)
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint16.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- uint16 value
9 | type uint16Value uint16
10 |
11 | func newUint16Value(val uint16, p *uint16) *uint16Value {
12 | *p = val
13 | return (*uint16Value)(p)
14 | }
15 | func (i *uint16Value) String() string { return fmt.Sprintf("%d", *i) }
16 | func (i *uint16Value) Set(s string) error {
17 | v, err := strconv.ParseUint(s, 0, 16)
18 | *i = uint16Value(v)
19 | return err
20 | }
21 |
22 | func (i *uint16Value) Type() string {
23 | return "uint16"
24 | }
25 |
26 | func uint16Conv(sval string) (interface{}, error) {
27 | v, err := strconv.ParseUint(sval, 0, 16)
28 | if err != nil {
29 | return 0, err
30 | }
31 | return uint16(v), nil
32 | }
33 |
34 | // GetUint16 return the uint16 value of a flag with the given name
35 | func (f *FlagSet) GetUint16(name string) (uint16, error) {
36 | val, err := f.getFlagType(name, "uint16", uint16Conv)
37 | if err != nil {
38 | return 0, err
39 | }
40 | return val.(uint16), nil
41 | }
42 |
43 | // Uint16Var defines a uint flag with specified name, default value, and usage string.
44 | // The argument p points to a uint variable in which to store the value of the flag.
45 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) {
46 | f.VarP(newUint16Value(value, p), name, "", usage)
47 | }
48 |
49 | // Like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
50 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
51 | f.VarP(newUint16Value(value, p), name, shorthand, usage)
52 | }
53 |
54 | // Uint16Var defines a uint flag with specified name, default value, and usage string.
55 | // The argument p points to a uint variable in which to store the value of the flag.
56 | func Uint16Var(p *uint16, name string, value uint16, usage string) {
57 | CommandLine.VarP(newUint16Value(value, p), name, "", usage)
58 | }
59 |
60 | // Like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
61 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
62 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage)
63 | }
64 |
65 | // Uint16 defines a uint flag with specified name, default value, and usage string.
66 | // The return value is the address of a uint variable that stores the value of the flag.
67 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 {
68 | p := new(uint16)
69 | f.Uint16VarP(p, name, "", value, usage)
70 | return p
71 | }
72 |
73 | // Like Uint16, but accepts a shorthand letter that can be used after a single dash.
74 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
75 | p := new(uint16)
76 | f.Uint16VarP(p, name, shorthand, value, usage)
77 | return p
78 | }
79 |
80 | // Uint16 defines a uint flag with specified name, default value, and usage string.
81 | // The return value is the address of a uint variable that stores the value of the flag.
82 | func Uint16(name string, value uint16, usage string) *uint16 {
83 | return CommandLine.Uint16P(name, "", value, usage)
84 | }
85 |
86 | // Like Uint16, but accepts a shorthand letter that can be used after a single dash.
87 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
88 | return CommandLine.Uint16P(name, shorthand, value, usage)
89 | }
90 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint32.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- uint16 value
9 | type uint32Value uint32
10 |
11 | func newUint32Value(val uint32, p *uint32) *uint32Value {
12 | *p = val
13 | return (*uint32Value)(p)
14 | }
15 | func (i *uint32Value) String() string { return fmt.Sprintf("%d", *i) }
16 | func (i *uint32Value) Set(s string) error {
17 | v, err := strconv.ParseUint(s, 0, 32)
18 | *i = uint32Value(v)
19 | return err
20 | }
21 |
22 | func (i *uint32Value) Type() string {
23 | return "uint32"
24 | }
25 |
26 | func uint32Conv(sval string) (interface{}, error) {
27 | v, err := strconv.ParseUint(sval, 0, 32)
28 | if err != nil {
29 | return 0, err
30 | }
31 | return uint32(v), nil
32 | }
33 |
34 | // GetUint32 return the uint32 value of a flag with the given name
35 | func (f *FlagSet) GetUint32(name string) (uint32, error) {
36 | val, err := f.getFlagType(name, "uint32", uint32Conv)
37 | if err != nil {
38 | return 0, err
39 | }
40 | return val.(uint32), nil
41 | }
42 |
43 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string.
44 | // The argument p points to a uint32 variable in which to store the value of the flag.
45 | func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) {
46 | f.VarP(newUint32Value(value, p), name, "", usage)
47 | }
48 |
49 | // Like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
50 | func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
51 | f.VarP(newUint32Value(value, p), name, shorthand, usage)
52 | }
53 |
54 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string.
55 | // The argument p points to a uint32 variable in which to store the value of the flag.
56 | func Uint32Var(p *uint32, name string, value uint32, usage string) {
57 | CommandLine.VarP(newUint32Value(value, p), name, "", usage)
58 | }
59 |
60 | // Like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
61 | func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
62 | CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage)
63 | }
64 |
65 | // Uint32 defines a uint32 flag with specified name, default value, and usage string.
66 | // The return value is the address of a uint32 variable that stores the value of the flag.
67 | func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 {
68 | p := new(uint32)
69 | f.Uint32VarP(p, name, "", value, usage)
70 | return p
71 | }
72 |
73 | // Like Uint32, but accepts a shorthand letter that can be used after a single dash.
74 | func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
75 | p := new(uint32)
76 | f.Uint32VarP(p, name, shorthand, value, usage)
77 | return p
78 | }
79 |
80 | // Uint32 defines a uint32 flag with specified name, default value, and usage string.
81 | // The return value is the address of a uint32 variable that stores the value of the flag.
82 | func Uint32(name string, value uint32, usage string) *uint32 {
83 | return CommandLine.Uint32P(name, "", value, usage)
84 | }
85 |
86 | // Like Uint32, but accepts a shorthand letter that can be used after a single dash.
87 | func Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
88 | return CommandLine.Uint32P(name, shorthand, value, usage)
89 | }
90 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint64.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- uint64 Value
9 | type uint64Value uint64
10 |
11 | func newUint64Value(val uint64, p *uint64) *uint64Value {
12 | *p = val
13 | return (*uint64Value)(p)
14 | }
15 |
16 | func (i *uint64Value) Set(s string) error {
17 | v, err := strconv.ParseUint(s, 0, 64)
18 | *i = uint64Value(v)
19 | return err
20 | }
21 |
22 | func (i *uint64Value) Type() string {
23 | return "uint64"
24 | }
25 |
26 | func (i *uint64Value) String() string { return fmt.Sprintf("%v", *i) }
27 |
28 | func uint64Conv(sval string) (interface{}, error) {
29 | v, err := strconv.ParseUint(sval, 0, 64)
30 | if err != nil {
31 | return 0, err
32 | }
33 | return uint64(v), nil
34 | }
35 |
36 | // GetUint64 return the uint64 value of a flag with the given name
37 | func (f *FlagSet) GetUint64(name string) (uint64, error) {
38 | val, err := f.getFlagType(name, "uint64", uint64Conv)
39 | if err != nil {
40 | return 0, err
41 | }
42 | return val.(uint64), nil
43 | }
44 |
45 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string.
46 | // The argument p points to a uint64 variable in which to store the value of the flag.
47 | func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) {
48 | f.VarP(newUint64Value(value, p), name, "", usage)
49 | }
50 |
51 | // Like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
52 | func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
53 | f.VarP(newUint64Value(value, p), name, shorthand, usage)
54 | }
55 |
56 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string.
57 | // The argument p points to a uint64 variable in which to store the value of the flag.
58 | func Uint64Var(p *uint64, name string, value uint64, usage string) {
59 | CommandLine.VarP(newUint64Value(value, p), name, "", usage)
60 | }
61 |
62 | // Like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
63 | func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
64 | CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage)
65 | }
66 |
67 | // Uint64 defines a uint64 flag with specified name, default value, and usage string.
68 | // The return value is the address of a uint64 variable that stores the value of the flag.
69 | func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 {
70 | p := new(uint64)
71 | f.Uint64VarP(p, name, "", value, usage)
72 | return p
73 | }
74 |
75 | // Like Uint64, but accepts a shorthand letter that can be used after a single dash.
76 | func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
77 | p := new(uint64)
78 | f.Uint64VarP(p, name, shorthand, value, usage)
79 | return p
80 | }
81 |
82 | // Uint64 defines a uint64 flag with specified name, default value, and usage string.
83 | // The return value is the address of a uint64 variable that stores the value of the flag.
84 | func Uint64(name string, value uint64, usage string) *uint64 {
85 | return CommandLine.Uint64P(name, "", value, usage)
86 | }
87 |
88 | // Like Uint64, but accepts a shorthand letter that can be used after a single dash.
89 | func Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
90 | return CommandLine.Uint64P(name, shorthand, value, usage)
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint8.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "strconv"
6 | )
7 |
8 | // -- uint8 Value
9 | type uint8Value uint8
10 |
11 | func newUint8Value(val uint8, p *uint8) *uint8Value {
12 | *p = val
13 | return (*uint8Value)(p)
14 | }
15 |
16 | func (i *uint8Value) Set(s string) error {
17 | v, err := strconv.ParseUint(s, 0, 8)
18 | *i = uint8Value(v)
19 | return err
20 | }
21 |
22 | func (i *uint8Value) Type() string {
23 | return "uint8"
24 | }
25 |
26 | func (i *uint8Value) String() string { return fmt.Sprintf("%v", *i) }
27 |
28 | func uint8Conv(sval string) (interface{}, error) {
29 | v, err := strconv.ParseUint(sval, 0, 8)
30 | if err != nil {
31 | return 0, err
32 | }
33 | return uint8(v), nil
34 | }
35 |
36 | // GetUint8 return the uint8 value of a flag with the given name
37 | func (f *FlagSet) GetUint8(name string) (uint8, error) {
38 | val, err := f.getFlagType(name, "uint8", uint8Conv)
39 | if err != nil {
40 | return 0, err
41 | }
42 | return val.(uint8), nil
43 | }
44 |
45 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string.
46 | // The argument p points to a uint8 variable in which to store the value of the flag.
47 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) {
48 | f.VarP(newUint8Value(value, p), name, "", usage)
49 | }
50 |
51 | // Like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
52 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
53 | f.VarP(newUint8Value(value, p), name, shorthand, usage)
54 | }
55 |
56 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string.
57 | // The argument p points to a uint8 variable in which to store the value of the flag.
58 | func Uint8Var(p *uint8, name string, value uint8, usage string) {
59 | CommandLine.VarP(newUint8Value(value, p), name, "", usage)
60 | }
61 |
62 | // Like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
63 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
64 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage)
65 | }
66 |
67 | // Uint8 defines a uint8 flag with specified name, default value, and usage string.
68 | // The return value is the address of a uint8 variable that stores the value of the flag.
69 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 {
70 | p := new(uint8)
71 | f.Uint8VarP(p, name, "", value, usage)
72 | return p
73 | }
74 |
75 | // Like Uint8, but accepts a shorthand letter that can be used after a single dash.
76 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
77 | p := new(uint8)
78 | f.Uint8VarP(p, name, shorthand, value, usage)
79 | return p
80 | }
81 |
82 | // Uint8 defines a uint8 flag with specified name, default value, and usage string.
83 | // The return value is the address of a uint8 variable that stores the value of the flag.
84 | func Uint8(name string, value uint8, usage string) *uint8 {
85 | return CommandLine.Uint8P(name, "", value, usage)
86 | }
87 |
88 | // Like Uint8, but accepts a shorthand letter that can be used after a single dash.
89 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
90 | return CommandLine.Uint8P(name, shorthand, value, usage)
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/go4.org/errorutil/highlight.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2011 Google Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // Package errorutil helps make better error messages.
18 | package errorutil // import "go4.org/errorutil"
19 |
20 | import (
21 | "bufio"
22 | "bytes"
23 | "fmt"
24 | "io"
25 | "strings"
26 | )
27 |
28 | // HighlightBytePosition takes a reader and the location in bytes of a parse
29 | // error (for instance, from json.SyntaxError.Offset) and returns the line, column,
30 | // and pretty-printed context around the error with an arrow indicating the exact
31 | // position of the syntax error.
32 | func HighlightBytePosition(f io.Reader, pos int64) (line, col int, highlight string) {
33 | line = 1
34 | br := bufio.NewReader(f)
35 | lastLine := ""
36 | thisLine := new(bytes.Buffer)
37 | for n := int64(0); n < pos; n++ {
38 | b, err := br.ReadByte()
39 | if err != nil {
40 | break
41 | }
42 | if b == '\n' {
43 | lastLine = thisLine.String()
44 | thisLine.Reset()
45 | line++
46 | col = 1
47 | } else {
48 | col++
49 | thisLine.WriteByte(b)
50 | }
51 | }
52 | if line > 1 {
53 | highlight += fmt.Sprintf("%5d: %s\n", line-1, lastLine)
54 | }
55 | highlight += fmt.Sprintf("%5d: %s\n", line, thisLine.String())
56 | highlight += fmt.Sprintf("%s^\n", strings.Repeat(" ", col+5))
57 | return
58 | }
59 |
--------------------------------------------------------------------------------
/vendor/gopkg.in/inf.v0/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Péter Surányi. Portions Copyright (c) 2009 The Go
2 | Authors. All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above
11 | copyright notice, this list of conditions and the following disclaimer
12 | in the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Google Inc. nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/vendor/gopkg.in/yaml.v2/LICENSE.libyaml:
--------------------------------------------------------------------------------
1 | The following files were ported to Go from C files of libyaml, and thus
2 | are still covered by their original copyright and license:
3 |
4 | apic.go
5 | emitterc.go
6 | parserc.go
7 | readerc.go
8 | scannerc.go
9 | writerc.go
10 | yamlh.go
11 | yamlprivateh.go
12 |
13 | Copyright (c) 2006 Kirill Simonov
14 |
15 | Permission is hereby granted, free of charge, to any person obtaining a copy of
16 | this software and associated documentation files (the "Software"), to deal in
17 | the Software without restriction, including without limitation the rights to
18 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
19 | of the Software, and to permit persons to whom the Software is furnished to do
20 | so, subject to the following conditions:
21 |
22 | The above copyright notice and this permission notice shall be included in all
23 | copies or substantial portions of the Software.
24 |
25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 | SOFTWARE.
32 |
--------------------------------------------------------------------------------
/vendor/gopkg.in/yaml.v2/sorter.go:
--------------------------------------------------------------------------------
1 | package yaml
2 |
3 | import (
4 | "reflect"
5 | "unicode"
6 | )
7 |
8 | type keyList []reflect.Value
9 |
10 | func (l keyList) Len() int { return len(l) }
11 | func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
12 | func (l keyList) Less(i, j int) bool {
13 | a := l[i]
14 | b := l[j]
15 | ak := a.Kind()
16 | bk := b.Kind()
17 | for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() {
18 | a = a.Elem()
19 | ak = a.Kind()
20 | }
21 | for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() {
22 | b = b.Elem()
23 | bk = b.Kind()
24 | }
25 | af, aok := keyFloat(a)
26 | bf, bok := keyFloat(b)
27 | if aok && bok {
28 | if af != bf {
29 | return af < bf
30 | }
31 | if ak != bk {
32 | return ak < bk
33 | }
34 | return numLess(a, b)
35 | }
36 | if ak != reflect.String || bk != reflect.String {
37 | return ak < bk
38 | }
39 | ar, br := []rune(a.String()), []rune(b.String())
40 | for i := 0; i < len(ar) && i < len(br); i++ {
41 | if ar[i] == br[i] {
42 | continue
43 | }
44 | al := unicode.IsLetter(ar[i])
45 | bl := unicode.IsLetter(br[i])
46 | if al && bl {
47 | return ar[i] < br[i]
48 | }
49 | if al || bl {
50 | return bl
51 | }
52 | var ai, bi int
53 | var an, bn int64
54 | for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ {
55 | an = an*10 + int64(ar[ai]-'0')
56 | }
57 | for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ {
58 | bn = bn*10 + int64(br[bi]-'0')
59 | }
60 | if an != bn {
61 | return an < bn
62 | }
63 | if ai != bi {
64 | return ai < bi
65 | }
66 | return ar[i] < br[i]
67 | }
68 | return len(ar) < len(br)
69 | }
70 |
71 | // keyFloat returns a float value for v if it is a number/bool
72 | // and whether it is a number/bool or not.
73 | func keyFloat(v reflect.Value) (f float64, ok bool) {
74 | switch v.Kind() {
75 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
76 | return float64(v.Int()), true
77 | case reflect.Float32, reflect.Float64:
78 | return v.Float(), true
79 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
80 | return float64(v.Uint()), true
81 | case reflect.Bool:
82 | if v.Bool() {
83 | return 1, true
84 | }
85 | return 0, true
86 | }
87 | return 0, false
88 | }
89 |
90 | // numLess returns whether a < b.
91 | // a and b must necessarily have the same kind.
92 | func numLess(a, b reflect.Value) bool {
93 | switch a.Kind() {
94 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
95 | return a.Int() < b.Int()
96 | case reflect.Float32, reflect.Float64:
97 | return a.Float() < b.Float()
98 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
99 | return a.Uint() < b.Uint()
100 | case reflect.Bool:
101 | return !a.Bool() && b.Bool()
102 | }
103 | panic("not a number")
104 | }
105 |
--------------------------------------------------------------------------------
/vendor/gopkg.in/yaml.v2/writerc.go:
--------------------------------------------------------------------------------
1 | package yaml
2 |
3 | // Set the writer error and return false.
4 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool {
5 | emitter.error = yaml_WRITER_ERROR
6 | emitter.problem = problem
7 | return false
8 | }
9 |
10 | // Flush the output buffer.
11 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool {
12 | if emitter.write_handler == nil {
13 | panic("write handler not set")
14 | }
15 |
16 | // Check if the buffer is empty.
17 | if emitter.buffer_pos == 0 {
18 | return true
19 | }
20 |
21 | // If the output encoding is UTF-8, we don't need to recode the buffer.
22 | if emitter.encoding == yaml_UTF8_ENCODING {
23 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil {
24 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error())
25 | }
26 | emitter.buffer_pos = 0
27 | return true
28 | }
29 |
30 | // Recode the buffer into the raw buffer.
31 | var low, high int
32 | if emitter.encoding == yaml_UTF16LE_ENCODING {
33 | low, high = 0, 1
34 | } else {
35 | high, low = 1, 0
36 | }
37 |
38 | pos := 0
39 | for pos < emitter.buffer_pos {
40 | // See the "reader.c" code for more details on UTF-8 encoding. Note
41 | // that we assume that the buffer contains a valid UTF-8 sequence.
42 |
43 | // Read the next UTF-8 character.
44 | octet := emitter.buffer[pos]
45 |
46 | var w int
47 | var value rune
48 | switch {
49 | case octet&0x80 == 0x00:
50 | w, value = 1, rune(octet&0x7F)
51 | case octet&0xE0 == 0xC0:
52 | w, value = 2, rune(octet&0x1F)
53 | case octet&0xF0 == 0xE0:
54 | w, value = 3, rune(octet&0x0F)
55 | case octet&0xF8 == 0xF0:
56 | w, value = 4, rune(octet&0x07)
57 | }
58 | for k := 1; k < w; k++ {
59 | octet = emitter.buffer[pos+k]
60 | value = (value << 6) + (rune(octet) & 0x3F)
61 | }
62 | pos += w
63 |
64 | // Write the character.
65 | if value < 0x10000 {
66 | var b [2]byte
67 | b[high] = byte(value >> 8)
68 | b[low] = byte(value & 0xFF)
69 | emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1])
70 | } else {
71 | // Write the character using a surrogate pair (check "reader.c").
72 | var b [4]byte
73 | value -= 0x10000
74 | b[high] = byte(0xD8 + (value >> 18))
75 | b[low] = byte((value >> 10) & 0xFF)
76 | b[high+2] = byte(0xDC + ((value >> 8) & 0xFF))
77 | b[low+2] = byte(value & 0xFF)
78 | emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1], b[2], b[3])
79 | }
80 | }
81 |
82 | // Write the raw buffer.
83 | if err := emitter.write_handler(emitter, emitter.raw_buffer); err != nil {
84 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error())
85 | }
86 | emitter.buffer_pos = 0
87 | emitter.raw_buffer = emitter.raw_buffer[:0]
88 | return true
89 | }
90 |
--------------------------------------------------------------------------------
/vendor/k8s.io/kubernetes/pkg/api/resource/generated.pb.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2016 The Kubernetes Authors.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | // Code generated by protoc-gen-gogo.
18 | // source: k8s.io/kubernetes/pkg/api/resource/generated.proto
19 | // DO NOT EDIT!
20 |
21 | /*
22 | Package resource is a generated protocol buffer package.
23 |
24 | It is generated from these files:
25 | k8s.io/kubernetes/pkg/api/resource/generated.proto
26 |
27 | It has these top-level messages:
28 | Quantity
29 | */
30 | package resource
31 |
32 | import proto "github.com/gogo/protobuf/proto"
33 | import fmt "fmt"
34 | import math "math"
35 |
36 | // Reference imports to suppress errors if they are not otherwise used.
37 | var _ = proto.Marshal
38 | var _ = fmt.Errorf
39 | var _ = math.Inf
40 |
41 | // This is a compile-time assertion to ensure that this generated file
42 | // is compatible with the proto package it is being compiled against.
43 | const _ = proto.GoGoProtoPackageIsVersion1
44 |
45 | func (m *Quantity) Reset() { *m = Quantity{} }
46 | func (*Quantity) ProtoMessage() {}
47 | func (*Quantity) Descriptor() ([]byte, []int) { return fileDescriptorGenerated, []int{0} }
48 |
49 | func init() {
50 | proto.RegisterType((*Quantity)(nil), "k8s.io.kubernetes.pkg.api.resource.Quantity")
51 | }
52 |
53 | var fileDescriptorGenerated = []byte{
54 | // 222 bytes of a gzipped FileDescriptorProto
55 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x32, 0xca, 0xb6, 0x28, 0xd6,
56 | 0xcb, 0xcc, 0xd7, 0xcf, 0x2e, 0x4d, 0x4a, 0x2d, 0xca, 0x4b, 0x2d, 0x49, 0x2d, 0xd6, 0x2f, 0xc8,
57 | 0x4e, 0xd7, 0x4f, 0x2c, 0xc8, 0xd4, 0x2f, 0x4a, 0x2d, 0xce, 0x2f, 0x2d, 0x4a, 0x4e, 0xd5, 0x4f,
58 | 0x4f, 0xcd, 0x4b, 0x2d, 0x4a, 0x2c, 0x49, 0x4d, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52,
59 | 0x82, 0xe8, 0xd1, 0x43, 0xe8, 0xd1, 0x03, 0xea, 0xd1, 0x03, 0xea, 0xd1, 0x83, 0xe9, 0x91, 0xd2,
60 | 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f, 0xcf, 0xd7,
61 | 0x07, 0x6b, 0x4d, 0x2a, 0x4d, 0x03, 0xf3, 0xc0, 0x1c, 0x30, 0x0b, 0x62, 0xa4, 0x94, 0x21, 0x76,
62 | 0x67, 0x94, 0x96, 0x64, 0xe6, 0xe8, 0x67, 0xe6, 0x95, 0x14, 0x97, 0x14, 0xa1, 0xbb, 0x42, 0xc9,
63 | 0x82, 0x8b, 0x23, 0xb0, 0x34, 0x31, 0xaf, 0x24, 0xb3, 0xa4, 0x52, 0x48, 0x8c, 0x8b, 0x0d, 0xa8,
64 | 0x24, 0x33, 0x2f, 0x5d, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x08, 0xca, 0xb3, 0x12, 0x99, 0xb1,
65 | 0x40, 0x9e, 0xa1, 0x63, 0xa1, 0x3c, 0xc3, 0x04, 0x20, 0x5e, 0x00, 0xc4, 0x0d, 0x77, 0x14, 0x18,
66 | 0x9c, 0xb4, 0x4e, 0x3c, 0x94, 0x63, 0xb8, 0x00, 0xc4, 0x37, 0x80, 0xb8, 0xe1, 0x91, 0x1c, 0xe3,
67 | 0x09, 0x20, 0xbe, 0x00, 0xc4, 0x0f, 0x80, 0x78, 0xc2, 0x63, 0x39, 0x86, 0x28, 0x0e, 0x98, 0x3f,
68 | 0x00, 0x01, 0x00, 0x00, 0xff, 0xff, 0x90, 0x1c, 0x7f, 0xff, 0x20, 0x01, 0x00, 0x00,
69 | }
70 |
--------------------------------------------------------------------------------
/vendor/k8s.io/kubernetes/pkg/api/resource/scale_int.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2015 The Kubernetes Authors.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | package resource
18 |
19 | import (
20 | "math"
21 | "math/big"
22 | "sync"
23 | )
24 |
25 | var (
26 | // A sync pool to reduce allocation.
27 | intPool sync.Pool
28 | maxInt64 = big.NewInt(math.MaxInt64)
29 | )
30 |
31 | func init() {
32 | intPool.New = func() interface{} {
33 | return &big.Int{}
34 | }
35 | }
36 |
37 | // scaledValue scales given unscaled value from scale to new Scale and returns
38 | // an int64. It ALWAYS rounds up the result when scale down. The final result might
39 | // overflow.
40 | //
41 | // scale, newScale represents the scale of the unscaled decimal.
42 | // The mathematical value of the decimal is unscaled * 10**(-scale).
43 | func scaledValue(unscaled *big.Int, scale, newScale int) int64 {
44 | dif := scale - newScale
45 | if dif == 0 {
46 | return unscaled.Int64()
47 | }
48 |
49 | // Handle scale up
50 | // This is an easy case, we do not need to care about rounding and overflow.
51 | // If any intermediate operation causes overflow, the result will overflow.
52 | if dif < 0 {
53 | return unscaled.Int64() * int64(math.Pow10(-dif))
54 | }
55 |
56 | // Handle scale down
57 | // We have to be careful about the intermediate operations.
58 |
59 | // fast path when unscaled < max.Int64 and exp(10,dif) < max.Int64
60 | const log10MaxInt64 = 19
61 | if unscaled.Cmp(maxInt64) < 0 && dif < log10MaxInt64 {
62 | divide := int64(math.Pow10(dif))
63 | result := unscaled.Int64() / divide
64 | mod := unscaled.Int64() % divide
65 | if mod != 0 {
66 | return result + 1
67 | }
68 | return result
69 | }
70 |
71 | // We should only convert back to int64 when getting the result.
72 | divisor := intPool.Get().(*big.Int)
73 | exp := intPool.Get().(*big.Int)
74 | result := intPool.Get().(*big.Int)
75 | defer func() {
76 | intPool.Put(divisor)
77 | intPool.Put(exp)
78 | intPool.Put(result)
79 | }()
80 |
81 | // divisor = 10^(dif)
82 | // TODO: create loop up table if exp costs too much.
83 | divisor.Exp(bigTen, exp.SetInt64(int64(dif)), nil)
84 | // reuse exp
85 | remainder := exp
86 |
87 | // result = unscaled / divisor
88 | // remainder = unscaled % divisor
89 | result.DivMod(unscaled, divisor, remainder)
90 | if remainder.Sign() != 0 {
91 | return result.Int64() + 1
92 | }
93 |
94 | return result.Int64()
95 | }
96 |
--------------------------------------------------------------------------------
/version.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "strconv"
5 | "strings"
6 | )
7 |
8 | type Version string
9 |
10 | func (v Version) compareTo(other Version) int {
11 | currTab := strings.SplitN(string(v), ".", 3)
12 | otherTab := strings.SplitN(string(other), ".", 3)
13 |
14 | currSuffix := strings.SplitN(currTab[len(currTab)-1], "-", 2)
15 | otherSuffix := strings.SplitN(otherTab[len(otherTab)-1], "-", 2)
16 | currTab[len(currTab)-1] = currSuffix[0]
17 | otherTab[len(otherTab)-1] = otherSuffix[0]
18 |
19 | max := len(currTab)
20 | if len(otherTab) > max {
21 | max = len(otherTab)
22 | }
23 | for i := 0; i < max; i++ {
24 | var currInt, otherInt int
25 | if len(currTab) > i {
26 | currInt, _ = strconv.Atoi(currTab[i])
27 | }
28 | if len(otherTab) > i {
29 | otherInt, _ = strconv.Atoi(otherTab[i])
30 | }
31 | if currInt > otherInt {
32 | return 1
33 | }
34 | if otherInt > currInt {
35 | return -1
36 | }
37 | }
38 |
39 | smax := 0
40 | if len(currSuffix) == 2 {
41 | smax = len(currSuffix[1])
42 | }
43 | if len(otherSuffix) == 2 && len(otherSuffix[1]) > smax {
44 | smax = len(otherSuffix[1])
45 | }
46 | for i := 0; i < smax; i++ {
47 | var currByte, otherByte byte
48 | if len(currSuffix) == 2 && len(currSuffix[1]) > i {
49 | currByte = currSuffix[1][i]
50 | }
51 | if len(otherSuffix) == 2 && len(otherSuffix[1]) > i {
52 | otherByte = otherSuffix[1][i]
53 | }
54 | if currByte > otherByte {
55 | return 1
56 | }
57 | if otherByte > currByte {
58 | return -1
59 | }
60 | }
61 |
62 | return 0
63 | }
64 |
65 | // LessThan checks if a version is less than another
66 | func (v Version) LessThan(other Version) bool {
67 | return v.compareTo(other) == -1
68 | }
69 |
70 | // LessThanOrEqualTo checks if a version is less than or equal to another
71 | func (v Version) LessThanOrEqualTo(other Version) bool {
72 | return v.compareTo(other) <= 0
73 | }
74 |
75 | // GreaterThan checks if a version is greater than another
76 | func (v Version) GreaterThan(other Version) bool {
77 | return v.compareTo(other) == 1
78 | }
79 |
80 | // GreaterThanOrEqualTo checks if a version is greater than or equal to another
81 | func (v Version) GreaterThanOrEqualTo(other Version) bool {
82 | return v.compareTo(other) >= 0
83 | }
84 |
85 | // Equal checks if a version is equal to another
86 | func (v Version) Equal(other Version) bool {
87 | return v.compareTo(other) == 0
88 | }
89 |
--------------------------------------------------------------------------------
/version_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func assertVersion(t *testing.T, a, b string, result int) {
8 | if r := Version(a).compareTo(Version(b)); r != result {
9 | t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result)
10 | }
11 | }
12 |
13 | func TestCompareVersion(t *testing.T) {
14 | assertVersion(t, "1.12", "1.12", 0)
15 | assertVersion(t, "1.0.0", "1", 0)
16 | assertVersion(t, "1", "1.0.0", 0)
17 | assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1)
18 | assertVersion(t, "1", "1.0.1", -1)
19 | assertVersion(t, "1.0.1", "1", 1)
20 | assertVersion(t, "1.0.1", "1.0.2", -1)
21 | assertVersion(t, "1.0.2", "1.0.3", -1)
22 | assertVersion(t, "1.0.3", "1.1", -1)
23 | assertVersion(t, "1.1", "1.1.1", -1)
24 | assertVersion(t, "1.1.1", "1.1.2", -1)
25 | assertVersion(t, "1.1.2", "1.2", -1)
26 | assertVersion(t, "1", "1", 0)
27 | assertVersion(t, "20161105.091808-vd37650e", "20161105.004945-vd37650e", 1)
28 | assertVersion(t, "20161105.091808-42A", "20161105.091808-42A", 0)
29 | assertVersion(t, "20161105.091808-42A", "20161105.091808-42B", -1)
30 | assertVersion(t, "20161105.091808-42A", "20161105-42A", 1)
31 | assertVersion(t, "20161105.091808-42A", "20161105", 1)
32 | assertVersion(t, "20161105.091808", "20161105-42A", 1)
33 | assertVersion(t, "20161105.091808", "20161105-42A", 1)
34 | }
35 |
--------------------------------------------------------------------------------