├── .gitignore
├── .goreleaser.yml
├── .travis.yml
├── CONTRIBUTING.md
├── Gopkg.lock
├── Gopkg.toml
├── LICENSE
├── README.md
├── cmd
├── configType.go
├── describe.go
├── generate.go
├── init.go
├── root.go
├── version.go
└── versionnumber.go
├── main.go
├── post-commit.sh
├── setup-local-hooks.sh
└── vendor
└── github.com
├── ahmedalhulaibi
└── substance
│ ├── .gitignore
│ ├── .travis.yml
│ ├── CONTRIBUTING.md
│ ├── Gopkg.lock
│ ├── Gopkg.toml
│ ├── LICENSE
│ ├── README.md
│ ├── docker-compose.yml
│ ├── providers
│ ├── mysqlsubstance
│ │ ├── mysqlDataTypeMap.go
│ │ ├── mysqlQueries.go
│ │ └── mysqlsubstance.go
│ ├── pgsqlsubstance
│ │ ├── pgsqlDataTypeMap.go
│ │ ├── pgsqlQueries.go
│ │ └── pgsqlsubstance.go
│ └── testsubstance
│ │ └── testsubstance.go
│ ├── substance.go
│ └── substancegen
│ ├── generators
│ ├── gorm
│ │ └── gorm.go
│ ├── gostruct
│ │ └── gostruct.go
│ ├── gqlschema
│ │ ├── gqlschema.go
│ │ └── gqlschema_templates.go
│ └── graphqlgo
│ │ ├── codeGeneration.go
│ │ ├── graphqlgo.go
│ │ └── graphqlgo_templates.go
│ ├── genutil.go
│ └── substancegen.go
├── apex
└── log
│ ├── LICENSE
│ ├── Makefile
│ ├── Readme.md
│ ├── default.go
│ ├── doc.go
│ ├── entry.go
│ ├── interface.go
│ ├── levels.go
│ ├── logger.go
│ ├── pkg.go
│ └── stack.go
├── go-sql-driver
└── mysql
│ ├── .gitignore
│ ├── .travis.yml
│ ├── AUTHORS
│ ├── CHANGELOG.md
│ ├── CONTRIBUTING.md
│ ├── LICENSE
│ ├── README.md
│ ├── appengine.go
│ ├── buffer.go
│ ├── collations.go
│ ├── connection.go
│ ├── const.go
│ ├── driver.go
│ ├── dsn.go
│ ├── errors.go
│ ├── infile.go
│ ├── packets.go
│ ├── result.go
│ ├── rows.go
│ ├── statement.go
│ ├── transaction.go
│ └── utils.go
├── inconshreveable
└── mousetrap
│ ├── LICENSE
│ ├── README.md
│ ├── trap_others.go
│ ├── trap_windows.go
│ └── trap_windows_1.4.go
├── jinzhu
└── inflection
│ ├── LICENSE
│ ├── README.md
│ └── inflections.go
├── lib
└── pq
│ ├── .gitignore
│ ├── .travis.sh
│ ├── .travis.yml
│ ├── CONTRIBUTING.md
│ ├── LICENSE.md
│ ├── README.md
│ ├── array.go
│ ├── buf.go
│ ├── conn.go
│ ├── conn_go18.go
│ ├── copy.go
│ ├── doc.go
│ ├── encode.go
│ ├── error.go
│ ├── notify.go
│ ├── oid
│ ├── doc.go
│ ├── gen.go
│ └── types.go
│ ├── rows.go
│ ├── ssl.go
│ ├── ssl_go1.7.go
│ ├── ssl_permissions.go
│ ├── ssl_renegotiation.go
│ ├── ssl_windows.go
│ ├── url.go
│ ├── user_posix.go
│ ├── user_windows.go
│ └── uuid.go
├── pkg
└── errors
│ ├── .gitignore
│ ├── .travis.yml
│ ├── LICENSE
│ ├── README.md
│ ├── appveyor.yml
│ ├── errors.go
│ └── stack.go
└── spf13
├── cobra
├── .gitignore
├── .mailmap
├── .travis.yml
├── LICENSE.txt
├── README.md
├── args.go
├── bash_completions.go
├── bash_completions.md
├── cobra.go
├── cobra
│ └── cmd
│ │ ├── license_agpl.go
│ │ ├── license_apache_2.go
│ │ ├── license_bsd_clause_2.go
│ │ ├── license_bsd_clause_3.go
│ │ ├── license_gpl_2.go
│ │ ├── license_gpl_3.go
│ │ ├── license_lgpl.go
│ │ ├── license_mit.go
│ │ ├── licenses.go
│ │ └── testdata
│ │ └── LICENSE.golden
├── command.go
├── command_notwin.go
├── command_win.go
└── zsh_completions.go
└── pflag
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── bool.go
├── bool_slice.go
├── count.go
├── duration.go
├── flag.go
├── float32.go
├── float64.go
├── golangflag.go
├── int.go
├── int32.go
├── int64.go
├── int8.go
├── int_slice.go
├── ip.go
├── ip_slice.go
├── ipmask.go
├── ipnet.go
├── string.go
├── string_array.go
├── string_slice.go
├── uint.go
├── uint16.go
├── uint32.go
├── uint64.go
├── uint8.go
└── uint_slice.go
/.gitignore:
--------------------------------------------------------------------------------
1 | debug
2 | *.sql
3 | .vscode/
4 | local*
5 | build-bin.sh
6 | dist
7 | graphqlator-pkg.json
8 |
--------------------------------------------------------------------------------
/.goreleaser.yml:
--------------------------------------------------------------------------------
1 | # .goreleaser.yml
2 | # Build customization
3 | builds:
4 | - binary: graphqlator
5 | goos:
6 | - windows
7 | - darwin
8 | - linux
9 | goarch:
10 | - amd64
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | after_success:
4 | - test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | This is my first open source project. For now the contributing guidelines will be loose and we'll develop it as we go.
4 |
5 |
6 | ## Contributing to the Contributing Guide
7 |
8 | If there is a good practice that anyone wants to add to the contributing guide for the sustainability of the project then by all means open an issue and we will have an open discussion.
9 |
10 |
11 | # Pull Requests
12 |
13 | Make sure to have tests up to date. Please include any environmental setup instructions.
14 |
15 | Currently I am the only reviewer. I will do my best to review within 1-2 weeks.
16 |
17 | ## Current Environment Setup
18 |
19 | The .travis.yml file contains the environment setup in terms of create the database schemas currently used.
20 |
21 | # Issues
22 |
23 | Open to any assistance in triaging and labelling issues. Hopefully we do not encounter too many problems/incidents.
24 |
25 | ## IMPORTANT
26 |
27 | Graphqlator tries to purely remain a CLI program. All the database introspection and code generation is done in the [Substance](https://github.com/ahmedalhulaibi/substance) package in [vendor](https://github.com/ahmedalhulaibi/graphqlator/tree/master/vendor/github.com/ahmedalhulaibi/substance).
28 |
29 | If an enhancement/issue is related to the generated code itself, it is likely related to [Substance](https://github.com/ahmedalhulaibi/substance). For the time being we will still accept issues and enhancement requests for [Substance](https://github.com/ahmedalhulaibi/substance) here. May need a way to duplicate the issues automatically and label them on the [Substance](https://github.com/ahmedalhulaibi/substance) project as coming from graphqlator.
30 |
31 | ## Bugs or Unexpected Behaviour
32 |
33 | Please write the steps to reproduce an issue. Make sure to include which database you are using in the title of the
34 |
35 | ## Enhancements
36 |
37 | No restrictions as of this writing on feature requests. When requesting an enhancement some use cases would be nice.
38 |
39 |
--------------------------------------------------------------------------------
/Gopkg.lock:
--------------------------------------------------------------------------------
1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2 |
3 |
4 | [[projects]]
5 | branch = "feature/gqlgen"
6 | name = "github.com/ahmedalhulaibi/substance"
7 | packages = [
8 | ".",
9 | "providers/mysqlsubstance",
10 | "providers/pgsqlsubstance",
11 | "providers/testsubstance",
12 | "substancegen",
13 | "substancegen/generators/gorm",
14 | "substancegen/generators/gostruct",
15 | "substancegen/generators/gqlschema",
16 | "substancegen/generators/graphqlgo"
17 | ]
18 | revision = "f0a209fc858c8ae867bc935a10820ede69eba4a6"
19 |
20 | [[projects]]
21 | name = "github.com/apex/log"
22 | packages = ["."]
23 | revision = "0296d6eb16bb28f8a0c55668affcf4876dc269be"
24 | version = "v1.0.0"
25 |
26 | [[projects]]
27 | name = "github.com/go-sql-driver/mysql"
28 | packages = ["."]
29 | revision = "a0583e0143b1624142adab07e0e97fe106d99561"
30 | version = "v1.3"
31 |
32 | [[projects]]
33 | name = "github.com/inconshreveable/mousetrap"
34 | packages = ["."]
35 | revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75"
36 | version = "v1.0"
37 |
38 | [[projects]]
39 | branch = "master"
40 | name = "github.com/jinzhu/inflection"
41 | packages = ["."]
42 | revision = "1c35d901db3da928c72a72d8458480cc9ade058f"
43 |
44 | [[projects]]
45 | branch = "master"
46 | name = "github.com/lib/pq"
47 | packages = [
48 | ".",
49 | "oid"
50 | ]
51 | revision = "88edab0803230a3898347e77b474f8c1820a1f20"
52 |
53 | [[projects]]
54 | name = "github.com/pkg/errors"
55 | packages = ["."]
56 | revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
57 | version = "v0.8.0"
58 |
59 | [[projects]]
60 | name = "github.com/spf13/cobra"
61 | packages = ["."]
62 | revision = "7b2c5ac9fc04fc5efafb60700713d4fa609b777b"
63 | version = "v0.0.1"
64 |
65 | [[projects]]
66 | name = "github.com/spf13/pflag"
67 | packages = ["."]
68 | revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66"
69 | version = "v1.0.0"
70 |
71 | [solve-meta]
72 | analyzer-name = "dep"
73 | analyzer-version = 1
74 | inputs-digest = "79ab68c39de52a117b705dec713d08d6271875f76f8e6d7e62180e29b2cfda72"
75 | solver-name = "gps-cdcl"
76 | solver-version = 1
77 |
--------------------------------------------------------------------------------
/Gopkg.toml:
--------------------------------------------------------------------------------
1 | # Gopkg.toml example
2 | #
3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4 | # for detailed Gopkg.toml documentation.
5 | #
6 | # required = ["github.com/user/thing/cmd/thing"]
7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8 | #
9 | # [[constraint]]
10 | # name = "github.com/user/project"
11 | # version = "1.0.0"
12 | #
13 | # [[constraint]]
14 | # name = "github.com/user/project2"
15 | # branch = "dev"
16 | # source = "github.com/myfork/project2"
17 | #
18 | # [[override]]
19 | # name = "github.com/x/y"
20 | # version = "2.4.0"
21 | #
22 | # [prune]
23 | # non-go = false
24 | # go-tests = true
25 | # unused-packages = true
26 |
27 | required = ["github.com/go-sql-driver/mysql","github.com/lib/pq"]
28 |
29 | [[constraint]]
30 | branch = "feature/gqlgen"
31 | name = "github.com/ahmedalhulaibi/substance"
32 |
33 | [[constraint]]
34 | name = "github.com/go-sql-driver/mysql"
35 | version = "1.3.0"
36 |
37 | [[constraint]]
38 | branch = "master"
39 | name = "github.com/lib/pq"
40 |
41 | [[constraint]]
42 | name = "github.com/spf13/cobra"
43 | version = "0.0.1"
44 |
45 | [prune]
46 | go-tests = true
47 | unused-packages = true
48 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Ahmed Al-Hulaibi
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Graphqlator CLI
2 | __*This project is a WIP.*__
3 | # Master branch is currently unstable.
4 |
5 | Graphqlator takes your existing database schema and generates code for a GraphQL-Go server. Type 'graphqlator help' to see usage.
6 |
7 | ## Status
8 |
9 | | Build | Report card |
10 | | :-------------------------------: | :-----------------------------------: |
11 | | [![Build][build-badge]][build-link] | [![Report card][rc-badge]][rc-link] |
12 |
13 | [build-badge]: https://travis-ci.org/ahmedalhulaibi/graphqlator.svg?branch=master "Travis-CI build status"
14 | [build-link]: https://travis-ci.org/ahmedalhulaibi/graphqlator "Travis-CI build status link"
15 | [rc-badge]: https://goreportcard.com/badge/github.com/ahmedalhulaibi/graphqlator "Report card status"
16 | [rc-link]: https://goreportcard.com/report/github.com/ahmedalhulaibi/graphqlator "Report card status"
17 |
18 | ## Supported Data Stores:
19 |
20 | - mysql
21 | - mariadb
22 | - postgres
23 |
24 | ## Installation:
25 |
26 | ```
27 | go get github.com/ahmedalhulaibi/graphqlator
28 | ```
29 |
30 | Or Download prebuilt binaries from the [releases page](https://github.com/ahmedalhulaibi/go-graphqlator-cli/releases)
31 |
32 | ## Prerequisites
33 |
34 | [grahpql-go](https://github.com/graphql-go/graphql) - Generated code uses graphql-go
35 |
36 | [GORM](https://github.com/jinzhu/gorm) - Generated code uses GORM
37 |
38 | ## Usage
39 | ```
40 | graphqlator [flags]
41 | graphqlator [command]
42 | ```
43 | Available Commands:
44 | ```
45 | init Create a graphqlator-pkg.json file.
46 | describe Describe database or table
47 | generate Generate GraphQL-Go API implementation using grapqhlator-pkg.json.
48 | help Help about any command
49 | version Print the version number of Graphqlator
50 | ```
51 | Flags:
52 | -h, --help help for graphqlator
53 |
54 | Use "graphqlator [command] --help" for more information about a command.
55 |
56 | ## Example Usage:
57 |
58 | Please visit the [graphqlator website](https://ahmedalhulaibi.github.io/graphqlator-website/) for a short tutorial.
59 |
60 | # External Libraries Used
61 | [goreturns](https://github.com/sqs/goreturns) - Generator uses goreturns to remove unnecessary generated imports
62 |
63 | [Substance](https://github.com/ahmedalhulaibi/substance) - This library is used to introspect on the database information schema and generate the graphql-go code.
64 |
65 | [grahpql-go](https://github.com/graphql-go/graphql) - The generated code is using this implementation of GraphQL in Go.
66 |
67 | [GORM](https://github.com/jinzhu/gorm) - The generated code is using GORM.
68 |
69 |
--------------------------------------------------------------------------------
/cmd/configType.go:
--------------------------------------------------------------------------------
1 | package cmd
2 |
3 | /*gqlpackage struct to read in graphqlator-pkg.json*/
4 | type gqlpackage struct {
5 | ProjectName string `json:"project_name"`
6 | DatabaseType string `json:"database_type"`
7 | ConnectionString string `json:"connection_string"`
8 | TableNames []string `json:"table_names"`
9 | GitRepo string `json:"git_repo"`
10 | GenMode string `json:"gen_mode"`
11 | }
12 |
--------------------------------------------------------------------------------
/cmd/describe.go:
--------------------------------------------------------------------------------
1 | package cmd
2 |
3 | import (
4 | "fmt"
5 |
6 | "github.com/ahmedalhulaibi/substance"
7 | "github.com/spf13/cobra"
8 | )
9 |
10 | func init() {
11 | RootCmd.AddCommand(describe)
12 | }
13 |
14 | var describe = &cobra.Command{
15 | Use: "describe [database type] [connection string] [table names...]",
16 | Short: "List database tables or describe columns of table(s)",
17 | Long: `List database tables or describe columns of table(s). If no table names given, it will list tables in database. If table names supplied, the columns of the tables will be described.`,
18 | Args: cobra.MinimumNArgs(2),
19 | Run: func(cmd *cobra.Command, args []string) {
20 | if len(args) > 2 {
21 | describleTable(args[0], args[1], args[2:len(args)])
22 | } else {
23 | describeDatabase(args[0], args[1])
24 | }
25 | },
26 | }
27 |
28 | func describeDatabase(dbType string, connectionString string) {
29 | results, err := substance.DescribeDatabase(dbType, connectionString)
30 | if err != nil {
31 | panic(err)
32 | }
33 | if len(results) > 0 {
34 | fmt.Println("Database: ", results[0].DatabaseName)
35 | }
36 | for _, result := range results {
37 | fmt.Printf("Table: %s\n", result.TableName)
38 | }
39 | fmt.Println("=====================")
40 | }
41 |
42 | func describleTable(dbType string, connectionString string, tableNames []string) {
43 | tableDesc := []substance.ColumnDescription{}
44 | for _, tableName := range tableNames {
45 | _results, _ := substance.DescribeTable(dbType, connectionString, tableName)
46 | tableDesc = append(tableDesc, _results...)
47 | }
48 | for _, colDesc := range tableDesc {
49 | //fmt.Println(colDesc)
50 | fmt.Println("Table Name:\t", colDesc.TableName)
51 | fmt.Println("Property Name:\t", colDesc.PropertyName)
52 | fmt.Println("Property Type:\t", colDesc.PropertyType)
53 | fmt.Println("Key Type:\t", colDesc.KeyType)
54 | fmt.Println("Nullable:\t", colDesc.Nullable)
55 | fmt.Println("------------------------")
56 | }
57 | fmt.Println("=====================")
58 | relationshipDesc := []substance.ColumnRelationship{}
59 |
60 | for _, tableName := range tableNames {
61 | _results, _ := substance.DescribeTableRelationship(dbType, connectionString, tableName)
62 | relationshipDesc = append(relationshipDesc, _results...)
63 | }
64 | for _, colRel := range relationshipDesc {
65 | //fmt.Println(colRel)
66 | fmt.Println("Table Name:\t", colRel.TableName)
67 | fmt.Println("Column Name:\t", colRel.ColumnName)
68 | fmt.Println("Ref Table Name:\t", colRel.ReferenceTableName)
69 | fmt.Println("Ref Col Name:\t", colRel.ReferenceColumnName)
70 | }
71 | fmt.Println("=====================")
72 | contraintDesc := []substance.ColumnConstraint{}
73 |
74 | for _, tableName := range tableNames {
75 | _results, _ := substance.DescribeTableConstraints(dbType, connectionString, tableName)
76 | contraintDesc = append(contraintDesc, _results...)
77 | }
78 | for _, colCon := range contraintDesc {
79 | //fmt.Println(colCon)
80 | fmt.Println("Table Name:\t", colCon.TableName)
81 | fmt.Println("Column Name:\t", colCon.ColumnName)
82 | fmt.Println("Constraint:\t", colCon.ConstraintType)
83 | }
84 | fmt.Println("=====================")
85 | }
86 |
--------------------------------------------------------------------------------
/cmd/init.go:
--------------------------------------------------------------------------------
1 | package cmd
2 |
3 | import (
4 | "bufio"
5 | "encoding/json"
6 | "fmt"
7 | "os"
8 | "strings"
9 |
10 | "github.com/spf13/cobra"
11 | )
12 |
13 | func init() {
14 | RootCmd.AddCommand(initCmd)
15 | }
16 |
17 | func check(e error, message string) {
18 | if e != nil {
19 | fmt.Println(message)
20 | fmt.Println(e.Error())
21 | panic(e)
22 | }
23 | }
24 |
25 | var initCmd = &cobra.Command{
26 | Use: "init [project-name]",
27 | Short: "Generate graphqlator config file.",
28 | Long: `Walks you through the generation of a graphqlator config file.`,
29 | Args: cobra.MaximumNArgs(1),
30 | Run: func(cmd *cobra.Command, args []string) {
31 | f, err := os.Open("graphqlator-pkg.json")
32 | if err == nil {
33 | check(fmt.Errorf(""), "graphqlator-pkg.json File already exists")
34 | }
35 |
36 | f, err = os.Create("graphqlator-pkg.json")
37 | defer f.Close()
38 | check(err, "Failed to create file.")
39 |
40 | reader := bufio.NewReader(os.Stdin)
41 |
42 | newGqlPackage := gqlpackage{}
43 |
44 | if len(args) > 0 {
45 | newGqlPackage.ProjectName = args[0]
46 | } else {
47 | fmt.Printf("Input project name (enter to continue): ")
48 | projectName, err := reader.ReadString('\n')
49 | check(err, "Problem reading input project name")
50 | projectName = strings.Replace(projectName, "\n", "", -1)
51 | projectName = strings.Replace(projectName, " ", "-", -1)
52 | newGqlPackage.ProjectName = projectName
53 | }
54 |
55 | //input database_type
56 | {
57 | fmt.Printf("Input database type e.g. mysql (enter to continue): ")
58 | dbType, err := reader.ReadString('\n')
59 | check(err, "Problem reading database type")
60 | dbType = strings.Replace(dbType, "\n", "", -1)
61 | newGqlPackage.DatabaseType = strings.ToLower(dbType)
62 | }
63 |
64 | //input connection_string
65 | {
66 | fmt.Printf(`Input Database Connection String
67 | MySql Example: username:password@tcp(localhost:3306)/schemaname
68 | Postgresql Example: postgres://username:password@localhost:5432/dbname
69 | Input database connection string (enter to continue): `)
70 | connString, err := reader.ReadString('\n')
71 | check(err, "Problem reading connection string")
72 | connString = strings.Replace(connString, "\n", "", -1)
73 | newGqlPackage.ConnectionString = strings.ToLower(connString)
74 | }
75 |
76 | //input git_repo link
77 | {
78 | fmt.Printf("Input git repo url (enter to continue): ")
79 | gitRepo, err := reader.ReadString('\n')
80 | check(err, "Problem reading git repo")
81 | gitRepo = strings.Replace(gitRepo, "\n", "", -1)
82 | newGqlPackage.GitRepo = gitRepo
83 | }
84 |
85 | //input table_names
86 | {
87 | fmt.Println("Input table names - Must be EXACT spelling and case (enter without input to skip)")
88 | tableNames := []string{}
89 | i := 1
90 | for {
91 | fmt.Printf("Table #%d : ", i)
92 | tableName, err := reader.ReadString('\n')
93 | check(err, "Problem reading table name")
94 | tableName = strings.Replace(tableName, "\n", "", -1)
95 | tableName = strings.Replace(tableName, " ", "", -1)
96 | if tableName != "" {
97 | tableNames = append(tableNames, tableName)
98 | } else {
99 | break
100 | }
101 | i++
102 | }
103 | newGqlPackage.TableNames = tableNames
104 | }
105 |
106 | {
107 | genMode := "graphql-go"
108 | //fmt.Println("Which graphql implementation will you be using? gqlgen or graphql-go?")
109 | //fmt.Println("gqlgen - https://github.com/vektah/gqlgen")
110 | //fmt.Println("graphql-go - https://github.com/graphql-go/graphql")
111 | //genMode, err := reader.ReadString('\n')
112 | //
113 | //check(err, "Problem reading gen mode")
114 | //genMode = strings.Replace(genMode, "\n", "", -1)
115 | newGqlPackage.GenMode = genMode
116 | }
117 |
118 | newGqlPackageContent, err := json.MarshalIndent(newGqlPackage, "", "\t")
119 | check(err, "Failed to encode JSON to byte string")
120 | f.Write(newGqlPackageContent)
121 |
122 | },
123 | }
124 |
--------------------------------------------------------------------------------
/cmd/root.go:
--------------------------------------------------------------------------------
1 | package cmd
2 |
3 | import (
4 | "fmt"
5 |
6 | "github.com/spf13/cobra"
7 | )
8 |
9 | var RootCmd = &cobra.Command{
10 | Use: "graphqlator",
11 | Short: "Graphqlator helps you generate a GraphQL type schema. Type 'graphqlator help' to see usage.",
12 | Long: `A command line tool that generates a GraphQL type schema from a MySQL database table schema. Complete documentation is available at https://github.com/ahmedalhulaibi/graphqlator-cli`,
13 | Run: func(cmd *cobra.Command, args []string) {
14 | // Do Stuff Here
15 | fmt.Println(cmd.Short)
16 | },
17 | }
18 |
--------------------------------------------------------------------------------
/cmd/version.go:
--------------------------------------------------------------------------------
1 | package cmd
2 |
3 | import (
4 | "fmt"
5 |
6 | "github.com/spf13/cobra"
7 | )
8 |
9 | func init() {
10 | RootCmd.AddCommand(versionCmd)
11 | }
12 |
13 | var versionCmd = &cobra.Command{
14 | Use: "version",
15 | Short: "Print the version number of Graphqlator",
16 | Long: `All software has versions. This is Graphqlators's`,
17 | Run: func(cmd *cobra.Command, args []string) {
18 | fmt.Printf("Graphqlator GraphQL Generator %s\n", versionNumber)
19 | },
20 | }
21 |
--------------------------------------------------------------------------------
/cmd/versionnumber.go:
--------------------------------------------------------------------------------
1 | package cmd
2 |
3 | var versionNumber = "v0.4.0"
4 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "os"
6 |
7 | "github.com/ahmedalhulaibi/graphqlator/cmd"
8 |
9 | _ "github.com/ahmedalhulaibi/substance/providers/mysqlsubstance"
10 | _ "github.com/ahmedalhulaibi/substance/providers/pgsqlsubstance"
11 | _ "github.com/ahmedalhulaibi/substance/providers/testsubstance"
12 | )
13 |
14 | func main() {
15 | if err := cmd.RootCmd.Execute(); err != nil {
16 | fmt.Println(err)
17 | os.Exit(1)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/post-commit.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | newtag=$(grep -Po 'v[0-9]+\.[0-9]+\.[0-9]+\-?([a-z]*)?' cmd/versionnumber.go)
4 | git tag $newtag
--------------------------------------------------------------------------------
/setup-local-hooks.sh:
--------------------------------------------------------------------------------
1 | cp post-commit.sh ./.git/hooks/post-commit
2 | chmod +x ./.git/hooks/post-commit
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode/*
2 | vendor/*
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | services:
4 | - mysql
5 | - postgresql
6 | env:
7 | - SUBSTANCE_MYSQL="root@tcp(127.0.0.1:3306)/delivery" SUBSTANCE_PGSQL="postgres://travis_test:password@127.0.0.1:5432/postgres"
8 | before_install:
9 | - mysql -e 'CREATE DATABASE delivery;'
10 | - mysql -e 'use delivery; CREATE TABLE Persons (ID int PRIMARY KEY,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE Orders (OrderID int UNIQUE NOT NULL,OrderNumber int NOT NULL,PersonID int DEFAULT NULL,PRIMARY KEY (OrderID),FOREIGN KEY (PersonID) REFERENCES Persons(ID));CREATE TABLE AntiOrders (AntiOrderID int UNIQUE NOT NULL,AntiOrderNumber int NOT NULL,PersonID int UNIQUE DEFAULT NULL,PRIMARY KEY (AntiOrderID),FOREIGN KEY (PersonID) REFERENCES Persons(ID));'
11 | - psql -c "CREATE USER travis_test WITH PASSWORD 'password';" -U postgres
12 | - psql -c "CREATE TABLE Persons (ID int PRIMARY KEY,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE Orders (OrderID int UNIQUE NOT NULL,OrderNumber int NOT NULL,PersonID int DEFAULT NULL,PRIMARY KEY (OrderID),FOREIGN KEY (PersonID) REFERENCES Persons(ID));CREATE TABLE AntiOrders (AntiOrderID int UNIQUE NOT NULL,AntiOrderNumber int NOT NULL,PersonID int UNIQUE DEFAULT NULL,PRIMARY KEY (AntiOrderID),FOREIGN KEY (PersonID) REFERENCES Persons(ID));" -U postgres
13 | - psql -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO travis_test;" -U postgres
14 |
15 | script:
16 | - go test -v ./providers/testsubstance/ -coverprofile=coverage.txt -covermode=atomic
17 | - bash <(curl -s https://codecov.io/bash)
18 | - go test -v ./providers/mysqlsubstance/ -coverprofile=coverage.txt -covermode=atomic
19 | - bash <(curl -s https://codecov.io/bash)
20 | - go test -v ./providers/pgsqlsubstance/ -coverprofile=coverage.txt -covermode=atomic
21 | - bash <(curl -s https://codecov.io/bash)
22 | - go test -v ./substancegen/ -coverprofile=coverage.txt -covermode=atomic
23 | - bash <(curl -s https://codecov.io/bash)
24 | - go test -v ./substancegen/generators/gorm/ -coverprofile=coverage.txt -covermode=atomic
25 | - bash <(curl -s https://codecov.io/bash)
26 | - go test -v ./substancegen/generators/gostruct/ -coverprofile=coverage.txt -covermode=atomic
27 | - bash <(curl -s https://codecov.io/bash)
28 | - go test -v ./substancegen/generators/graphqlgo/ -coverprofile=coverage.txt -covermode=atomic
29 | - bash <(curl -s https://codecov.io/bash)
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | This is my first open source project. For now the contributing guidelines will be loose and we'll develop it as we go.
4 |
5 |
6 | ## Contributing to the Contributing Guide
7 |
8 | If there is a good practice that anyone wants to add to the contributing guide for the sustainability of the project then by all means open an issue and we will have an open discussion.
9 |
10 |
11 | # Pull Requests
12 |
13 | Make sure to have tests up to date. Please include any environmental setup instructions.
14 |
15 | Currently I am the only reviewer. I will do my best to review within 1-2 weeks.
16 |
17 | ## Environment Setup
18 |
19 | Install [docker](https://docs.docker.com/install/) and [docker-compose](https://docs.docker.com/compose/install/)
20 |
21 | Run the local hooks setup script if you want your code tested locally after each commit. The commits will be aborted if the `go test ./...` fails. The pre-commit script will also start the containers if required and export the required environment variable:
22 | ```bash
23 | . setupScripts/setup-local-hooks.sh
24 | ```
25 |
26 | Run [start-sql-containers.sh](https://github.com/ahmedalhulaibi/substance/blob/feature/gqlgen/setupScripts/setup-local-hooks.sh). This script will start postgres and mysql containers described in [docker-compose.yml](https://github.com/ahmedalhulaibi/substance/blob/feature/gqlgen/docker-compose.yml) and setup two environment variables
27 | ```bash
28 | $ . setupScripts/start-sql-containers.sh
29 | $ echo $SUBSTANCE_MYSQL
30 | root@tcp(172.19.0.3:3306)/delivery
31 | $ echo $SUBSTANCE_PGSQL
32 | postgres://travis_test:password@172.19.0.2:5432/postgres?sslmode=disable
33 | ```
34 |
35 | # Issues
36 |
37 | Open to any assistance in triaging and labelling issues. Hopefully we do not encounter too many problems/incidents.
38 |
39 | ## Bugs or Unexpected Behaviour
40 |
41 | Please write the steps to reproduce an issue. Make sure to include which database you are using in the title of the
42 |
43 | ## Enhancements
44 |
45 | No restrictions as of this writing on feature requests. When requesting an enhancement some use cases would be nice.
46 |
47 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/Gopkg.lock:
--------------------------------------------------------------------------------
1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2 |
3 |
4 | [[projects]]
5 | name = "github.com/apex/log"
6 | packages = ["."]
7 | revision = "0296d6eb16bb28f8a0c55668affcf4876dc269be"
8 | version = "v1.0.0"
9 |
10 | [[projects]]
11 | name = "github.com/go-sql-driver/mysql"
12 | packages = ["."]
13 | revision = "a0583e0143b1624142adab07e0e97fe106d99561"
14 | version = "v1.3"
15 |
16 | [[projects]]
17 | branch = "master"
18 | name = "github.com/jinzhu/inflection"
19 | packages = ["."]
20 | revision = "1c35d901db3da928c72a72d8458480cc9ade058f"
21 |
22 | [[projects]]
23 | branch = "master"
24 | name = "github.com/lib/pq"
25 | packages = [
26 | ".",
27 | "oid"
28 | ]
29 | revision = "88edab0803230a3898347e77b474f8c1820a1f20"
30 |
31 | [[projects]]
32 | name = "github.com/pkg/errors"
33 | packages = ["."]
34 | revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
35 | version = "v0.8.0"
36 |
37 | [solve-meta]
38 | analyzer-name = "dep"
39 | analyzer-version = 1
40 | inputs-digest = "bc6c416160e882888041a01c6cc1baa6e6fc6ead7423aad276a6583e0db8980a"
41 | solver-name = "gps-cdcl"
42 | solver-version = 1
43 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/Gopkg.toml:
--------------------------------------------------------------------------------
1 | # Gopkg.toml example
2 | #
3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4 | # for detailed Gopkg.toml documentation.
5 | #
6 | # required = ["github.com/user/thing/cmd/thing"]
7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8 | #
9 | # [[constraint]]
10 | # name = "github.com/user/project"
11 | # version = "1.0.0"
12 | #
13 | # [[constraint]]
14 | # name = "github.com/user/project2"
15 | # branch = "dev"
16 | # source = "github.com/myfork/project2"
17 | #
18 | # [[override]]
19 | # name = "github.com/x/y"
20 | # version = "2.4.0"
21 | #
22 | # [prune]
23 | # non-go = false
24 | # go-tests = true
25 | # unused-packages = true
26 |
27 |
28 | [[constraint]]
29 | name = "github.com/go-sql-driver/mysql"
30 | version = "1.3.0"
31 |
32 | [[constraint]]
33 | branch = "master"
34 | name = "github.com/lib/pq"
35 |
36 | [prune]
37 | go-tests = true
38 | unused-packages = true
39 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Ahmed Al-Hulaibi
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 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/README.md:
--------------------------------------------------------------------------------
1 | # substance
2 |
3 | _This project is a work in progress. This means the master branch is unstable and broken builds may occur._
4 |
5 | Substance provides an interface for implementations extract schema data from a data provider (mysql, postgres, etc.).
6 |
7 | SubstanceGen provides an interface for implementations to use data produced by Substance to generate code.
8 |
9 | ## Status
10 |
11 | | Build | Code coverage | Report card | Codebeat |
12 | | :-------------------------------: | :-------------------------------------: | :-----------------------------------: | :-----------------------------------: |
13 | | [![Build][build-badge]][build-link] | [![Code coverage][cov-badge]][cov-link] | [![Report card][rc-badge]][rc-link] | [![Codebeat][codebeat-badge]][codebeat-link] |
14 |
15 | [build-badge]: https://travis-ci.org/ahmedalhulaibi/substance.svg?branch=master "Travis-CI build status"
16 | [build-link]: https://travis-ci.org/ahmedalhulaibi/substance "Travis-CI build status link"
17 | [cov-badge]: https://codecov.io/gh/ahmedalhulaibi/substance/branch/master/graph/badge.svg "Code coverage status"
18 | [cov-link]: https://codecov.io/gh/ahmedalhulaibi/substance "Code coverage status"
19 | [rc-badge]: https://goreportcard.com/badge/github.com/ahmedalhulaibi/substance "Report card status"
20 | [rc-link]: https://goreportcard.com/report/github.com/ahmedalhulaibi/substance "Report card status"
21 | [codebeat-badge]: https://codebeat.co/badges/490b4031-5ae5-4fb5-bc46-b2c8802b944f
22 | [codebeat-link]: https://codebeat.co/projects/github-com-ahmedalhulaibi-substance-master
23 |
24 | ## Substance Supported Data Providers
25 |
26 | - MySQL/MariaDB
27 | - Postgres
28 | - JSON _planned_
29 |
30 | ## SubstanceGen Code Generators
31 |
32 | - GraphQL-Go Server
33 | - GoStructs
34 | - GORM CRUD functions_WIP_
35 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | pgsqldbsubstance:
4 | restart: always
5 | container_name: pgsqldbsubstance
6 | image: postgres
7 | environment:
8 | - POSTGRES_USER=travis_test
9 | - POSTGRES_PASSWORD=password
10 | - POSTGRES_DB=postgres
11 | ports:
12 | - "5432:5432"
13 | mysqldbsubstance:
14 | restart: always
15 | container_name: mysqldbsubstance
16 | image: mysql
17 | environment:
18 | - MYSQL_DATABASE=delivery
19 | - MYSQL_ALLOW_EMPTY_PASSWORD=yes
20 | ports:
21 | - "3306:3306"
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/providers/mysqlsubstance/mysqlDataTypeMap.go:
--------------------------------------------------------------------------------
1 | package mysqlsubstance
2 |
3 | var regexDataTypePatterns = make(map[string]string)
4 |
5 | func init() {
6 | regexDataTypePatterns["bit.*"] = "int64"
7 | regexDataTypePatterns["bool.*|tinyint\\(1\\)"] = "bool"
8 | regexDataTypePatterns["tinyint.*"] = "int8"
9 | regexDataTypePatterns["unsigned\\stinyint.*"] = "uint8"
10 | regexDataTypePatterns["smallint.*"] = "int16"
11 | regexDataTypePatterns["unsigned\\ssmallint.*"] = "uint16"
12 | regexDataTypePatterns["(mediumint.*|int.*)"] = "int32"
13 | regexDataTypePatterns["unsigned\\s(mediumint.*|int.*)"] = "uint32"
14 | regexDataTypePatterns["bigint.*"] = "int64"
15 | regexDataTypePatterns["unsigned\\sbigint.*"] = "uint64"
16 | regexDataTypePatterns["(unsigned\\s){0,1}(double.*|float.*|dec.*|numeric.*)"] = "float64"
17 | regexDataTypePatterns["varchar.*|date.*|time.*|year.*|char.*|.*text.*|enum.*|set.*|.*blob.*|.*binary.*|json|jsonb"] = "string"
18 | }
19 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/providers/mysqlsubstance/mysqlQueries.go:
--------------------------------------------------------------------------------
1 | package mysqlsubstance
2 |
3 | /*GetCurrentDatabaseNameQuery used in GetCurrentDatabaseNamefunc*/
4 | var GetCurrentDatabaseNameQuery = `SELECT DATABASE()`
5 |
6 | /*DescribeDatabaseQuery used in DescribeDatabaseFunc*/
7 | var DescribeDatabaseQuery = `SHOW TABLES`
8 |
9 | /*DescribeTableQuery used in DescribeTableFunc*/
10 | var DescribeTableQuery = `DESCRIBE %s`
11 |
12 | /*DescribeTableRelationshipQuery used in DescribeTableRelationshipFunc*/
13 | var DescribeTableRelationshipQuery = `SELECT
14 | TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME
15 | FROM
16 | INFORMATION_SCHEMA.KEY_COLUMN_USAGE
17 | WHERE
18 | REFERENCED_TABLE_SCHEMA = '%s' AND
19 | REFERENCED_TABLE_NAME = ?;`
20 |
21 | /*DescribeTableConstraintsQuery used in DescribeTableConstraintsFunc*/
22 | var DescribeTableConstraintsQuery = `SELECT DISTINCT kcu.column_name as 'Column', tc.constraint_type as 'Constraint'
23 | FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE as kcu
24 | JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS as tc on tc.constraint_name = kcu.constraint_name
25 | WHERE kcu.table_name = ?
26 | order by kcu.column_name, tc.constraint_type;`
27 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/providers/pgsqlsubstance/pgsqlDataTypeMap.go:
--------------------------------------------------------------------------------
1 | package pgsqlsubstance
2 |
3 | var regexDataTypePatterns = make(map[string]string)
4 |
5 | func init() {
6 | regexDataTypePatterns["bit.*"] = "int64"
7 | regexDataTypePatterns["bool.*|tinyint\\(1\\)"] = "bool"
8 | regexDataTypePatterns["tinyint.*"] = "int8"
9 | regexDataTypePatterns["unsigned\\stinyint.*"] = "uint8"
10 | regexDataTypePatterns["smallint.*"] = "int16"
11 | regexDataTypePatterns["unsigned\\ssmallint.*"] = "uint16"
12 | regexDataTypePatterns["(mediumint.*|int.*)"] = "int32"
13 | regexDataTypePatterns["unsigned\\s(mediumint.*|int.*)"] = "uint32"
14 | regexDataTypePatterns["bigint.*"] = "int64"
15 | regexDataTypePatterns["unsigned\\sbigint.*"] = "uint64"
16 | regexDataTypePatterns["(unsigned\\s){0,1}(double.*|float.*|dec.*|real|numeric.*)"] = "float64"
17 | regexDataTypePatterns["varchar.*|date.*|time.*|year.*|char.*|.*text.*|enum.*|set.*|.*blob.*|.*binary.*|point|jsonb|json"] = "string"
18 | }
19 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/providers/pgsqlsubstance/pgsqlQueries.go:
--------------------------------------------------------------------------------
1 | package pgsqlsubstance
2 |
3 | /*GetCurrentDatabaseNameQuery used in GetCurrentDatabaseNamefunc*/
4 | var GetCurrentDatabaseNameQuery = `select current_database();`
5 |
6 | /*DescribeDatabaseQuery used in DescribeDatabaseFunc*/
7 | var DescribeDatabaseQuery = `select * from pg_catalog.pg_tables where schemaname not in ('pg_catalog','information_schema');`
8 |
9 | /*DescribeTableQuery used in DescribeTableFunc*/
10 | var DescribeTableQuery = `select
11 | att.attrelid as "classId",
12 | class.relname as "Table",
13 | att.attname as "Field",
14 | dsc.description as "description",
15 | typ.typname as "Type",
16 | att.attnum as "num",
17 | att.attnotnull as "isNotNull",
18 | att.atthasdef as "hasDefault"
19 | from
20 | pg_catalog.pg_attribute as att
21 | left join pg_catalog.pg_description as dsc on dsc.objoid = att.attrelid
22 | and dsc.objsubid = att.attnum
23 | left join pg_type as typ on typ.oid = att.atttypid
24 | left join pg_catalog.pg_class as class on class.oid = att.attrelid
25 | where
26 | att.attrelid in (
27 | select
28 | rel.oid as "id"
29 | from
30 | pg_catalog.pg_class as rel
31 | left join pg_catalog.pg_description as dsc on dsc.objoid = rel.oid
32 | and dsc.objsubid = 0
33 | where
34 | class.relname = $1
35 | and rel.relpersistence in ('p')
36 | and rel.relkind in ('r', 'v', 'm', 'c', 'f')
37 | )
38 | and att.attnum > 0
39 | and not att.attisdropped
40 | order by
41 | att.attrelid,
42 | att.attnum;`
43 |
44 | /*DescribeTableRelationshipQuery used in DescribeTableRelationshipFunc*/
45 | var DescribeTableRelationshipQuery = `select
46 | tc.table_name as "table_name",
47 | kcu.column_name as "column",
48 | class.relname as "ref_table",
49 | con.confkey as "ref_columnNum"
50 | from
51 | pg_catalog.pg_constraint as con
52 | left join information_schema.table_constraints as tc on tc.constraint_name = con.conname
53 | left join information_schema.key_column_usage as kcu on kcu.constraint_name = con.conname
54 | left join pg_catalog.pg_class as class on class.oid = con.confrelid
55 | where
56 | tc.table_name = $1 and
57 | con.contype = 'f'
58 | ;`
59 |
60 | /*DescribeTableConstraintsQuery used in DescribeTableConstraintsFunc*/
61 | var DescribeTableConstraintsQuery = `select distinct on (con.conrelid, con.conkey, con.confrelid, con.confkey)
62 | tc.table_name,
63 | kcu.column_name as "column",
64 | contype
65 | from
66 | pg_catalog.pg_constraint as con
67 | left join information_schema.table_constraints as tc on tc.constraint_name = con.conname
68 | left join information_schema.key_column_usage as kcu on kcu.constraint_name = con.conname
69 | left join pg_catalog.pg_class as class on class.oid = con.confrelid
70 | where
71 | tc.table_name = $1
72 | ;`
73 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/gostruct/gostruct.go:
--------------------------------------------------------------------------------
1 | package gostruct
2 |
3 | import (
4 | "bytes"
5 | "log"
6 | "text/template"
7 |
8 | "github.com/ahmedalhulaibi/substance/substancegen"
9 | )
10 |
11 | /*GenObjectTypeToStructFunc takes a GenObjectType and writes it to a buffer as a go struct*/
12 | func GenObjectTypeToStructFunc(genObjectTypes map[string]substancegen.GenObjectType, buff *bytes.Buffer) {
13 | gostructTemplate := "{{range $key, $value := . }}\ntype {{.Name}} struct { {{range .Properties}}\n\t{{.ScalarNameUpper}}\t{{if .IsList}}[]{{end}}{{.ScalarType}}\t`{{range $index, $element := .Tags}}{{$index}}:\"{{range $element}}{{.}}{{end}}\" {{end}}`{{end}}\n}\n{{end}}"
14 |
15 | tmpl := template.New("gostruct")
16 | tmpl, err := tmpl.Parse(gostructTemplate)
17 | if err != nil {
18 | log.Fatal("Parse: ", err)
19 | return
20 | }
21 | err1 := tmpl.Execute(buff, genObjectTypes)
22 | if err1 != nil {
23 | log.Fatal("Execute: ", err1)
24 | return
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/gqlschema/gqlschema.go:
--------------------------------------------------------------------------------
1 | package gqlschema
2 |
3 | import (
4 | "bytes"
5 | "html/template"
6 | "log"
7 |
8 | "github.com/ahmedalhulaibi/substance/substancegen"
9 | )
10 |
11 | var graphqlDataTypes map[string]string
12 |
13 | func init() {
14 | graphqlDataTypes = make(map[string]string)
15 | graphqlDataTypes["int"] = "Int"
16 | graphqlDataTypes["int8"] = "Int"
17 | graphqlDataTypes["int16"] = "Int"
18 | graphqlDataTypes["int32"] = "Int"
19 | graphqlDataTypes["int64"] = "Int"
20 | graphqlDataTypes["uint"] = "Int"
21 | graphqlDataTypes["uint8"] = "Int"
22 | graphqlDataTypes["uint16"] = "Int"
23 | graphqlDataTypes["uint32"] = "Int"
24 | graphqlDataTypes["uint64"] = "Int"
25 | graphqlDataTypes["byte"] = "Int"
26 | graphqlDataTypes["rune"] = "Int"
27 | graphqlDataTypes["bool"] = "Boolean"
28 | graphqlDataTypes["string"] = "String"
29 | graphqlDataTypes["float32"] = "Float"
30 | graphqlDataTypes["float64"] = "Float"
31 | }
32 |
33 | /*OutputGraphqlSchema Returns a buffer containing a GraphQL schema in the standard GraphQL schema syntax*/
34 | func OutputGraphqlSchema(gqlObjectTypes map[string]substancegen.GenObjectType) bytes.Buffer {
35 | var buff bytes.Buffer
36 | GenerateGraphqlSchemaTypes(gqlObjectTypes, &buff)
37 |
38 | return buff
39 | }
40 |
41 | /*GenerateGraphqlSchemaTypes generates graphql types in graphql sstandard syntax*/
42 | func GenerateGraphqlSchemaTypes(gqlObjectTypes map[string]substancegen.GenObjectType, buff *bytes.Buffer) {
43 | for _, object := range gqlObjectTypes {
44 | for _, propVal := range object.Properties {
45 | if propVal.IsObjectType {
46 | propVal.AltScalarType["gqlschema"] = propVal.ScalarNameUpper
47 | } else {
48 | propVal.AltScalarType["gqlschema"] = graphqlDataTypes[propVal.ScalarType]
49 | }
50 | }
51 | }
52 |
53 | tmpl := template.New("graphqlSchema")
54 | tmpl, err := tmpl.Parse(graphqlSchemaTypesTemplate)
55 | if err != nil {
56 | log.Fatal("Parse: ", err)
57 | return
58 | }
59 | //print schema
60 | err1 := tmpl.Execute(buff, gqlObjectTypes)
61 | if err1 != nil {
62 | log.Fatal("Execute: ", err1)
63 | return
64 | }
65 | }
66 |
67 | /*GenerateGraphqlQueries generates graphql queries and mutations in graphql standard syntax*/
68 | func GenerateGraphqlQueries(gqlObjectTypes map[string]substancegen.GenObjectType, buff *bytes.Buffer) {
69 | for _, object := range gqlObjectTypes {
70 | for _, propVal := range object.Properties {
71 | if propVal.IsObjectType {
72 | propVal.AltScalarType["gqlschema"] = propVal.ScalarNameUpper
73 | }
74 | propVal.AltScalarType["gqlschema"] = graphqlDataTypes[propVal.ScalarType]
75 | }
76 | }
77 |
78 | tmpl := template.New("graphql")
79 | tmpl, err := tmpl.Parse(graphqlSchemaTypesTemplate)
80 | if err != nil {
81 | log.Fatal("Parse: ", err)
82 | return
83 | }
84 | //print schema
85 | err1 := tmpl.Execute(buff, gqlObjectTypes)
86 | if err1 != nil {
87 | log.Fatal("Execute: ", err1)
88 | return
89 | }
90 | }
91 |
92 | /*GenerateGraphqlQueries generates graphql GET queries in graphql standard syntax*/
93 | func GenerateGraphqlGetQueries(gqlObjectTypes map[string]substancegen.GenObjectType, buff *bytes.Buffer) {
94 | for _, object := range gqlObjectTypes {
95 | for _, propVal := range object.Properties {
96 | if propVal.IsObjectType {
97 | propVal.AltScalarType["gqlschema"] = propVal.ScalarNameUpper
98 | }
99 | propVal.AltScalarType["gqlschema"] = graphqlDataTypes[propVal.ScalarType]
100 | }
101 | }
102 |
103 | tmpl := template.New("graphqlSchemaGet")
104 | tmpl, err := tmpl.Parse(graphqlSchemaGetQueriesTemplate)
105 | if err != nil {
106 | log.Fatal("Parse: ", err)
107 | return
108 | }
109 | //print schema
110 | err1 := tmpl.Execute(buff, gqlObjectTypes)
111 | if err1 != nil {
112 | log.Fatal("Execute: ", err1)
113 | return
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/gqlschema/gqlschema_templates.go:
--------------------------------------------------------------------------------
1 | package gqlschema
2 |
3 | var graphqlSchemaTypesTemplate = `{{range $key, $value := . }}type {{.Name}} { {{range .Properties}}
4 | {{.ScalarName}}: {{if .IsList}}[{{index .AltScalarType "gqlschema"}}]{{else}}{{index .AltScalarType "gqlschema"}}{{end}}{{if .Nullable}}{{else}}!{{end}}{{end}}
5 | }
6 | {{end}}`
7 |
8 | var graphqlSchemaQueriesTemplate = `{{range .}}{{end}}`
9 |
10 | var graphqlSchemaGetQueriesTemplate = `{{range $key, $value := . }}
11 | # {{.Name}} returns first {{.Name}} in database table
12 | {{.Name}}: {{.Name}}
13 | # Get{{.Name}} takes the properties of {{.Name}} as search parameters. It will return all {{.Name}} rows found that matches the search criteria. Null input paramters are valid.
14 | Get{{.Name}}({{range .Properties}}{{.ScalarName}}: {{if .IsList}}[{{index .AltScalarType "gqlschema"}}]{{else}}{{index .AltScalarType "gqlschema"}}{{end}}, {{end}}): [{{.Name}}]{{end}}
15 | `
16 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/substancegen/generators/graphqlgo/graphqlgo.go:
--------------------------------------------------------------------------------
1 | package graphqlgo
2 |
3 | import (
4 | "bytes"
5 |
6 | "github.com/ahmedalhulaibi/substance/substancegen"
7 | "github.com/ahmedalhulaibi/substance/substancegen/generators/gorm"
8 | "github.com/ahmedalhulaibi/substance/substancegen/generators/gostruct"
9 | )
10 |
11 | func init() {
12 | gqlPlugin := Gql{}
13 | gqlPlugin.GraphqlDataTypes = make(map[string]string)
14 | InitGraphqlDataTypes(&gqlPlugin)
15 | gqlPlugin.GraphqlDbTypeImports = make(map[string]string)
16 | gqlPlugin.GraphqlDbTypeImports["mysql"] = "\n\t\"github.com/jinzhu/gorm\"\n\t_ \"github.com/jinzhu/gorm/dialects/mysql\""
17 | gqlPlugin.GraphqlDbTypeImports["postgres"] = "\n\t\"github.com/jinzhu/gorm\"\n\t_ \"github.com/jinzhu/gorm/dialects/postgres\""
18 | substancegen.Register("graphql-go", gqlPlugin)
19 | }
20 |
21 | /*InitGraphqlDataTypes initializes gqlPlugin data for go to graphql-go type mapping*/
22 | func InitGraphqlDataTypes(gqlPlugin *Gql) {
23 | gqlPlugin.GraphqlDataTypes = make(map[string]string)
24 | gqlPlugin.GraphqlDataTypes["int"] = "graphql.Int"
25 | gqlPlugin.GraphqlDataTypes["int8"] = "graphql.Int"
26 | gqlPlugin.GraphqlDataTypes["int16"] = "graphql.Int"
27 | gqlPlugin.GraphqlDataTypes["int32"] = "graphql.Int"
28 | gqlPlugin.GraphqlDataTypes["int64"] = "graphql.Int"
29 | gqlPlugin.GraphqlDataTypes["uint"] = "graphql.Int"
30 | gqlPlugin.GraphqlDataTypes["uint8"] = "graphql.Int"
31 | gqlPlugin.GraphqlDataTypes["uint16"] = "graphql.Int"
32 | gqlPlugin.GraphqlDataTypes["uint32"] = "graphql.Int"
33 | gqlPlugin.GraphqlDataTypes["uint64"] = "graphql.Int"
34 | gqlPlugin.GraphqlDataTypes["byte"] = "graphql.Int"
35 | gqlPlugin.GraphqlDataTypes["rune"] = "graphql.Int"
36 | gqlPlugin.GraphqlDataTypes["bool"] = "graphql.Boolean"
37 | gqlPlugin.GraphqlDataTypes["string"] = "graphql.String"
38 | gqlPlugin.GraphqlDataTypes["float32"] = "graphql.Float"
39 | gqlPlugin.GraphqlDataTypes["float64"] = "graphql.Float"
40 | }
41 |
42 | /*Gql plugin struct implementation of substancegen Generator interface*/
43 | type Gql struct {
44 | Name string
45 | GraphqlDataTypes map[string]string
46 | GraphqlDbTypeGormFlag map[string]bool
47 | GraphqlDbTypeImports map[string]string
48 | }
49 |
50 | /*OutputCodeFunc returns a buffer with a graphql-go implementation in a single file*/
51 | func (g Gql) OutputCodeFunc(dbType string, connectionString string, gqlObjectTypes map[string]substancegen.GenObjectType) bytes.Buffer {
52 | var buff bytes.Buffer
53 |
54 | g.GenPackageImports(dbType, &buff)
55 | //print schema
56 | substancegen.AddJSONTagsToProperties(gqlObjectTypes)
57 | gostruct.GenObjectTypeToStructFunc(gqlObjectTypes, &buff)
58 | for _, value := range gqlObjectTypes {
59 | gorm.GenGormObjectTableNameOverrideFunc(value, &buff)
60 | }
61 | g.GenerateGraphqlGoTypesFunc(gqlObjectTypes, &buff)
62 | buff.WriteString(GraphqlGoExecuteQueryFunc)
63 | var graphqlFieldsBuff bytes.Buffer
64 | GenGraphqlGoFieldsFunc(gqlObjectTypes, &graphqlFieldsBuff)
65 | buff.Write(graphqlFieldsBuff.Bytes())
66 | GenGraphqlGoMainFunc(dbType, connectionString, gqlObjectTypes, &buff)
67 | return buff
68 | }
69 |
--------------------------------------------------------------------------------
/vendor/github.com/ahmedalhulaibi/substance/substancegen/genutil.go:
--------------------------------------------------------------------------------
1 | package substancegen
2 |
3 | import (
4 | "sort"
5 | )
6 |
7 | /*StringInSlice returns true if a string is an element within a slice*/
8 | func StringInSlice(searchVal string, list []string) bool {
9 | for _, val := range list {
10 | if val == searchVal {
11 | return true
12 | }
13 | }
14 | return false
15 | }
16 |
17 | /*AddJSONTagsToProperties adds json go tags to each property for each object*/
18 | func AddJSONTagsToProperties(gqlObjectTypes map[string]GenObjectType) {
19 |
20 | for _, value := range gqlObjectTypes {
21 | for _, propVal := range value.Properties {
22 | propVal.Tags["json"] = append(propVal.Tags["json"], propVal.ScalarName)
23 | }
24 | }
25 | }
26 |
27 | /*SearchForKeyColumnByKeyType returns a string containing the name of the column of a certain key type*/
28 | func SearchForKeyColumnByKeyType(gqlObjectType GenObjectType, searchKeyType string) string {
29 | keyColumn := ""
30 | //Loop through all properties in alphabetic order (key sorted)
31 | //This prevents different keys being identified across multiple runs using the same input data
32 | propKeys := make([]string, 0)
33 | for propKey := range gqlObjectType.Properties {
34 | propKeys = append(propKeys, propKey)
35 | }
36 | sort.Strings(propKeys)
37 | for _, propKey := range propKeys {
38 | propVal := gqlObjectType.Properties[propKey]
39 | if StringInSlice(searchKeyType, propVal.KeyType) {
40 | keyColumn = propVal.ScalarNameUpper
41 | break
42 | }
43 | }
44 | return keyColumn
45 | }
46 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/LICENSE:
--------------------------------------------------------------------------------
1 | (The MIT License)
2 |
3 | Copyright (c) 2015 TJ Holowaychuk <tj@tjholowaychuk.coma>
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | 'Software'), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/Makefile:
--------------------------------------------------------------------------------
1 |
2 | include github.com/tj/make/golang
3 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/Readme.md:
--------------------------------------------------------------------------------
1 |
2 | 
3 |
4 | Package log implements a simple structured logging API inspired by Logrus, designed with centralization in mind. Read more on [Medium](https://medium.com/@tjholowaychuk/apex-log-e8d9627f4a9a#.rav8yhkud).
5 |
6 | ## Handlers
7 |
8 | - __cli__ – human-friendly CLI output
9 | - __discard__ – discards all logs
10 | - __es__ – Elasticsearch handler
11 | - __graylog__ – Graylog handler
12 | - __json__ – JSON output handler
13 | - __kinesis__ – AWS Kinesis handler
14 | - __level__ – level filter handler
15 | - __logfmt__ – logfmt plain-text formatter
16 | - __memory__ – in-memory handler for tests
17 | - __multi__ – fan-out to multiple handlers
18 | - __papertrail__ – Papertrail handler
19 | - __text__ – human-friendly colored output
20 | - __delta__ – outputs the delta between log calls and spinner
21 |
22 | ---
23 |
24 | [](https://semaphoreci.com/tj/log)
25 | [](https://godoc.org/github.com/apex/log)
26 | 
27 | 
28 |
29 |
30 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/default.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | import (
4 | "bytes"
5 | "fmt"
6 | "log"
7 | "sort"
8 | )
9 |
10 | // field used for sorting.
11 | type field struct {
12 | Name string
13 | Value interface{}
14 | }
15 |
16 | // by sorts fields by name.
17 | type byName []field
18 |
19 | func (a byName) Len() int { return len(a) }
20 | func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
21 | func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name }
22 |
23 | // handleStdLog outpouts to the stlib log.
24 | func handleStdLog(e *Entry) error {
25 | level := levelNames[e.Level]
26 |
27 | var fields []field
28 |
29 | for k, v := range e.Fields {
30 | fields = append(fields, field{k, v})
31 | }
32 |
33 | sort.Sort(byName(fields))
34 |
35 | var b bytes.Buffer
36 | fmt.Fprintf(&b, "%5s %-25s", level, e.Message)
37 |
38 | for _, f := range fields {
39 | fmt.Fprintf(&b, " %s=%v", f.Name, f.Value)
40 | }
41 |
42 | log.Println(b.String())
43 |
44 | return nil
45 | }
46 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/doc.go:
--------------------------------------------------------------------------------
1 | /*
2 | Package log implements a simple structured logging API designed with few assumptions. Designed for
3 | centralized logging solutions such as Kinesis which require encoding and decoding before fanning-out
4 | to handlers.
5 |
6 | You may use this package with inline handlers, much like Logrus, however a centralized solution
7 | is recommended so that apps do not need to be re-deployed to add or remove logging service
8 | providers.
9 | */
10 | package log
11 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/interface.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | // Interface represents the API of both Logger and Entry.
4 | type Interface interface {
5 | WithFields(fields Fielder) *Entry
6 | WithField(key string, value interface{}) *Entry
7 | WithError(err error) *Entry
8 | Debug(msg string)
9 | Info(msg string)
10 | Warn(msg string)
11 | Error(msg string)
12 | Fatal(msg string)
13 | Debugf(msg string, v ...interface{})
14 | Infof(msg string, v ...interface{})
15 | Warnf(msg string, v ...interface{})
16 | Errorf(msg string, v ...interface{})
17 | Fatalf(msg string, v ...interface{})
18 | Trace(msg string) *Entry
19 | }
20 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/levels.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | import (
4 | "bytes"
5 | "errors"
6 | "strings"
7 | )
8 |
9 | // ErrInvalidLevel is returned if the severity level is invalid.
10 | var ErrInvalidLevel = errors.New("invalid level")
11 |
12 | // Level of severity.
13 | type Level int
14 |
15 | // Log levels.
16 | const (
17 | InvalidLevel Level = iota - 1
18 | DebugLevel
19 | InfoLevel
20 | WarnLevel
21 | ErrorLevel
22 | FatalLevel
23 | )
24 |
25 | var levelNames = [...]string{
26 | DebugLevel: "debug",
27 | InfoLevel: "info",
28 | WarnLevel: "warn",
29 | ErrorLevel: "error",
30 | FatalLevel: "fatal",
31 | }
32 |
33 | var levelStrings = map[string]Level{
34 | "debug": DebugLevel,
35 | "info": InfoLevel,
36 | "warn": WarnLevel,
37 | "warning": WarnLevel,
38 | "error": ErrorLevel,
39 | "fatal": FatalLevel,
40 | }
41 |
42 | // String implementation.
43 | func (l Level) String() string {
44 | return levelNames[l]
45 | }
46 |
47 | // MarshalJSON implementation.
48 | func (l Level) MarshalJSON() ([]byte, error) {
49 | return []byte(`"` + l.String() + `"`), nil
50 | }
51 |
52 | // UnmarshalJSON implementation.
53 | func (l *Level) UnmarshalJSON(b []byte) error {
54 | v, err := ParseLevel(string(bytes.Trim(b, `"`)))
55 | if err != nil {
56 | return err
57 | }
58 |
59 | *l = v
60 | return nil
61 | }
62 |
63 | // ParseLevel parses level string.
64 | func ParseLevel(s string) (Level, error) {
65 | l, ok := levelStrings[strings.ToLower(s)]
66 | if !ok {
67 | return InvalidLevel, ErrInvalidLevel
68 | }
69 |
70 | return l, nil
71 | }
72 |
73 | // MustParseLevel parses level string or panics.
74 | func MustParseLevel(s string) Level {
75 | l, err := ParseLevel(s)
76 | if err != nil {
77 | panic("invalid log level")
78 | }
79 |
80 | return l
81 | }
82 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/logger.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | import (
4 | stdlog "log"
5 | "sort"
6 | )
7 |
8 | // assert interface compliance.
9 | var _ Interface = (*Logger)(nil)
10 |
11 | // Fielder is an interface for providing fields to custom types.
12 | type Fielder interface {
13 | Fields() Fields
14 | }
15 |
16 | // Fields represents a map of entry level data used for structured logging.
17 | type Fields map[string]interface{}
18 |
19 | // Fields implements Fielder.
20 | func (f Fields) Fields() Fields {
21 | return f
22 | }
23 |
24 | // Get field value by name.
25 | func (f Fields) Get(name string) interface{} {
26 | return f[name]
27 | }
28 |
29 | // Names returns field names sorted.
30 | func (f Fields) Names() (v []string) {
31 | for k := range f {
32 | v = append(v, k)
33 | }
34 |
35 | sort.Strings(v)
36 | return
37 | }
38 |
39 | // The HandlerFunc type is an adapter to allow the use of ordinary functions as
40 | // log handlers. If f is a function with the appropriate signature,
41 | // HandlerFunc(f) is a Handler object that calls f.
42 | type HandlerFunc func(*Entry) error
43 |
44 | // HandleLog calls f(e).
45 | func (f HandlerFunc) HandleLog(e *Entry) error {
46 | return f(e)
47 | }
48 |
49 | // Handler is used to handle log events, outputting them to
50 | // stdio or sending them to remote services. See the "handlers"
51 | // directory for implementations.
52 | //
53 | // It is left up to Handlers to implement thread-safety.
54 | type Handler interface {
55 | HandleLog(*Entry) error
56 | }
57 |
58 | // Logger represents a logger with configurable Level and Handler.
59 | type Logger struct {
60 | Handler Handler
61 | Level Level
62 | }
63 |
64 | // WithFields returns a new entry with `fields` set.
65 | func (l *Logger) WithFields(fields Fielder) *Entry {
66 | return NewEntry(l).WithFields(fields.Fields())
67 | }
68 |
69 | // WithField returns a new entry with the `key` and `value` set.
70 | //
71 | // Note that the `key` should not have spaces in it - use camel
72 | // case or underscores
73 | func (l *Logger) WithField(key string, value interface{}) *Entry {
74 | return NewEntry(l).WithField(key, value)
75 | }
76 |
77 | // WithError returns a new entry with the "error" set to `err`.
78 | func (l *Logger) WithError(err error) *Entry {
79 | return NewEntry(l).WithError(err)
80 | }
81 |
82 | // Debug level message.
83 | func (l *Logger) Debug(msg string) {
84 | NewEntry(l).Debug(msg)
85 | }
86 |
87 | // Info level message.
88 | func (l *Logger) Info(msg string) {
89 | NewEntry(l).Info(msg)
90 | }
91 |
92 | // Warn level message.
93 | func (l *Logger) Warn(msg string) {
94 | NewEntry(l).Warn(msg)
95 | }
96 |
97 | // Error level message.
98 | func (l *Logger) Error(msg string) {
99 | NewEntry(l).Error(msg)
100 | }
101 |
102 | // Fatal level message, followed by an exit.
103 | func (l *Logger) Fatal(msg string) {
104 | NewEntry(l).Fatal(msg)
105 | }
106 |
107 | // Debugf level formatted message.
108 | func (l *Logger) Debugf(msg string, v ...interface{}) {
109 | NewEntry(l).Debugf(msg, v...)
110 | }
111 |
112 | // Infof level formatted message.
113 | func (l *Logger) Infof(msg string, v ...interface{}) {
114 | NewEntry(l).Infof(msg, v...)
115 | }
116 |
117 | // Warnf level formatted message.
118 | func (l *Logger) Warnf(msg string, v ...interface{}) {
119 | NewEntry(l).Warnf(msg, v...)
120 | }
121 |
122 | // Errorf level formatted message.
123 | func (l *Logger) Errorf(msg string, v ...interface{}) {
124 | NewEntry(l).Errorf(msg, v...)
125 | }
126 |
127 | // Fatalf level formatted message, followed by an exit.
128 | func (l *Logger) Fatalf(msg string, v ...interface{}) {
129 | NewEntry(l).Fatalf(msg, v...)
130 | }
131 |
132 | // Trace returns a new entry with a Stop method to fire off
133 | // a corresponding completion log, useful with defer.
134 | func (l *Logger) Trace(msg string) *Entry {
135 | return NewEntry(l).Trace(msg)
136 | }
137 |
138 | // log the message, invoking the handler. We clone the entry here
139 | // to bypass the overhead in Entry methods when the level is not
140 | // met.
141 | func (l *Logger) log(level Level, e *Entry, msg string) {
142 | if level < l.Level {
143 | return
144 | }
145 |
146 | if err := l.Handler.HandleLog(e.finalize(level, msg)); err != nil {
147 | stdlog.Printf("error logging: %s", err)
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/pkg.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | // singletons ftw?
4 | var Log Interface = &Logger{
5 | Handler: HandlerFunc(handleStdLog),
6 | Level: InfoLevel,
7 | }
8 |
9 | // SetHandler sets the handler. This is not thread-safe.
10 | // The default handler outputs to the stdlib log.
11 | func SetHandler(h Handler) {
12 | if logger, ok := Log.(*Logger); ok {
13 | logger.Handler = h
14 | }
15 | }
16 |
17 | // SetLevel sets the log level. This is not thread-safe.
18 | func SetLevel(l Level) {
19 | if logger, ok := Log.(*Logger); ok {
20 | logger.Level = l
21 | }
22 | }
23 |
24 | // SetLevelFromString sets the log level from a string, panicing when invalid. This is not thread-safe.
25 | func SetLevelFromString(s string) {
26 | if logger, ok := Log.(*Logger); ok {
27 | logger.Level = MustParseLevel(s)
28 | }
29 | }
30 |
31 | // WithFields returns a new entry with `fields` set.
32 | func WithFields(fields Fielder) *Entry {
33 | return Log.WithFields(fields)
34 | }
35 |
36 | // WithField returns a new entry with the `key` and `value` set.
37 | func WithField(key string, value interface{}) *Entry {
38 | return Log.WithField(key, value)
39 | }
40 |
41 | // WithError returns a new entry with the "error" set to `err`.
42 | func WithError(err error) *Entry {
43 | return Log.WithError(err)
44 | }
45 |
46 | // Debug level message.
47 | func Debug(msg string) {
48 | Log.Debug(msg)
49 | }
50 |
51 | // Info level message.
52 | func Info(msg string) {
53 | Log.Info(msg)
54 | }
55 |
56 | // Warn level message.
57 | func Warn(msg string) {
58 | Log.Warn(msg)
59 | }
60 |
61 | // Error level message.
62 | func Error(msg string) {
63 | Log.Error(msg)
64 | }
65 |
66 | // Fatal level message, followed by an exit.
67 | func Fatal(msg string) {
68 | Log.Fatal(msg)
69 | }
70 |
71 | // Debugf level formatted message.
72 | func Debugf(msg string, v ...interface{}) {
73 | Log.Debugf(msg, v...)
74 | }
75 |
76 | // Infof level formatted message.
77 | func Infof(msg string, v ...interface{}) {
78 | Log.Infof(msg, v...)
79 | }
80 |
81 | // Warnf level formatted message.
82 | func Warnf(msg string, v ...interface{}) {
83 | Log.Warnf(msg, v...)
84 | }
85 |
86 | // Errorf level formatted message.
87 | func Errorf(msg string, v ...interface{}) {
88 | Log.Errorf(msg, v...)
89 | }
90 |
91 | // Fatalf level formatted message, followed by an exit.
92 | func Fatalf(msg string, v ...interface{}) {
93 | Log.Fatalf(msg, v...)
94 | }
95 |
96 | // Trace returns a new entry with a Stop method to fire off
97 | // a corresponding completion log, useful with defer.
98 | func Trace(msg string) *Entry {
99 | return Log.Trace(msg)
100 | }
101 |
--------------------------------------------------------------------------------
/vendor/github.com/apex/log/stack.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | import "github.com/pkg/errors"
4 |
5 | // stackTracer interface.
6 | type stackTracer interface {
7 | StackTrace() errors.StackTrace
8 | }
9 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .DS_Store?
3 | ._*
4 | .Spotlight-V100
5 | .Trashes
6 | Icon?
7 | ehthumbs.db
8 | Thumbs.db
9 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: go
3 | go:
4 | - 1.2
5 | - 1.3
6 | - 1.4
7 | - 1.5
8 | - 1.6
9 | - 1.7
10 | - tip
11 |
12 | before_script:
13 | - mysql -e 'create database gotest;'
14 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/AUTHORS:
--------------------------------------------------------------------------------
1 | # This is the official list of Go-MySQL-Driver authors for copyright purposes.
2 |
3 | # If you are submitting a patch, please add your name or the name of the
4 | # organization which holds the copyright to this list in alphabetical order.
5 |
6 | # Names should be added to this file as
7 | # Name
8 | # The email address is not required for organizations.
9 | # Please keep the list sorted.
10 |
11 |
12 | # Individual Persons
13 |
14 | Aaron Hopkins
15 | Arne Hormann
16 | Carlos Nieto
17 | Chris Moos
18 | Daniel Nichter
19 | Daniël van Eeden
20 | DisposaBoy
21 | Frederick Mayle
22 | Gustavo Kristic
23 | Hanno Braun
24 | Henri Yandell
25 | Hirotaka Yamamoto
26 | INADA Naoki
27 | James Harr
28 | Jian Zhen
29 | Joshua Prunier
30 | Julien Lefevre
31 | Julien Schmidt
32 | Kamil Dziedzic
33 | Kevin Malachowski
34 | Lennart Rudolph
35 | Leonardo YongUk Kim
36 | Luca Looz
37 | Lucas Liu
38 | Luke Scott
39 | Michael Woolnough
40 | Nicola Peduzzi
41 | Olivier Mengué
42 | Paul Bonser
43 | Runrioter Wung
44 | Soroush Pour
45 | Stan Putrya
46 | Stanley Gunawan
47 | Xiangyu Hu
48 | Xiaobing Jiang
49 | Xiuming Chen
50 | Zhenye Xie
51 |
52 | # Organizations
53 |
54 | Barracuda Networks, Inc.
55 | Google Inc.
56 | Stripe Inc.
57 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | ## Reporting Issues
4 |
5 | Before creating a new Issue, please check first if a similar Issue [already exists](https://github.com/go-sql-driver/mysql/issues?state=open) or was [recently closed](https://github.com/go-sql-driver/mysql/issues?direction=desc&page=1&sort=updated&state=closed).
6 |
7 | ## Contributing Code
8 |
9 | By contributing to this project, you share your code under the Mozilla Public License 2, as specified in the LICENSE file.
10 | Don't forget to add yourself to the AUTHORS file.
11 |
12 | ### Code Review
13 |
14 | Everyone is invited to review and comment on pull requests.
15 | If it looks fine to you, comment with "LGTM" (Looks good to me).
16 |
17 | If changes are required, notice the reviewers with "PTAL" (Please take another look) after committing the fixes.
18 |
19 | Before merging the Pull Request, at least one [team member](https://github.com/go-sql-driver?tab=members) must have commented with "LGTM".
20 |
21 | ## Development Ideas
22 |
23 | If you are looking for ideas for code contributions, please check our [Development Ideas](https://github.com/go-sql-driver/mysql/wiki/Development-Ideas) Wiki page.
24 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/appengine.go:
--------------------------------------------------------------------------------
1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2 | //
3 | // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
4 | //
5 | // This Source Code Form is subject to the terms of the Mozilla Public
6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file,
7 | // You can obtain one at http://mozilla.org/MPL/2.0/.
8 |
9 | // +build appengine
10 |
11 | package mysql
12 |
13 | import (
14 | "appengine/cloudsql"
15 | )
16 |
17 | func init() {
18 | RegisterDial("cloudsql", cloudsql.Dial)
19 | }
20 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/buffer.go:
--------------------------------------------------------------------------------
1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2 | //
3 | // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
4 | //
5 | // This Source Code Form is subject to the terms of the Mozilla Public
6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file,
7 | // You can obtain one at http://mozilla.org/MPL/2.0/.
8 |
9 | package mysql
10 |
11 | import (
12 | "io"
13 | "net"
14 | "time"
15 | )
16 |
17 | const defaultBufSize = 4096
18 |
19 | // A buffer which is used for both reading and writing.
20 | // This is possible since communication on each connection is synchronous.
21 | // In other words, we can't write and read simultaneously on the same connection.
22 | // The buffer is similar to bufio.Reader / Writer but zero-copy-ish
23 | // Also highly optimized for this particular use case.
24 | type buffer struct {
25 | buf []byte
26 | nc net.Conn
27 | idx int
28 | length int
29 | timeout time.Duration
30 | }
31 |
32 | func newBuffer(nc net.Conn) buffer {
33 | var b [defaultBufSize]byte
34 | return buffer{
35 | buf: b[:],
36 | nc: nc,
37 | }
38 | }
39 |
40 | // fill reads into the buffer until at least _need_ bytes are in it
41 | func (b *buffer) fill(need int) error {
42 | n := b.length
43 |
44 | // move existing data to the beginning
45 | if n > 0 && b.idx > 0 {
46 | copy(b.buf[0:n], b.buf[b.idx:])
47 | }
48 |
49 | // grow buffer if necessary
50 | // TODO: let the buffer shrink again at some point
51 | // Maybe keep the org buf slice and swap back?
52 | if need > len(b.buf) {
53 | // Round up to the next multiple of the default size
54 | newBuf := make([]byte, ((need/defaultBufSize)+1)*defaultBufSize)
55 | copy(newBuf, b.buf)
56 | b.buf = newBuf
57 | }
58 |
59 | b.idx = 0
60 |
61 | for {
62 | if b.timeout > 0 {
63 | if err := b.nc.SetReadDeadline(time.Now().Add(b.timeout)); err != nil {
64 | return err
65 | }
66 | }
67 |
68 | nn, err := b.nc.Read(b.buf[n:])
69 | n += nn
70 |
71 | switch err {
72 | case nil:
73 | if n < need {
74 | continue
75 | }
76 | b.length = n
77 | return nil
78 |
79 | case io.EOF:
80 | if n >= need {
81 | b.length = n
82 | return nil
83 | }
84 | return io.ErrUnexpectedEOF
85 |
86 | default:
87 | return err
88 | }
89 | }
90 | }
91 |
92 | // returns next N bytes from buffer.
93 | // The returned slice is only guaranteed to be valid until the next read
94 | func (b *buffer) readNext(need int) ([]byte, error) {
95 | if b.length < need {
96 | // refill
97 | if err := b.fill(need); err != nil {
98 | return nil, err
99 | }
100 | }
101 |
102 | offset := b.idx
103 | b.idx += need
104 | b.length -= need
105 | return b.buf[offset:b.idx], nil
106 | }
107 |
108 | // returns a buffer with the requested size.
109 | // If possible, a slice from the existing buffer is returned.
110 | // Otherwise a bigger buffer is made.
111 | // Only one buffer (total) can be used at a time.
112 | func (b *buffer) takeBuffer(length int) []byte {
113 | if b.length > 0 {
114 | return nil
115 | }
116 |
117 | // test (cheap) general case first
118 | if length <= defaultBufSize || length <= cap(b.buf) {
119 | return b.buf[:length]
120 | }
121 |
122 | if length < maxPacketSize {
123 | b.buf = make([]byte, length)
124 | return b.buf
125 | }
126 | return make([]byte, length)
127 | }
128 |
129 | // shortcut which can be used if the requested buffer is guaranteed to be
130 | // smaller than defaultBufSize
131 | // Only one buffer (total) can be used at a time.
132 | func (b *buffer) takeSmallBuffer(length int) []byte {
133 | if b.length == 0 {
134 | return b.buf[:length]
135 | }
136 | return nil
137 | }
138 |
139 | // takeCompleteBuffer returns the complete existing buffer.
140 | // This can be used if the necessary buffer size is unknown.
141 | // Only one buffer (total) can be used at a time.
142 | func (b *buffer) takeCompleteBuffer() []byte {
143 | if b.length == 0 {
144 | return b.buf
145 | }
146 | return nil
147 | }
148 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/const.go:
--------------------------------------------------------------------------------
1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2 | //
3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
4 | //
5 | // This Source Code Form is subject to the terms of the Mozilla Public
6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file,
7 | // You can obtain one at http://mozilla.org/MPL/2.0/.
8 |
9 | package mysql
10 |
11 | const (
12 | minProtocolVersion byte = 10
13 | maxPacketSize = 1<<24 - 1
14 | timeFormat = "2006-01-02 15:04:05.999999"
15 | )
16 |
17 | // MySQL constants documentation:
18 | // http://dev.mysql.com/doc/internals/en/client-server-protocol.html
19 |
20 | const (
21 | iOK byte = 0x00
22 | iLocalInFile byte = 0xfb
23 | iEOF byte = 0xfe
24 | iERR byte = 0xff
25 | )
26 |
27 | // https://dev.mysql.com/doc/internals/en/capability-flags.html#packet-Protocol::CapabilityFlags
28 | type clientFlag uint32
29 |
30 | const (
31 | clientLongPassword clientFlag = 1 << iota
32 | clientFoundRows
33 | clientLongFlag
34 | clientConnectWithDB
35 | clientNoSchema
36 | clientCompress
37 | clientODBC
38 | clientLocalFiles
39 | clientIgnoreSpace
40 | clientProtocol41
41 | clientInteractive
42 | clientSSL
43 | clientIgnoreSIGPIPE
44 | clientTransactions
45 | clientReserved
46 | clientSecureConn
47 | clientMultiStatements
48 | clientMultiResults
49 | clientPSMultiResults
50 | clientPluginAuth
51 | clientConnectAttrs
52 | clientPluginAuthLenEncClientData
53 | clientCanHandleExpiredPasswords
54 | clientSessionTrack
55 | clientDeprecateEOF
56 | )
57 |
58 | const (
59 | comQuit byte = iota + 1
60 | comInitDB
61 | comQuery
62 | comFieldList
63 | comCreateDB
64 | comDropDB
65 | comRefresh
66 | comShutdown
67 | comStatistics
68 | comProcessInfo
69 | comConnect
70 | comProcessKill
71 | comDebug
72 | comPing
73 | comTime
74 | comDelayedInsert
75 | comChangeUser
76 | comBinlogDump
77 | comTableDump
78 | comConnectOut
79 | comRegisterSlave
80 | comStmtPrepare
81 | comStmtExecute
82 | comStmtSendLongData
83 | comStmtClose
84 | comStmtReset
85 | comSetOption
86 | comStmtFetch
87 | )
88 |
89 | // https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::ColumnType
90 | const (
91 | fieldTypeDecimal byte = iota
92 | fieldTypeTiny
93 | fieldTypeShort
94 | fieldTypeLong
95 | fieldTypeFloat
96 | fieldTypeDouble
97 | fieldTypeNULL
98 | fieldTypeTimestamp
99 | fieldTypeLongLong
100 | fieldTypeInt24
101 | fieldTypeDate
102 | fieldTypeTime
103 | fieldTypeDateTime
104 | fieldTypeYear
105 | fieldTypeNewDate
106 | fieldTypeVarChar
107 | fieldTypeBit
108 | )
109 | const (
110 | fieldTypeJSON byte = iota + 0xf5
111 | fieldTypeNewDecimal
112 | fieldTypeEnum
113 | fieldTypeSet
114 | fieldTypeTinyBLOB
115 | fieldTypeMediumBLOB
116 | fieldTypeLongBLOB
117 | fieldTypeBLOB
118 | fieldTypeVarString
119 | fieldTypeString
120 | fieldTypeGeometry
121 | )
122 |
123 | type fieldFlag uint16
124 |
125 | const (
126 | flagNotNULL fieldFlag = 1 << iota
127 | flagPriKey
128 | flagUniqueKey
129 | flagMultipleKey
130 | flagBLOB
131 | flagUnsigned
132 | flagZeroFill
133 | flagBinary
134 | flagEnum
135 | flagAutoIncrement
136 | flagTimestamp
137 | flagSet
138 | flagUnknown1
139 | flagUnknown2
140 | flagUnknown3
141 | flagUnknown4
142 | )
143 |
144 | // http://dev.mysql.com/doc/internals/en/status-flags.html
145 | type statusFlag uint16
146 |
147 | const (
148 | statusInTrans statusFlag = 1 << iota
149 | statusInAutocommit
150 | statusReserved // Not in documentation
151 | statusMoreResultsExists
152 | statusNoGoodIndexUsed
153 | statusNoIndexUsed
154 | statusCursorExists
155 | statusLastRowSent
156 | statusDbDropped
157 | statusNoBackslashEscapes
158 | statusMetadataChanged
159 | statusQueryWasSlow
160 | statusPsOutParams
161 | statusInTransReadonly
162 | statusSessionStateChanged
163 | )
164 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/result.go:
--------------------------------------------------------------------------------
1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2 | //
3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
4 | //
5 | // This Source Code Form is subject to the terms of the Mozilla Public
6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file,
7 | // You can obtain one at http://mozilla.org/MPL/2.0/.
8 |
9 | package mysql
10 |
11 | type mysqlResult struct {
12 | affectedRows int64
13 | insertId int64
14 | }
15 |
16 | func (res *mysqlResult) LastInsertId() (int64, error) {
17 | return res.insertId, nil
18 | }
19 |
20 | func (res *mysqlResult) RowsAffected() (int64, error) {
21 | return res.affectedRows, nil
22 | }
23 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/rows.go:
--------------------------------------------------------------------------------
1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2 | //
3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
4 | //
5 | // This Source Code Form is subject to the terms of the Mozilla Public
6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file,
7 | // You can obtain one at http://mozilla.org/MPL/2.0/.
8 |
9 | package mysql
10 |
11 | import (
12 | "database/sql/driver"
13 | "io"
14 | )
15 |
16 | type mysqlField struct {
17 | tableName string
18 | name string
19 | flags fieldFlag
20 | fieldType byte
21 | decimals byte
22 | }
23 |
24 | type mysqlRows struct {
25 | mc *mysqlConn
26 | columns []mysqlField
27 | }
28 |
29 | type binaryRows struct {
30 | mysqlRows
31 | }
32 |
33 | type textRows struct {
34 | mysqlRows
35 | }
36 |
37 | type emptyRows struct{}
38 |
39 | func (rows *mysqlRows) Columns() []string {
40 | columns := make([]string, len(rows.columns))
41 | if rows.mc != nil && rows.mc.cfg.ColumnsWithAlias {
42 | for i := range columns {
43 | if tableName := rows.columns[i].tableName; len(tableName) > 0 {
44 | columns[i] = tableName + "." + rows.columns[i].name
45 | } else {
46 | columns[i] = rows.columns[i].name
47 | }
48 | }
49 | } else {
50 | for i := range columns {
51 | columns[i] = rows.columns[i].name
52 | }
53 | }
54 | return columns
55 | }
56 |
57 | func (rows *mysqlRows) Close() error {
58 | mc := rows.mc
59 | if mc == nil {
60 | return nil
61 | }
62 | if mc.netConn == nil {
63 | return ErrInvalidConn
64 | }
65 |
66 | // Remove unread packets from stream
67 | err := mc.readUntilEOF()
68 | if err == nil {
69 | if err = mc.discardResults(); err != nil {
70 | return err
71 | }
72 | }
73 |
74 | rows.mc = nil
75 | return err
76 | }
77 |
78 | func (rows *binaryRows) Next(dest []driver.Value) error {
79 | if mc := rows.mc; mc != nil {
80 | if mc.netConn == nil {
81 | return ErrInvalidConn
82 | }
83 |
84 | // Fetch next row from stream
85 | return rows.readRow(dest)
86 | }
87 | return io.EOF
88 | }
89 |
90 | func (rows *textRows) Next(dest []driver.Value) error {
91 | if mc := rows.mc; mc != nil {
92 | if mc.netConn == nil {
93 | return ErrInvalidConn
94 | }
95 |
96 | // Fetch next row from stream
97 | return rows.readRow(dest)
98 | }
99 | return io.EOF
100 | }
101 |
102 | func (rows emptyRows) Columns() []string {
103 | return nil
104 | }
105 |
106 | func (rows emptyRows) Close() error {
107 | return nil
108 | }
109 |
110 | func (rows emptyRows) Next(dest []driver.Value) error {
111 | return io.EOF
112 | }
113 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/statement.go:
--------------------------------------------------------------------------------
1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2 | //
3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
4 | //
5 | // This Source Code Form is subject to the terms of the Mozilla Public
6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file,
7 | // You can obtain one at http://mozilla.org/MPL/2.0/.
8 |
9 | package mysql
10 |
11 | import (
12 | "database/sql/driver"
13 | "fmt"
14 | "reflect"
15 | "strconv"
16 | )
17 |
18 | type mysqlStmt struct {
19 | mc *mysqlConn
20 | id uint32
21 | paramCount int
22 | columns []mysqlField // cached from the first query
23 | }
24 |
25 | func (stmt *mysqlStmt) Close() error {
26 | if stmt.mc == nil || stmt.mc.netConn == nil {
27 | // driver.Stmt.Close can be called more than once, thus this function
28 | // has to be idempotent.
29 | // See also Issue #450 and golang/go#16019.
30 | //errLog.Print(ErrInvalidConn)
31 | return driver.ErrBadConn
32 | }
33 |
34 | err := stmt.mc.writeCommandPacketUint32(comStmtClose, stmt.id)
35 | stmt.mc = nil
36 | return err
37 | }
38 |
39 | func (stmt *mysqlStmt) NumInput() int {
40 | return stmt.paramCount
41 | }
42 |
43 | func (stmt *mysqlStmt) ColumnConverter(idx int) driver.ValueConverter {
44 | return converter{}
45 | }
46 |
47 | func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) {
48 | if stmt.mc.netConn == nil {
49 | errLog.Print(ErrInvalidConn)
50 | return nil, driver.ErrBadConn
51 | }
52 | // Send command
53 | err := stmt.writeExecutePacket(args)
54 | if err != nil {
55 | return nil, err
56 | }
57 |
58 | mc := stmt.mc
59 |
60 | mc.affectedRows = 0
61 | mc.insertId = 0
62 |
63 | // Read Result
64 | resLen, err := mc.readResultSetHeaderPacket()
65 | if err == nil {
66 | if resLen > 0 {
67 | // Columns
68 | err = mc.readUntilEOF()
69 | if err != nil {
70 | return nil, err
71 | }
72 |
73 | // Rows
74 | err = mc.readUntilEOF()
75 | }
76 | if err == nil {
77 | return &mysqlResult{
78 | affectedRows: int64(mc.affectedRows),
79 | insertId: int64(mc.insertId),
80 | }, nil
81 | }
82 | }
83 |
84 | return nil, err
85 | }
86 |
87 | func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) {
88 | if stmt.mc.netConn == nil {
89 | errLog.Print(ErrInvalidConn)
90 | return nil, driver.ErrBadConn
91 | }
92 | // Send command
93 | err := stmt.writeExecutePacket(args)
94 | if err != nil {
95 | return nil, err
96 | }
97 |
98 | mc := stmt.mc
99 |
100 | // Read Result
101 | resLen, err := mc.readResultSetHeaderPacket()
102 | if err != nil {
103 | return nil, err
104 | }
105 |
106 | rows := new(binaryRows)
107 |
108 | if resLen > 0 {
109 | rows.mc = mc
110 | // Columns
111 | // If not cached, read them and cache them
112 | if stmt.columns == nil {
113 | rows.columns, err = mc.readColumns(resLen)
114 | stmt.columns = rows.columns
115 | } else {
116 | rows.columns = stmt.columns
117 | err = mc.readUntilEOF()
118 | }
119 | }
120 |
121 | return rows, err
122 | }
123 |
124 | type converter struct{}
125 |
126 | func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
127 | if driver.IsValue(v) {
128 | return v, nil
129 | }
130 |
131 | rv := reflect.ValueOf(v)
132 | switch rv.Kind() {
133 | case reflect.Ptr:
134 | // indirect pointers
135 | if rv.IsNil() {
136 | return nil, nil
137 | }
138 | return c.ConvertValue(rv.Elem().Interface())
139 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
140 | return rv.Int(), nil
141 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32:
142 | return int64(rv.Uint()), nil
143 | case reflect.Uint64:
144 | u64 := rv.Uint()
145 | if u64 >= 1<<63 {
146 | return strconv.FormatUint(u64, 10), nil
147 | }
148 | return int64(u64), nil
149 | case reflect.Float32, reflect.Float64:
150 | return rv.Float(), nil
151 | }
152 | return nil, fmt.Errorf("unsupported type %T, a %s", v, rv.Kind())
153 | }
154 |
--------------------------------------------------------------------------------
/vendor/github.com/go-sql-driver/mysql/transaction.go:
--------------------------------------------------------------------------------
1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2 | //
3 | // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
4 | //
5 | // This Source Code Form is subject to the terms of the Mozilla Public
6 | // License, v. 2.0. If a copy of the MPL was not distributed with this file,
7 | // You can obtain one at http://mozilla.org/MPL/2.0/.
8 |
9 | package mysql
10 |
11 | type mysqlTx struct {
12 | mc *mysqlConn
13 | }
14 |
15 | func (tx *mysqlTx) Commit() (err error) {
16 | if tx.mc == nil || tx.mc.netConn == nil {
17 | return ErrInvalidConn
18 | }
19 | err = tx.mc.exec("COMMIT")
20 | tx.mc = nil
21 | return
22 | }
23 |
24 | func (tx *mysqlTx) Rollback() (err error) {
25 | if tx.mc == nil || tx.mc.netConn == nil {
26 | return ErrInvalidConn
27 | }
28 | err = tx.mc.exec("ROLLBACK")
29 | tx.mc = nil
30 | return
31 | }
32 |
--------------------------------------------------------------------------------
/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/README.md:
--------------------------------------------------------------------------------
1 | # mousetrap
2 |
3 | mousetrap is a tiny library that answers a single question.
4 |
5 | On a Windows machine, was the process invoked by someone double clicking on
6 | the executable file while browsing in explorer?
7 |
8 | ### Motivation
9 |
10 | Windows developers unfamiliar with command line tools will often "double-click"
11 | the executable for a tool. Because most CLI tools print the help and then exit
12 | when invoked without arguments, this is often very frustrating for those users.
13 |
14 | mousetrap provides a way to detect these invocations so that you can provide
15 | more helpful behavior and instructions on how to run the CLI tool. To see what
16 | this looks like, both from an organizational and a technical perspective, see
17 | https://inconshreveable.com/09-09-2014/sweat-the-small-stuff/
18 |
19 | ### The interface
20 |
21 | The library exposes a single interface:
22 |
23 | func StartedByExplorer() (bool)
24 |
--------------------------------------------------------------------------------
/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/jinzhu/inflection/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 - Jinzhu
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 |
--------------------------------------------------------------------------------
/vendor/github.com/jinzhu/inflection/README.md:
--------------------------------------------------------------------------------
1 | Inflection
2 | =========
3 |
4 | Inflection pluralizes and singularizes English nouns
5 |
6 | ## Basic Usage
7 |
8 | ```go
9 | inflection.Plural("person") => "people"
10 | inflection.Plural("Person") => "People"
11 | inflection.Plural("PERSON") => "PEOPLE"
12 | inflection.Plural("bus") => "buses"
13 | inflection.Plural("BUS") => "BUSES"
14 | inflection.Plural("Bus") => "Buses"
15 |
16 | inflection.Singular("people") => "person"
17 | inflection.Singular("People") => "Person"
18 | inflection.Singular("PEOPLE") => "PERSON"
19 | inflection.Singular("buses") => "bus"
20 | inflection.Singular("BUSES") => "BUS"
21 | inflection.Singular("Buses") => "Bus"
22 |
23 | inflection.Plural("FancyPerson") => "FancyPeople"
24 | inflection.Singular("FancyPeople") => "FancyPerson"
25 | ```
26 |
27 | ## Register Rules
28 |
29 | Standard rules are from Rails's ActiveSupport (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflections.rb)
30 |
31 | If you want to register more rules, follow:
32 |
33 | ```
34 | inflection.AddUncountable("fish")
35 | inflection.AddIrregular("person", "people")
36 | inflection.AddPlural("(bu)s$", "${1}ses") # "bus" => "buses" / "BUS" => "BUSES" / "Bus" => "Buses"
37 | inflection.AddSingular("(bus)(es)?$", "${1}") # "buses" => "bus" / "Buses" => "Bus" / "BUSES" => "BUS"
38 | ```
39 |
40 | ## Supporting the project
41 |
42 | [](http://patreon.com/jinzhu)
43 |
44 |
45 | ## Author
46 |
47 | **jinzhu**
48 |
49 | *
50 | *
51 | *
52 |
53 | ## License
54 |
55 | Released under the [MIT License](http://www.opensource.org/licenses/MIT).
56 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/.gitignore:
--------------------------------------------------------------------------------
1 | .db
2 | *.test
3 | *~
4 | *.swp
5 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/.travis.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -eu
4 |
5 | client_configure() {
6 | sudo chmod 600 $PQSSLCERTTEST_PATH/postgresql.key
7 | }
8 |
9 | pgdg_repository() {
10 | local sourcelist='sources.list.d/postgresql.list'
11 |
12 | curl -sS 'https://www.postgresql.org/media/keys/ACCC4CF8.asc' | sudo apt-key add -
13 | echo deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main $PGVERSION | sudo tee "/etc/apt/$sourcelist"
14 | sudo apt-get -o Dir::Etc::sourcelist="$sourcelist" -o Dir::Etc::sourceparts='-' -o APT::Get::List-Cleanup='0' update
15 | }
16 |
17 | postgresql_configure() {
18 | sudo tee /etc/postgresql/$PGVERSION/main/pg_hba.conf > /dev/null <<-config
19 | local all all trust
20 | hostnossl all pqgossltest 127.0.0.1/32 reject
21 | hostnossl all pqgosslcert 127.0.0.1/32 reject
22 | hostssl all pqgossltest 127.0.0.1/32 trust
23 | hostssl all pqgosslcert 127.0.0.1/32 cert
24 | host all all 127.0.0.1/32 trust
25 | hostnossl all pqgossltest ::1/128 reject
26 | hostnossl all pqgosslcert ::1/128 reject
27 | hostssl all pqgossltest ::1/128 trust
28 | hostssl all pqgosslcert ::1/128 cert
29 | host all all ::1/128 trust
30 | config
31 |
32 | xargs sudo install -o postgres -g postgres -m 600 -t /var/lib/postgresql/$PGVERSION/main/ <<-certificates
33 | certs/root.crt
34 | certs/server.crt
35 | certs/server.key
36 | certificates
37 |
38 | sort -VCu <<-versions ||
39 | $PGVERSION
40 | 9.2
41 | versions
42 | sudo tee -a /etc/postgresql/$PGVERSION/main/postgresql.conf > /dev/null <<-config
43 | ssl_ca_file = 'root.crt'
44 | ssl_cert_file = 'server.crt'
45 | ssl_key_file = 'server.key'
46 | config
47 |
48 | echo 127.0.0.1 postgres | sudo tee -a /etc/hosts > /dev/null
49 |
50 | sudo service postgresql restart
51 | }
52 |
53 | postgresql_install() {
54 | xargs sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confnew' install <<-packages
55 | postgresql-$PGVERSION
56 | postgresql-server-dev-$PGVERSION
57 | postgresql-contrib-$PGVERSION
58 | packages
59 | }
60 |
61 | postgresql_uninstall() {
62 | sudo service postgresql stop
63 | xargs sudo apt-get -y --purge remove <<-packages
64 | libpq-dev
65 | libpq5
66 | postgresql
67 | postgresql-client-common
68 | postgresql-common
69 | packages
70 | sudo rm -rf /var/lib/postgresql
71 | }
72 |
73 | megacheck_install() {
74 | # Megacheck is Go 1.6+, so skip if Go 1.5.
75 | if [[ "$(go version)" =~ "go1.5" ]]
76 | then
77 | echo "megacheck not supported, skipping installation"
78 | return 0
79 | fi
80 | # Lock megacheck version at $MEGACHECK_VERSION to prevent spontaneous
81 | # new error messages in old code.
82 | go get -d honnef.co/go/tools/...
83 | git -C $GOPATH/src/honnef.co/go/tools/ checkout $MEGACHECK_VERSION
84 | go install honnef.co/go/tools/cmd/megacheck
85 | megacheck --version
86 | }
87 |
88 | golint_install() {
89 | # Golint is Go 1.6+, so skip if Go 1.5.
90 | if [[ "$(go version)" =~ "go1.5" ]]
91 | then
92 | echo "golint not supported, skipping installation"
93 | return 0
94 | fi
95 | go get github.com/golang/lint/golint
96 | }
97 |
98 | $1
99 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | go:
4 | - 1.6.x
5 | - 1.7.x
6 | - 1.8.x
7 | - 1.9.x
8 | - master
9 |
10 | sudo: true
11 |
12 | env:
13 | global:
14 | - PGUSER=postgres
15 | - PQGOSSLTESTS=1
16 | - PQSSLCERTTEST_PATH=$PWD/certs
17 | - PGHOST=127.0.0.1
18 | - MEGACHECK_VERSION=2017.2.1
19 | matrix:
20 | - PGVERSION=10
21 | - PGVERSION=9.6
22 | - PGVERSION=9.5
23 | - PGVERSION=9.4
24 | - PGVERSION=9.3
25 | - PGVERSION=9.2
26 | - PGVERSION=9.1
27 | - PGVERSION=9.0
28 |
29 | before_install:
30 | - ./.travis.sh postgresql_uninstall
31 | - ./.travis.sh pgdg_repository
32 | - ./.travis.sh postgresql_install
33 | - ./.travis.sh postgresql_configure
34 | - ./.travis.sh client_configure
35 | - ./.travis.sh megacheck_install
36 | - ./.travis.sh golint_install
37 | - go get golang.org/x/tools/cmd/goimports
38 |
39 | before_script:
40 | - createdb pqgotest
41 | - createuser -DRS pqgossltest
42 | - createuser -DRS pqgosslcert
43 |
44 | script:
45 | - >
46 | goimports -d -e $(find -name '*.go') | awk '{ print } END { exit NR == 0 ? 0 : 1 }'
47 | - go vet ./...
48 | # For compatibility with Go 1.5, launch only if megacheck is present.
49 | - >
50 | which megacheck > /dev/null && megacheck -go 1.5 ./...
51 | || echo 'megacheck is not supported, skipping check'
52 | # For compatibility with Go 1.5, launch only if golint is present.
53 | - >
54 | which golint > /dev/null && golint ./...
55 | || echo 'golint is not supported, skipping check'
56 | - PQTEST_BINARY_PARAMETERS=no go test -race -v ./...
57 | - PQTEST_BINARY_PARAMETERS=yes go test -race -v ./...
58 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing to pq
2 |
3 | `pq` has a backlog of pull requests, but contributions are still very
4 | much welcome. You can help with patch review, submitting bug reports,
5 | or adding new functionality. There is no formal style guide, but
6 | please conform to the style of existing code and general Go formatting
7 | conventions when submitting patches.
8 |
9 | ### Patch review
10 |
11 | Help review existing open pull requests by commenting on the code or
12 | proposed functionality.
13 |
14 | ### Bug reports
15 |
16 | We appreciate any bug reports, but especially ones with self-contained
17 | (doesn't depend on code outside of pq), minimal (can't be simplified
18 | further) test cases. It's especially helpful if you can submit a pull
19 | request with just the failing test case (you'll probably want to
20 | pattern it after the tests in
21 | [conn_test.go](https://github.com/lib/pq/blob/master/conn_test.go).
22 |
23 | ### New functionality
24 |
25 | There are a number of pending patches for new functionality, so
26 | additional feature patches will take a while to merge. Still, patches
27 | are generally reviewed based on usefulness and complexity in addition
28 | to time-in-queue, so if you have a knockout idea, take a shot. Feel
29 | free to open an issue discussion your proposed patch beforehand.
30 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011-2013, 'pq' Contributors
2 | Portions Copyright (C) 2011 Blake Mizerany
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/README.md:
--------------------------------------------------------------------------------
1 | # pq - A pure Go postgres driver for Go's database/sql package
2 |
3 | [](https://godoc.org/github.com/lib/pq)
4 | [](https://travis-ci.org/lib/pq)
5 |
6 | ## Install
7 |
8 | go get github.com/lib/pq
9 |
10 | ## Docs
11 |
12 | For detailed documentation and basic usage examples, please see the package
13 | documentation at .
14 |
15 | ## Tests
16 |
17 | `go test` is used for testing. A running PostgreSQL server is
18 | required, with the ability to log in. The default database to connect
19 | to test with is "pqgotest," but it can be overridden using environment
20 | variables.
21 |
22 | Example:
23 |
24 | PGHOST=/run/postgresql go test github.com/lib/pq
25 |
26 | Optionally, a benchmark suite can be run as part of the tests:
27 |
28 | PGHOST=/run/postgresql go test -bench .
29 |
30 | ## Features
31 |
32 | * SSL
33 | * Handles bad connections for `database/sql`
34 | * Scan `time.Time` correctly (i.e. `timestamp[tz]`, `time[tz]`, `date`)
35 | * Scan binary blobs correctly (i.e. `bytea`)
36 | * Package for `hstore` support
37 | * COPY FROM support
38 | * pq.ParseURL for converting urls to connection strings for sql.Open.
39 | * Many libpq compatible environment variables
40 | * Unix socket support
41 | * Notifications: `LISTEN`/`NOTIFY`
42 | * pgpass support
43 |
44 | ## Future / Things you can help with
45 |
46 | * Better COPY FROM / COPY TO (see discussion in #181)
47 |
48 | ## Thank you (alphabetical)
49 |
50 | Some of these contributors are from the original library `bmizerany/pq.go` whose
51 | code still exists in here.
52 |
53 | * Andy Balholm (andybalholm)
54 | * Ben Berkert (benburkert)
55 | * Benjamin Heatwole (bheatwole)
56 | * Bill Mill (llimllib)
57 | * Bjørn Madsen (aeons)
58 | * Blake Gentry (bgentry)
59 | * Brad Fitzpatrick (bradfitz)
60 | * Charlie Melbye (cmelbye)
61 | * Chris Bandy (cbandy)
62 | * Chris Gilling (cgilling)
63 | * Chris Walsh (cwds)
64 | * Dan Sosedoff (sosedoff)
65 | * Daniel Farina (fdr)
66 | * Eric Chlebek (echlebek)
67 | * Eric Garrido (minusnine)
68 | * Eric Urban (hydrogen18)
69 | * Everyone at The Go Team
70 | * Evan Shaw (edsrzf)
71 | * Ewan Chou (coocood)
72 | * Fazal Majid (fazalmajid)
73 | * Federico Romero (federomero)
74 | * Fumin (fumin)
75 | * Gary Burd (garyburd)
76 | * Heroku (heroku)
77 | * James Pozdena (jpoz)
78 | * Jason McVetta (jmcvetta)
79 | * Jeremy Jay (pbnjay)
80 | * Joakim Sernbrant (serbaut)
81 | * John Gallagher (jgallagher)
82 | * Jonathan Rudenberg (titanous)
83 | * Joël Stemmer (jstemmer)
84 | * Kamil Kisiel (kisielk)
85 | * Kelly Dunn (kellydunn)
86 | * Keith Rarick (kr)
87 | * Kir Shatrov (kirs)
88 | * Lann Martin (lann)
89 | * Maciek Sakrejda (uhoh-itsmaciek)
90 | * Marc Brinkmann (mbr)
91 | * Marko Tiikkaja (johto)
92 | * Matt Newberry (MattNewberry)
93 | * Matt Robenolt (mattrobenolt)
94 | * Martin Olsen (martinolsen)
95 | * Mike Lewis (mikelikespie)
96 | * Nicolas Patry (Narsil)
97 | * Oliver Tonnhofer (olt)
98 | * Patrick Hayes (phayes)
99 | * Paul Hammond (paulhammond)
100 | * Ryan Smith (ryandotsmith)
101 | * Samuel Stauffer (samuel)
102 | * Timothée Peignier (cyberdelia)
103 | * Travis Cline (tmc)
104 | * TruongSinh Tran-Nguyen (truongsinh)
105 | * Yaismel Miranda (ympons)
106 | * notedit (notedit)
107 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/buf.go:
--------------------------------------------------------------------------------
1 | package pq
2 |
3 | import (
4 | "bytes"
5 | "encoding/binary"
6 |
7 | "github.com/lib/pq/oid"
8 | )
9 |
10 | type readBuf []byte
11 |
12 | func (b *readBuf) int32() (n int) {
13 | n = int(int32(binary.BigEndian.Uint32(*b)))
14 | *b = (*b)[4:]
15 | return
16 | }
17 |
18 | func (b *readBuf) oid() (n oid.Oid) {
19 | n = oid.Oid(binary.BigEndian.Uint32(*b))
20 | *b = (*b)[4:]
21 | return
22 | }
23 |
24 | // N.B: this is actually an unsigned 16-bit integer, unlike int32
25 | func (b *readBuf) int16() (n int) {
26 | n = int(binary.BigEndian.Uint16(*b))
27 | *b = (*b)[2:]
28 | return
29 | }
30 |
31 | func (b *readBuf) string() string {
32 | i := bytes.IndexByte(*b, 0)
33 | if i < 0 {
34 | errorf("invalid message format; expected string terminator")
35 | }
36 | s := (*b)[:i]
37 | *b = (*b)[i+1:]
38 | return string(s)
39 | }
40 |
41 | func (b *readBuf) next(n int) (v []byte) {
42 | v = (*b)[:n]
43 | *b = (*b)[n:]
44 | return
45 | }
46 |
47 | func (b *readBuf) byte() byte {
48 | return b.next(1)[0]
49 | }
50 |
51 | type writeBuf struct {
52 | buf []byte
53 | pos int
54 | }
55 |
56 | func (b *writeBuf) int32(n int) {
57 | x := make([]byte, 4)
58 | binary.BigEndian.PutUint32(x, uint32(n))
59 | b.buf = append(b.buf, x...)
60 | }
61 |
62 | func (b *writeBuf) int16(n int) {
63 | x := make([]byte, 2)
64 | binary.BigEndian.PutUint16(x, uint16(n))
65 | b.buf = append(b.buf, x...)
66 | }
67 |
68 | func (b *writeBuf) string(s string) {
69 | b.buf = append(b.buf, (s + "\000")...)
70 | }
71 |
72 | func (b *writeBuf) byte(c byte) {
73 | b.buf = append(b.buf, c)
74 | }
75 |
76 | func (b *writeBuf) bytes(v []byte) {
77 | b.buf = append(b.buf, v...)
78 | }
79 |
80 | func (b *writeBuf) wrap() []byte {
81 | p := b.buf[b.pos:]
82 | binary.BigEndian.PutUint32(p, uint32(len(p)))
83 | return b.buf
84 | }
85 |
86 | func (b *writeBuf) next(c byte) {
87 | p := b.buf[b.pos:]
88 | binary.BigEndian.PutUint32(p, uint32(len(p)))
89 | b.pos = len(b.buf) + 1
90 | b.buf = append(b.buf, c, 0, 0, 0, 0)
91 | }
92 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/conn_go18.go:
--------------------------------------------------------------------------------
1 | // +build go1.8
2 |
3 | package pq
4 |
5 | import (
6 | "context"
7 | "database/sql"
8 | "database/sql/driver"
9 | "fmt"
10 | "io"
11 | "io/ioutil"
12 | )
13 |
14 | // Implement the "QueryerContext" interface
15 | func (cn *conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
16 | list := make([]driver.Value, len(args))
17 | for i, nv := range args {
18 | list[i] = nv.Value
19 | }
20 | finish := cn.watchCancel(ctx)
21 | r, err := cn.query(query, list)
22 | if err != nil {
23 | if finish != nil {
24 | finish()
25 | }
26 | return nil, err
27 | }
28 | r.finish = finish
29 | return r, nil
30 | }
31 |
32 | // Implement the "ExecerContext" interface
33 | func (cn *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
34 | list := make([]driver.Value, len(args))
35 | for i, nv := range args {
36 | list[i] = nv.Value
37 | }
38 |
39 | if finish := cn.watchCancel(ctx); finish != nil {
40 | defer finish()
41 | }
42 |
43 | return cn.Exec(query, list)
44 | }
45 |
46 | // Implement the "ConnBeginTx" interface
47 | func (cn *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
48 | var mode string
49 |
50 | switch sql.IsolationLevel(opts.Isolation) {
51 | case sql.LevelDefault:
52 | // Don't touch mode: use the server's default
53 | case sql.LevelReadUncommitted:
54 | mode = " ISOLATION LEVEL READ UNCOMMITTED"
55 | case sql.LevelReadCommitted:
56 | mode = " ISOLATION LEVEL READ COMMITTED"
57 | case sql.LevelRepeatableRead:
58 | mode = " ISOLATION LEVEL REPEATABLE READ"
59 | case sql.LevelSerializable:
60 | mode = " ISOLATION LEVEL SERIALIZABLE"
61 | default:
62 | return nil, fmt.Errorf("pq: isolation level not supported: %d", opts.Isolation)
63 | }
64 |
65 | if opts.ReadOnly {
66 | mode += " READ ONLY"
67 | } else {
68 | mode += " READ WRITE"
69 | }
70 |
71 | tx, err := cn.begin(mode)
72 | if err != nil {
73 | return nil, err
74 | }
75 | cn.txnFinish = cn.watchCancel(ctx)
76 | return tx, nil
77 | }
78 |
79 | func (cn *conn) watchCancel(ctx context.Context) func() {
80 | if done := ctx.Done(); done != nil {
81 | finished := make(chan struct{})
82 | go func() {
83 | select {
84 | case <-done:
85 | _ = cn.cancel()
86 | finished <- struct{}{}
87 | case <-finished:
88 | }
89 | }()
90 | return func() {
91 | select {
92 | case <-finished:
93 | case finished <- struct{}{}:
94 | }
95 | }
96 | }
97 | return nil
98 | }
99 |
100 | func (cn *conn) cancel() error {
101 | c, err := dial(cn.dialer, cn.opts)
102 | if err != nil {
103 | return err
104 | }
105 | defer c.Close()
106 |
107 | {
108 | can := conn{
109 | c: c,
110 | }
111 | can.ssl(cn.opts)
112 |
113 | w := can.writeBuf(0)
114 | w.int32(80877102) // cancel request code
115 | w.int32(cn.processID)
116 | w.int32(cn.secretKey)
117 |
118 | if err := can.sendStartupPacket(w); err != nil {
119 | return err
120 | }
121 | }
122 |
123 | // Read until EOF to ensure that the server received the cancel.
124 | {
125 | _, err := io.Copy(ioutil.Discard, c)
126 | return err
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/oid/doc.go:
--------------------------------------------------------------------------------
1 | // Package oid contains OID constants
2 | // as defined by the Postgres server.
3 | package oid
4 |
5 | // Oid is a Postgres Object ID.
6 | type Oid uint32
7 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/oid/gen.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | // Generate the table of OID values
4 | // Run with 'go run gen.go'.
5 | package main
6 |
7 | import (
8 | "database/sql"
9 | "fmt"
10 | "log"
11 | "os"
12 | "os/exec"
13 | "strings"
14 |
15 | _ "github.com/lib/pq"
16 | )
17 |
18 | // OID represent a postgres Object Identifier Type.
19 | type OID struct {
20 | ID int
21 | Type string
22 | }
23 |
24 | // Name returns an upper case version of the oid type.
25 | func (o OID) Name() string {
26 | return strings.ToUpper(o.Type)
27 | }
28 |
29 | func main() {
30 | datname := os.Getenv("PGDATABASE")
31 | sslmode := os.Getenv("PGSSLMODE")
32 |
33 | if datname == "" {
34 | os.Setenv("PGDATABASE", "pqgotest")
35 | }
36 |
37 | if sslmode == "" {
38 | os.Setenv("PGSSLMODE", "disable")
39 | }
40 |
41 | db, err := sql.Open("postgres", "")
42 | if err != nil {
43 | log.Fatal(err)
44 | }
45 | rows, err := db.Query(`
46 | SELECT typname, oid
47 | FROM pg_type WHERE oid < 10000
48 | ORDER BY oid;
49 | `)
50 | if err != nil {
51 | log.Fatal(err)
52 | }
53 | oids := make([]*OID, 0)
54 | for rows.Next() {
55 | var oid OID
56 | if err = rows.Scan(&oid.Type, &oid.ID); err != nil {
57 | log.Fatal(err)
58 | }
59 | oids = append(oids, &oid)
60 | }
61 | if err = rows.Err(); err != nil {
62 | log.Fatal(err)
63 | }
64 | cmd := exec.Command("gofmt")
65 | cmd.Stderr = os.Stderr
66 | w, err := cmd.StdinPipe()
67 | if err != nil {
68 | log.Fatal(err)
69 | }
70 | f, err := os.Create("types.go")
71 | if err != nil {
72 | log.Fatal(err)
73 | }
74 | cmd.Stdout = f
75 | err = cmd.Start()
76 | if err != nil {
77 | log.Fatal(err)
78 | }
79 | fmt.Fprintln(w, "// Code generated by gen.go. DO NOT EDIT.")
80 | fmt.Fprintln(w, "\npackage oid")
81 | fmt.Fprintln(w, "const (")
82 | for _, oid := range oids {
83 | fmt.Fprintf(w, "T_%s Oid = %d\n", oid.Type, oid.ID)
84 | }
85 | fmt.Fprintln(w, ")")
86 | fmt.Fprintln(w, "var TypeName = map[Oid]string{")
87 | for _, oid := range oids {
88 | fmt.Fprintf(w, "T_%s: \"%s\",\n", oid.Type, oid.Name())
89 | }
90 | fmt.Fprintln(w, "}")
91 | w.Close()
92 | cmd.Wait()
93 | }
94 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/rows.go:
--------------------------------------------------------------------------------
1 | package pq
2 |
3 | import (
4 | "math"
5 | "reflect"
6 | "time"
7 |
8 | "github.com/lib/pq/oid"
9 | )
10 |
11 | const headerSize = 4
12 |
13 | type fieldDesc struct {
14 | // The object ID of the data type.
15 | OID oid.Oid
16 | // The data type size (see pg_type.typlen).
17 | // Note that negative values denote variable-width types.
18 | Len int
19 | // The type modifier (see pg_attribute.atttypmod).
20 | // The meaning of the modifier is type-specific.
21 | Mod int
22 | }
23 |
24 | func (fd fieldDesc) Type() reflect.Type {
25 | switch fd.OID {
26 | case oid.T_int8:
27 | return reflect.TypeOf(int64(0))
28 | case oid.T_int4:
29 | return reflect.TypeOf(int32(0))
30 | case oid.T_int2:
31 | return reflect.TypeOf(int16(0))
32 | case oid.T_varchar, oid.T_text:
33 | return reflect.TypeOf("")
34 | case oid.T_bool:
35 | return reflect.TypeOf(false)
36 | case oid.T_date, oid.T_time, oid.T_timetz, oid.T_timestamp, oid.T_timestamptz:
37 | return reflect.TypeOf(time.Time{})
38 | case oid.T_bytea:
39 | return reflect.TypeOf([]byte(nil))
40 | default:
41 | return reflect.TypeOf(new(interface{})).Elem()
42 | }
43 | }
44 |
45 | func (fd fieldDesc) Name() string {
46 | return oid.TypeName[fd.OID]
47 | }
48 |
49 | func (fd fieldDesc) Length() (length int64, ok bool) {
50 | switch fd.OID {
51 | case oid.T_text, oid.T_bytea:
52 | return math.MaxInt64, true
53 | case oid.T_varchar, oid.T_bpchar:
54 | return int64(fd.Mod - headerSize), true
55 | default:
56 | return 0, false
57 | }
58 | }
59 |
60 | func (fd fieldDesc) PrecisionScale() (precision, scale int64, ok bool) {
61 | switch fd.OID {
62 | case oid.T_numeric, oid.T__numeric:
63 | mod := fd.Mod - headerSize
64 | precision = int64((mod >> 16) & 0xffff)
65 | scale = int64(mod & 0xffff)
66 | return precision, scale, true
67 | default:
68 | return 0, 0, false
69 | }
70 | }
71 |
72 | // ColumnTypeScanType returns the value type that can be used to scan types into.
73 | func (rs *rows) ColumnTypeScanType(index int) reflect.Type {
74 | return rs.colTyps[index].Type()
75 | }
76 |
77 | // ColumnTypeDatabaseTypeName return the database system type name.
78 | func (rs *rows) ColumnTypeDatabaseTypeName(index int) string {
79 | return rs.colTyps[index].Name()
80 | }
81 |
82 | // ColumnTypeLength returns the length of the column type if the column is a
83 | // variable length type. If the column is not a variable length type ok
84 | // should return false.
85 | func (rs *rows) ColumnTypeLength(index int) (length int64, ok bool) {
86 | return rs.colTyps[index].Length()
87 | }
88 |
89 | // ColumnTypePrecisionScale should return the precision and scale for decimal
90 | // types. If not applicable, ok should be false.
91 | func (rs *rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) {
92 | return rs.colTyps[index].PrecisionScale()
93 | }
94 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/ssl_go1.7.go:
--------------------------------------------------------------------------------
1 | // +build go1.7
2 |
3 | package pq
4 |
5 | import "crypto/tls"
6 |
7 | // Accept renegotiation requests initiated by the backend.
8 | //
9 | // Renegotiation was deprecated then removed from PostgreSQL 9.5, but
10 | // the default configuration of older versions has it enabled. Redshift
11 | // also initiates renegotiations and cannot be reconfigured.
12 | func sslRenegotiation(conf *tls.Config) {
13 | conf.Renegotiation = tls.RenegotiateFreelyAsClient
14 | }
15 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/ssl_permissions.go:
--------------------------------------------------------------------------------
1 | // +build !windows
2 |
3 | package pq
4 |
5 | import "os"
6 |
7 | // sslKeyPermissions checks the permissions on user-supplied ssl key files.
8 | // The key file should have very little access.
9 | //
10 | // libpq does not check key file permissions on Windows.
11 | func sslKeyPermissions(sslkey string) error {
12 | info, err := os.Stat(sslkey)
13 | if err != nil {
14 | return err
15 | }
16 | if info.Mode().Perm()&0077 != 0 {
17 | return ErrSSLKeyHasWorldPermissions
18 | }
19 | return nil
20 | }
21 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/ssl_renegotiation.go:
--------------------------------------------------------------------------------
1 | // +build !go1.7
2 |
3 | package pq
4 |
5 | import "crypto/tls"
6 |
7 | // Renegotiation is not supported by crypto/tls until Go 1.7.
8 | func sslRenegotiation(*tls.Config) {}
9 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/ssl_windows.go:
--------------------------------------------------------------------------------
1 | // +build windows
2 |
3 | package pq
4 |
5 | // sslKeyPermissions checks the permissions on user-supplied ssl key files.
6 | // The key file should have very little access.
7 | //
8 | // libpq does not check key file permissions on Windows.
9 | func sslKeyPermissions(string) error { return nil }
10 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/url.go:
--------------------------------------------------------------------------------
1 | package pq
2 |
3 | import (
4 | "fmt"
5 | "net"
6 | nurl "net/url"
7 | "sort"
8 | "strings"
9 | )
10 |
11 | // ParseURL no longer needs to be used by clients of this library since supplying a URL as a
12 | // connection string to sql.Open() is now supported:
13 | //
14 | // sql.Open("postgres", "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full")
15 | //
16 | // It remains exported here for backwards-compatibility.
17 | //
18 | // ParseURL converts a url to a connection string for driver.Open.
19 | // Example:
20 | //
21 | // "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full"
22 | //
23 | // converts to:
24 | //
25 | // "user=bob password=secret host=1.2.3.4 port=5432 dbname=mydb sslmode=verify-full"
26 | //
27 | // A minimal example:
28 | //
29 | // "postgres://"
30 | //
31 | // This will be blank, causing driver.Open to use all of the defaults
32 | func ParseURL(url string) (string, error) {
33 | u, err := nurl.Parse(url)
34 | if err != nil {
35 | return "", err
36 | }
37 |
38 | if u.Scheme != "postgres" && u.Scheme != "postgresql" {
39 | return "", fmt.Errorf("invalid connection protocol: %s", u.Scheme)
40 | }
41 |
42 | var kvs []string
43 | escaper := strings.NewReplacer(` `, `\ `, `'`, `\'`, `\`, `\\`)
44 | accrue := func(k, v string) {
45 | if v != "" {
46 | kvs = append(kvs, k+"="+escaper.Replace(v))
47 | }
48 | }
49 |
50 | if u.User != nil {
51 | v := u.User.Username()
52 | accrue("user", v)
53 |
54 | v, _ = u.User.Password()
55 | accrue("password", v)
56 | }
57 |
58 | if host, port, err := net.SplitHostPort(u.Host); err != nil {
59 | accrue("host", u.Host)
60 | } else {
61 | accrue("host", host)
62 | accrue("port", port)
63 | }
64 |
65 | if u.Path != "" {
66 | accrue("dbname", u.Path[1:])
67 | }
68 |
69 | q := u.Query()
70 | for k := range q {
71 | accrue(k, q.Get(k))
72 | }
73 |
74 | sort.Strings(kvs) // Makes testing easier (not a performance concern)
75 | return strings.Join(kvs, " "), nil
76 | }
77 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/user_posix.go:
--------------------------------------------------------------------------------
1 | // Package pq is a pure Go Postgres driver for the database/sql package.
2 |
3 | // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris rumprun
4 |
5 | package pq
6 |
7 | import (
8 | "os"
9 | "os/user"
10 | )
11 |
12 | func userCurrent() (string, error) {
13 | u, err := user.Current()
14 | if err == nil {
15 | return u.Username, nil
16 | }
17 |
18 | name := os.Getenv("USER")
19 | if name != "" {
20 | return name, nil
21 | }
22 |
23 | return "", ErrCouldNotDetectUsername
24 | }
25 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/user_windows.go:
--------------------------------------------------------------------------------
1 | // Package pq is a pure Go Postgres driver for the database/sql package.
2 | package pq
3 |
4 | import (
5 | "path/filepath"
6 | "syscall"
7 | )
8 |
9 | // Perform Windows user name lookup identically to libpq.
10 | //
11 | // The PostgreSQL code makes use of the legacy Win32 function
12 | // GetUserName, and that function has not been imported into stock Go.
13 | // GetUserNameEx is available though, the difference being that a
14 | // wider range of names are available. To get the output to be the
15 | // same as GetUserName, only the base (or last) component of the
16 | // result is returned.
17 | func userCurrent() (string, error) {
18 | pw_name := make([]uint16, 128)
19 | pwname_size := uint32(len(pw_name)) - 1
20 | err := syscall.GetUserNameEx(syscall.NameSamCompatible, &pw_name[0], &pwname_size)
21 | if err != nil {
22 | return "", ErrCouldNotDetectUsername
23 | }
24 | s := syscall.UTF16ToString(pw_name)
25 | u := filepath.Base(s)
26 | return u, nil
27 | }
28 |
--------------------------------------------------------------------------------
/vendor/github.com/lib/pq/uuid.go:
--------------------------------------------------------------------------------
1 | package pq
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | )
7 |
8 | // decodeUUIDBinary interprets the binary format of a uuid, returning it in text format.
9 | func decodeUUIDBinary(src []byte) ([]byte, error) {
10 | if len(src) != 16 {
11 | return nil, fmt.Errorf("pq: unable to decode uuid; bad length: %d", len(src))
12 | }
13 |
14 | dst := make([]byte, 36)
15 | dst[8], dst[13], dst[18], dst[23] = '-', '-', '-', '-'
16 | hex.Encode(dst[0:], src[0:4])
17 | hex.Encode(dst[9:], src[4:6])
18 | hex.Encode(dst[14:], src[6:8])
19 | hex.Encode(dst[19:], src[8:10])
20 | hex.Encode(dst[24:], src[10:16])
21 |
22 | return dst, nil
23 | }
24 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/.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 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 | go_import_path: github.com/pkg/errors
3 | go:
4 | - 1.4.3
5 | - 1.5.4
6 | - 1.6.2
7 | - 1.7.1
8 | - tip
9 |
10 | script:
11 | - go test -v ./...
12 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015, Dave Cheney
2 | 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 met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/README.md:
--------------------------------------------------------------------------------
1 | # errors [](https://travis-ci.org/pkg/errors) [](https://ci.appveyor.com/project/davecheney/errors/branch/master) [](http://godoc.org/github.com/pkg/errors) [](https://goreportcard.com/report/github.com/pkg/errors)
2 |
3 | Package errors provides simple error handling primitives.
4 |
5 | `go get github.com/pkg/errors`
6 |
7 | The traditional error handling idiom in Go is roughly akin to
8 | ```go
9 | if err != nil {
10 | return err
11 | }
12 | ```
13 | which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error.
14 |
15 | ## Adding context to an error
16 |
17 | The errors.Wrap function returns a new error that adds context to the original error. For example
18 | ```go
19 | _, err := ioutil.ReadAll(r)
20 | if err != nil {
21 | return errors.Wrap(err, "read failed")
22 | }
23 | ```
24 | ## Retrieving the cause of an error
25 |
26 | Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`.
27 | ```go
28 | type causer interface {
29 | Cause() error
30 | }
31 | ```
32 | `errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example:
33 | ```go
34 | switch err := errors.Cause(err).(type) {
35 | case *MyError:
36 | // handle specifically
37 | default:
38 | // unknown error
39 | }
40 | ```
41 |
42 | [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors).
43 |
44 | ## Contributing
45 |
46 | We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high.
47 |
48 | Before proposing a change, please discuss your change by raising an issue.
49 |
50 | ## Licence
51 |
52 | BSD-2-Clause
53 |
--------------------------------------------------------------------------------
/vendor/github.com/pkg/errors/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: build-{build}.{branch}
2 |
3 | clone_folder: C:\gopath\src\github.com\pkg\errors
4 | shallow_clone: true # for startup speed
5 |
6 | environment:
7 | GOPATH: C:\gopath
8 |
9 | platform:
10 | - x64
11 |
12 | # http://www.appveyor.com/docs/installed-software
13 | install:
14 | # some helpful output for debugging builds
15 | - go version
16 | - go env
17 | # pre-installed MinGW at C:\MinGW is 32bit only
18 | # but MSYS2 at C:\msys64 has mingw64
19 | - set PATH=C:\msys64\mingw64\bin;%PATH%
20 | - gcc --version
21 | - g++ --version
22 |
23 | build_script:
24 | - go install -v ./...
25 |
26 | test_script:
27 | - set PATH=C:\gopath\bin;%PATH%
28 | - go test -v ./...
29 |
30 | #artifacts:
31 | # - path: '%GOPATH%\bin\*.exe'
32 | deploy: off
33 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/.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 | # Vim files https://github.com/github/gitignore/blob/master/Global/Vim.gitignore
23 | # swap
24 | [._]*.s[a-w][a-z]
25 | [._]s[a-w][a-z]
26 | # session
27 | Session.vim
28 | # temporary
29 | .netrwhist
30 | *~
31 | # auto-generated tag files
32 | tags
33 |
34 | *.exe
35 |
36 | cobra.test
37 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/.mailmap:
--------------------------------------------------------------------------------
1 | Steve Francia
2 | Bjørn Erik Pedersen
3 | Fabiano Franz
4 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | matrix:
4 | include:
5 | - go: 1.7.6
6 | - go: 1.8.3
7 | - go: tip
8 | allow_failures:
9 | - go: tip
10 |
11 | before_install:
12 | - mkdir -p bin
13 | - curl -Lso bin/shellcheck https://github.com/caarlos0/shellcheck-docker/releases/download/v0.4.3/shellcheck
14 | - chmod +x bin/shellcheck
15 | script:
16 | - PATH=$PATH:$PWD/bin go test -v ./...
17 | - go build
18 | - diff -u <(echo -n) <(gofmt -d -s .)
19 | - if [ -z $NOVET ]; then
20 | diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint');
21 | fi
22 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/args.go:
--------------------------------------------------------------------------------
1 | package cobra
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type PositionalArgs func(cmd *Command, args []string) error
8 |
9 | // Legacy arg validation has the following behaviour:
10 | // - root commands with no subcommands can take arbitrary arguments
11 | // - root commands with subcommands will do subcommand validity checking
12 | // - subcommands will always accept arbitrary arguments
13 | func legacyArgs(cmd *Command, args []string) error {
14 | // no subcommand, always take args
15 | if !cmd.HasSubCommands() {
16 | return nil
17 | }
18 |
19 | // root command with subcommands, do subcommand checking
20 | if !cmd.HasParent() && len(args) > 0 {
21 | return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0]))
22 | }
23 | return nil
24 | }
25 |
26 | // NoArgs returns an error if any args are included
27 | func NoArgs(cmd *Command, args []string) error {
28 | if len(args) > 0 {
29 | return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath())
30 | }
31 | return nil
32 | }
33 |
34 | // OnlyValidArgs returns an error if any args are not in the list of ValidArgs
35 | func OnlyValidArgs(cmd *Command, args []string) error {
36 | if len(cmd.ValidArgs) > 0 {
37 | for _, v := range args {
38 | if !stringInSlice(v, cmd.ValidArgs) {
39 | return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0]))
40 | }
41 | }
42 | }
43 | return nil
44 | }
45 |
46 | func stringInSlice(a string, list []string) bool {
47 | for _, b := range list {
48 | if b == a {
49 | return true
50 | }
51 | }
52 | return false
53 | }
54 |
55 | // ArbitraryArgs never returns an error
56 | func ArbitraryArgs(cmd *Command, args []string) error {
57 | return nil
58 | }
59 |
60 | // MinimumNArgs returns an error if there is not at least N args
61 | func MinimumNArgs(n int) PositionalArgs {
62 | return func(cmd *Command, args []string) error {
63 | if len(args) < n {
64 | return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args))
65 | }
66 | return nil
67 | }
68 | }
69 |
70 | // MaximumNArgs returns an error if there are more than N args
71 | func MaximumNArgs(n int) PositionalArgs {
72 | return func(cmd *Command, args []string) error {
73 | if len(args) > n {
74 | return fmt.Errorf("accepts at most %d arg(s), received %d", n, len(args))
75 | }
76 | return nil
77 | }
78 | }
79 |
80 | // ExactArgs returns an error if there are not exactly n args
81 | func ExactArgs(n int) PositionalArgs {
82 | return func(cmd *Command, args []string) error {
83 | if len(args) != n {
84 | return fmt.Errorf("accepts %d arg(s), received %d", n, len(args))
85 | }
86 | return nil
87 | }
88 | }
89 |
90 | // RangeArgs returns an error if the number of args is not within the expected range
91 | func RangeArgs(min int, max int) PositionalArgs {
92 | return func(cmd *Command, args []string) error {
93 | if len(args) < min || len(args) > max {
94 | return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args))
95 | }
96 | return nil
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/cobra/cmd/license_bsd_clause_2.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2015 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 | // Parts inspired by https://github.com/ryanuber/go-license
15 |
16 | package cmd
17 |
18 | func initBsdClause2() {
19 | Licenses["freebsd"] = License{
20 | Name: "Simplified BSD License",
21 | PossibleMatches: []string{"freebsd", "simpbsd", "simple bsd", "2-clause bsd",
22 | "2 clause bsd", "simplified bsd license"},
23 | Header: `All rights reserved.
24 |
25 | Redistribution and use in source and binary forms, with or without
26 | modification, are permitted provided that the following conditions are met:
27 |
28 | 1. Redistributions of source code must retain the above copyright notice,
29 | this list of conditions and the following disclaimer.
30 |
31 | 2. Redistributions in binary form must reproduce the above copyright notice,
32 | this list of conditions and the following disclaimer in the documentation
33 | and/or other materials provided with the distribution.
34 |
35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
39 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
42 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
43 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45 | POSSIBILITY OF SUCH DAMAGE.`,
46 | Text: `{{ .copyright }}
47 | All rights reserved.
48 |
49 | Redistribution and use in source and binary forms, with or without
50 | modification, are permitted provided that the following conditions are met:
51 |
52 | 1. Redistributions of source code must retain the above copyright notice,
53 | this list of conditions and the following disclaimer.
54 |
55 | 2. Redistributions in binary form must reproduce the above copyright notice,
56 | this list of conditions and the following disclaimer in the documentation
57 | and/or other materials provided with the distribution.
58 |
59 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
60 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
62 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
63 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
66 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
67 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
68 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 | `,
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/cobra/cmd/license_bsd_clause_3.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2015 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 | // Parts inspired by https://github.com/ryanuber/go-license
15 |
16 | package cmd
17 |
18 | func initBsdClause3() {
19 | Licenses["bsd"] = License{
20 | Name: "NewBSD",
21 | PossibleMatches: []string{"bsd", "newbsd", "3 clause bsd", "3-clause bsd"},
22 | Header: `All rights reserved.
23 |
24 | Redistribution and use in source and binary forms, with or without
25 | modification, are permitted provided that the following conditions are met:
26 |
27 | 1. Redistributions of source code must retain the above copyright notice,
28 | this list of conditions and the following disclaimer.
29 |
30 | 2. Redistributions in binary form must reproduce the above copyright notice,
31 | this list of conditions and the following disclaimer in the documentation
32 | and/or other materials provided with the distribution.
33 |
34 | 3. Neither the name of the copyright holder nor the names of its contributors
35 | may be used to endorse or promote products derived from this software
36 | without specific prior written permission.
37 |
38 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
42 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
43 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
44 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
46 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48 | POSSIBILITY OF SUCH DAMAGE.`,
49 | Text: `{{ .copyright }}
50 | All rights reserved.
51 |
52 | Redistribution and use in source and binary forms, with or without
53 | modification, are permitted provided that the following conditions are met:
54 |
55 | 1. Redistributions of source code must retain the above copyright notice,
56 | this list of conditions and the following disclaimer.
57 |
58 | 2. Redistributions in binary form must reproduce the above copyright notice,
59 | this list of conditions and the following disclaimer in the documentation
60 | and/or other materials provided with the distribution.
61 |
62 | 3. Neither the name of the copyright holder nor the names of its contributors
63 | may be used to endorse or promote products derived from this software
64 | without specific prior written permission.
65 |
66 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
67 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
69 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
70 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
72 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
73 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
74 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
75 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
76 | `,
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/cobra/cmd/license_mit.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2015 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 | // Parts inspired by https://github.com/ryanuber/go-license
15 |
16 | package cmd
17 |
18 | func initMit() {
19 | Licenses["mit"] = License{
20 | Name: "MIT License",
21 | PossibleMatches: []string{"mit"},
22 | Header: `
23 | Permission is hereby granted, free of charge, to any person obtaining a copy
24 | of this software and associated documentation files (the "Software"), to deal
25 | in the Software without restriction, including without limitation the rights
26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 | copies of the Software, and to permit persons to whom the Software is
28 | furnished to do so, subject to the following conditions:
29 |
30 | The above copyright notice and this permission notice shall be included in
31 | all copies or substantial portions of the Software.
32 |
33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 | THE SOFTWARE.`,
40 | Text: `The MIT License (MIT)
41 |
42 | {{ .copyright }}
43 |
44 | Permission is hereby granted, free of charge, to any person obtaining a copy
45 | of this software and associated documentation files (the "Software"), to deal
46 | in the Software without restriction, including without limitation the rights
47 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48 | copies of the Software, and to permit persons to whom the Software is
49 | furnished to do so, subject to the following conditions:
50 |
51 | The above copyright notice and this permission notice shall be included in
52 | all copies or substantial portions of the Software.
53 |
54 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
60 | THE SOFTWARE.
61 | `,
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go:
--------------------------------------------------------------------------------
1 | // Copyright © 2015 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 | // Parts inspired by https://github.com/ryanuber/go-license
15 |
16 | package cmd
17 |
18 | import (
19 | "strings"
20 | "time"
21 |
22 | "github.com/spf13/viper"
23 | )
24 |
25 | // Licenses contains all possible licenses a user can choose from.
26 | var Licenses = make(map[string]License)
27 |
28 | // License represents a software license agreement, containing the Name of
29 | // the license, its possible matches (on the command line as given to cobra),
30 | // the header to be used with each file on the file's creating, and the text
31 | // of the license
32 | type License struct {
33 | Name string // The type of license in use
34 | PossibleMatches []string // Similar names to guess
35 | Text string // License text data
36 | Header string // License header for source files
37 | }
38 |
39 | func init() {
40 | // Allows a user to not use a license.
41 | Licenses["none"] = License{"None", []string{"none", "false"}, "", ""}
42 |
43 | initApache2()
44 | initMit()
45 | initBsdClause3()
46 | initBsdClause2()
47 | initGpl2()
48 | initGpl3()
49 | initLgpl()
50 | initAgpl()
51 | }
52 |
53 | // getLicense returns license specified by user in flag or in config.
54 | // If user didn't specify the license, it returns Apache License 2.0.
55 | //
56 | // TODO: Inspect project for existing license
57 | func getLicense() License {
58 | // If explicitly flagged, use that.
59 | if userLicense != "" {
60 | return findLicense(userLicense)
61 | }
62 |
63 | // If user wants to have custom license, use that.
64 | if viper.IsSet("license.header") || viper.IsSet("license.text") {
65 | return License{Header: viper.GetString("license.header"),
66 | Text: viper.GetString("license.text")}
67 | }
68 |
69 | // If user wants to have built-in license, use that.
70 | if viper.IsSet("license") {
71 | return findLicense(viper.GetString("license"))
72 | }
73 |
74 | // If user didn't set any license, use Apache 2.0 by default.
75 | return Licenses["apache"]
76 | }
77 |
78 | func copyrightLine() string {
79 | author := viper.GetString("author")
80 |
81 | year := viper.GetString("year") // For tests.
82 | if year == "" {
83 | year = time.Now().Format("2006")
84 | }
85 |
86 | return "Copyright © " + year + " " + author
87 | }
88 |
89 | // findLicense looks for License object of built-in licenses.
90 | // If it didn't find license, then the app will be terminated and
91 | // error will be printed.
92 | func findLicense(name string) License {
93 | found := matchLicense(name)
94 | if found == "" {
95 | er("unknown license: " + name)
96 | }
97 | return Licenses[found]
98 | }
99 |
100 | // matchLicense compares the given a license name
101 | // to PossibleMatches of all built-in licenses.
102 | // It returns blank string, if name is blank string or it didn't find
103 | // then appropriate match to name.
104 | func matchLicense(name string) string {
105 | if name == "" {
106 | return ""
107 | }
108 |
109 | for key, lic := range Licenses {
110 | for _, match := range lic.PossibleMatches {
111 | if strings.EqualFold(name, match) {
112 | return key
113 | }
114 | }
115 | }
116 |
117 | return ""
118 | }
119 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/command_notwin.go:
--------------------------------------------------------------------------------
1 | // +build !windows
2 |
3 | package cobra
4 |
5 | var preExecHookFn func(*Command)
6 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/command_win.go:
--------------------------------------------------------------------------------
1 | // +build windows
2 |
3 | package cobra
4 |
5 | import (
6 | "os"
7 | "time"
8 |
9 | "github.com/inconshreveable/mousetrap"
10 | )
11 |
12 | var preExecHookFn = preExecHook
13 |
14 | func preExecHook(c *Command) {
15 | if MousetrapHelpText != "" && mousetrap.StartedByExplorer() {
16 | c.Print(MousetrapHelpText)
17 | time.Sleep(5 * time.Second)
18 | os.Exit(1)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/cobra/zsh_completions.go:
--------------------------------------------------------------------------------
1 | package cobra
2 |
3 | import (
4 | "bytes"
5 | "fmt"
6 | "io"
7 | "os"
8 | "strings"
9 | )
10 |
11 | // GenZshCompletionFile generates zsh completion file.
12 | func (c *Command) GenZshCompletionFile(filename string) error {
13 | outFile, err := os.Create(filename)
14 | if err != nil {
15 | return err
16 | }
17 | defer outFile.Close()
18 |
19 | return c.GenZshCompletion(outFile)
20 | }
21 |
22 | // GenZshCompletion generates a zsh completion file and writes to the passed writer.
23 | func (c *Command) GenZshCompletion(w io.Writer) error {
24 | buf := new(bytes.Buffer)
25 |
26 | writeHeader(buf, c)
27 | maxDepth := maxDepth(c)
28 | writeLevelMapping(buf, maxDepth)
29 | writeLevelCases(buf, maxDepth, c)
30 |
31 | _, err := buf.WriteTo(w)
32 | return err
33 | }
34 |
35 | func writeHeader(w io.Writer, cmd *Command) {
36 | fmt.Fprintf(w, "#compdef %s\n\n", cmd.Name())
37 | }
38 |
39 | func maxDepth(c *Command) int {
40 | if len(c.Commands()) == 0 {
41 | return 0
42 | }
43 | maxDepthSub := 0
44 | for _, s := range c.Commands() {
45 | subDepth := maxDepth(s)
46 | if subDepth > maxDepthSub {
47 | maxDepthSub = subDepth
48 | }
49 | }
50 | return 1 + maxDepthSub
51 | }
52 |
53 | func writeLevelMapping(w io.Writer, numLevels int) {
54 | fmt.Fprintln(w, `_arguments \`)
55 | for i := 1; i <= numLevels; i++ {
56 | fmt.Fprintf(w, ` '%d: :->level%d' \`, i, i)
57 | fmt.Fprintln(w)
58 | }
59 | fmt.Fprintf(w, ` '%d: :%s'`, numLevels+1, "_files")
60 | fmt.Fprintln(w)
61 | }
62 |
63 | func writeLevelCases(w io.Writer, maxDepth int, root *Command) {
64 | fmt.Fprintln(w, "case $state in")
65 | defer fmt.Fprintln(w, "esac")
66 |
67 | for i := 1; i <= maxDepth; i++ {
68 | fmt.Fprintf(w, " level%d)\n", i)
69 | writeLevel(w, root, i)
70 | fmt.Fprintln(w, " ;;")
71 | }
72 | fmt.Fprintln(w, " *)")
73 | fmt.Fprintln(w, " _arguments '*: :_files'")
74 | fmt.Fprintln(w, " ;;")
75 | }
76 |
77 | func writeLevel(w io.Writer, root *Command, i int) {
78 | fmt.Fprintf(w, " case $words[%d] in\n", i)
79 | defer fmt.Fprintln(w, " esac")
80 |
81 | commands := filterByLevel(root, i)
82 | byParent := groupByParent(commands)
83 |
84 | for p, c := range byParent {
85 | names := names(c)
86 | fmt.Fprintf(w, " %s)\n", p)
87 | fmt.Fprintf(w, " _arguments '%d: :(%s)'\n", i, strings.Join(names, " "))
88 | fmt.Fprintln(w, " ;;")
89 | }
90 | fmt.Fprintln(w, " *)")
91 | fmt.Fprintln(w, " _arguments '*: :_files'")
92 | fmt.Fprintln(w, " ;;")
93 |
94 | }
95 |
96 | func filterByLevel(c *Command, l int) []*Command {
97 | cs := make([]*Command, 0)
98 | if l == 0 {
99 | cs = append(cs, c)
100 | return cs
101 | }
102 | for _, s := range c.Commands() {
103 | cs = append(cs, filterByLevel(s, l-1)...)
104 | }
105 | return cs
106 | }
107 |
108 | func groupByParent(commands []*Command) map[string][]*Command {
109 | m := make(map[string][]*Command)
110 | for _, c := range commands {
111 | parent := c.Parent()
112 | if parent == nil {
113 | continue
114 | }
115 | m[parent.Name()] = append(m[parent.Name()], c)
116 | }
117 | return m
118 | }
119 |
120 | func names(commands []*Command) []string {
121 | ns := make([]string, len(commands))
122 | for i, c := range commands {
123 | ns[i] = c.Name()
124 | }
125 | return ns
126 | }
127 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/*
2 |
3 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 |
3 | language: go
4 |
5 | go:
6 | - 1.7.3
7 | - 1.8.1
8 | - tip
9 |
10 | matrix:
11 | allow_failures:
12 | - go: tip
13 |
14 | install:
15 | - go get github.com/golang/lint/golint
16 | - export PATH=$GOPATH/bin:$PATH
17 | - go install ./...
18 |
19 | script:
20 | - verify/all.sh -v
21 | - go test ./...
22 |
--------------------------------------------------------------------------------
/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 "strconv"
4 |
5 | // optional interface to indicate boolean flags that can be
6 | // supplied without "=value" text
7 | type boolFlag interface {
8 | Value
9 | IsBoolFlag() bool
10 | }
11 |
12 | // -- bool Value
13 | type boolValue bool
14 |
15 | func newBoolValue(val bool, p *bool) *boolValue {
16 | *p = val
17 | return (*boolValue)(p)
18 | }
19 |
20 | func (b *boolValue) Set(s string) error {
21 | v, err := strconv.ParseBool(s)
22 | *b = boolValue(v)
23 | return err
24 | }
25 |
26 | func (b *boolValue) Type() string {
27 | return "bool"
28 | }
29 |
30 | func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) }
31 |
32 | func (b *boolValue) IsBoolFlag() bool { return true }
33 |
34 | func boolConv(sval string) (interface{}, error) {
35 | return strconv.ParseBool(sval)
36 | }
37 |
38 | // GetBool return the bool value of a flag with the given name
39 | func (f *FlagSet) GetBool(name string) (bool, error) {
40 | val, err := f.getFlagType(name, "bool", boolConv)
41 | if err != nil {
42 | return false, err
43 | }
44 | return val.(bool), nil
45 | }
46 |
47 | // BoolVar defines a bool flag with specified name, default value, and usage string.
48 | // The argument p points to a bool variable in which to store the value of the flag.
49 | func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) {
50 | f.BoolVarP(p, name, "", value, usage)
51 | }
52 |
53 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
54 | func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
55 | flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage)
56 | flag.NoOptDefVal = "true"
57 | }
58 |
59 | // BoolVar defines a bool flag with specified name, default value, and usage string.
60 | // The argument p points to a bool variable in which to store the value of the flag.
61 | func BoolVar(p *bool, name string, value bool, usage string) {
62 | BoolVarP(p, name, "", value, usage)
63 | }
64 |
65 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
66 | func BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
67 | flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage)
68 | flag.NoOptDefVal = "true"
69 | }
70 |
71 | // Bool defines a bool flag with specified name, default value, and usage string.
72 | // The return value is the address of a bool variable that stores the value of the flag.
73 | func (f *FlagSet) Bool(name string, value bool, usage string) *bool {
74 | return f.BoolP(name, "", value, usage)
75 | }
76 |
77 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
78 | func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool {
79 | p := new(bool)
80 | f.BoolVarP(p, name, shorthand, value, usage)
81 | return p
82 | }
83 |
84 | // Bool defines a bool flag with specified name, default value, and usage string.
85 | // The return value is the address of a bool variable that stores the value of the flag.
86 | func Bool(name string, value bool, usage string) *bool {
87 | return BoolP(name, "", value, usage)
88 | }
89 |
90 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
91 | func BoolP(name, shorthand string, value bool, usage string) *bool {
92 | b := CommandLine.BoolP(name, shorthand, value, usage)
93 | return b
94 | }
95 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/count.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- count Value
6 | type countValue int
7 |
8 | func newCountValue(val int, p *int) *countValue {
9 | *p = val
10 | return (*countValue)(p)
11 | }
12 |
13 | func (i *countValue) Set(s string) error {
14 | v, err := strconv.ParseInt(s, 0, 64)
15 | // -1 means that no specific value was passed, so increment
16 | if v == -1 {
17 | *i = countValue(*i + 1)
18 | } else {
19 | *i = countValue(v)
20 | }
21 | return err
22 | }
23 |
24 | func (i *countValue) Type() string {
25 | return "count"
26 | }
27 |
28 | func (i *countValue) String() string { return strconv.Itoa(int(*i)) }
29 |
30 | func countConv(sval string) (interface{}, error) {
31 | i, err := strconv.Atoi(sval)
32 | if err != nil {
33 | return nil, err
34 | }
35 | return i, nil
36 | }
37 |
38 | // GetCount return the int value of a flag with the given name
39 | func (f *FlagSet) GetCount(name string) (int, error) {
40 | val, err := f.getFlagType(name, "count", countConv)
41 | if err != nil {
42 | return 0, err
43 | }
44 | return val.(int), nil
45 | }
46 |
47 | // CountVar defines a count flag with specified name, default value, and usage string.
48 | // The argument p points to an int variable in which to store the value of the flag.
49 | // A count flag will add 1 to its value evey time it is found on the command line
50 | func (f *FlagSet) CountVar(p *int, name string, usage string) {
51 | f.CountVarP(p, name, "", usage)
52 | }
53 |
54 | // CountVarP is like CountVar only take a shorthand for the flag name.
55 | func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) {
56 | flag := f.VarPF(newCountValue(0, p), name, shorthand, usage)
57 | flag.NoOptDefVal = "-1"
58 | }
59 |
60 | // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set
61 | func CountVar(p *int, name string, usage string) {
62 | CommandLine.CountVar(p, name, usage)
63 | }
64 |
65 | // CountVarP is like CountVar only take a shorthand for the flag name.
66 | func CountVarP(p *int, name, shorthand string, usage string) {
67 | CommandLine.CountVarP(p, name, shorthand, usage)
68 | }
69 |
70 | // Count defines a count flag with specified name, default value, and usage string.
71 | // The return value is the address of an int variable that stores the value of the flag.
72 | // A count flag will add 1 to its value evey time it is found on the command line
73 | func (f *FlagSet) Count(name string, usage string) *int {
74 | p := new(int)
75 | f.CountVarP(p, name, "", usage)
76 | return p
77 | }
78 |
79 | // CountP is like Count only takes a shorthand for the flag name.
80 | func (f *FlagSet) CountP(name, shorthand string, usage string) *int {
81 | p := new(int)
82 | f.CountVarP(p, name, shorthand, usage)
83 | return p
84 | }
85 |
86 | // Count defines a count flag with specified name, default value, and usage string.
87 | // The return value is the address of an int variable that stores the value of the flag.
88 | // A count flag will add 1 to its value evey time it is found on the command line
89 | func Count(name string, usage string) *int {
90 | return CommandLine.CountP(name, "", usage)
91 | }
92 |
93 | // CountP is like Count only takes a shorthand for the flag name.
94 | func CountP(name, shorthand string, usage string) *int {
95 | return CommandLine.CountP(name, shorthand, usage)
96 | }
97 |
--------------------------------------------------------------------------------
/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 | // DurationVarP is 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 | // DurationVarP is 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 | // DurationP is 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 | // DurationP is 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 "strconv"
4 |
5 | // -- float32 Value
6 | type float32Value float32
7 |
8 | func newFloat32Value(val float32, p *float32) *float32Value {
9 | *p = val
10 | return (*float32Value)(p)
11 | }
12 |
13 | func (f *float32Value) Set(s string) error {
14 | v, err := strconv.ParseFloat(s, 32)
15 | *f = float32Value(v)
16 | return err
17 | }
18 |
19 | func (f *float32Value) Type() string {
20 | return "float32"
21 | }
22 |
23 | func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) }
24 |
25 | func float32Conv(sval string) (interface{}, error) {
26 | v, err := strconv.ParseFloat(sval, 32)
27 | if err != nil {
28 | return 0, err
29 | }
30 | return float32(v), nil
31 | }
32 |
33 | // GetFloat32 return the float32 value of a flag with the given name
34 | func (f *FlagSet) GetFloat32(name string) (float32, error) {
35 | val, err := f.getFlagType(name, "float32", float32Conv)
36 | if err != nil {
37 | return 0, err
38 | }
39 | return val.(float32), nil
40 | }
41 |
42 | // Float32Var defines a float32 flag with specified name, default value, and usage string.
43 | // The argument p points to a float32 variable in which to store the value of the flag.
44 | func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) {
45 | f.VarP(newFloat32Value(value, p), name, "", usage)
46 | }
47 |
48 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
49 | func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
50 | f.VarP(newFloat32Value(value, p), name, shorthand, usage)
51 | }
52 |
53 | // Float32Var defines a float32 flag with specified name, default value, and usage string.
54 | // The argument p points to a float32 variable in which to store the value of the flag.
55 | func Float32Var(p *float32, name string, value float32, usage string) {
56 | CommandLine.VarP(newFloat32Value(value, p), name, "", usage)
57 | }
58 |
59 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
60 | func Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
61 | CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage)
62 | }
63 |
64 | // Float32 defines a float32 flag with specified name, default value, and usage string.
65 | // The return value is the address of a float32 variable that stores the value of the flag.
66 | func (f *FlagSet) Float32(name string, value float32, usage string) *float32 {
67 | p := new(float32)
68 | f.Float32VarP(p, name, "", value, usage)
69 | return p
70 | }
71 |
72 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
73 | func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 {
74 | p := new(float32)
75 | f.Float32VarP(p, name, shorthand, value, usage)
76 | return p
77 | }
78 |
79 | // Float32 defines a float32 flag with specified name, default value, and usage string.
80 | // The return value is the address of a float32 variable that stores the value of the flag.
81 | func Float32(name string, value float32, usage string) *float32 {
82 | return CommandLine.Float32P(name, "", value, usage)
83 | }
84 |
85 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
86 | func Float32P(name, shorthand string, value float32, usage string) *float32 {
87 | return CommandLine.Float32P(name, shorthand, value, usage)
88 | }
89 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/float64.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- float64 Value
6 | type float64Value float64
7 |
8 | func newFloat64Value(val float64, p *float64) *float64Value {
9 | *p = val
10 | return (*float64Value)(p)
11 | }
12 |
13 | func (f *float64Value) Set(s string) error {
14 | v, err := strconv.ParseFloat(s, 64)
15 | *f = float64Value(v)
16 | return err
17 | }
18 |
19 | func (f *float64Value) Type() string {
20 | return "float64"
21 | }
22 |
23 | func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) }
24 |
25 | func float64Conv(sval string) (interface{}, error) {
26 | return strconv.ParseFloat(sval, 64)
27 | }
28 |
29 | // GetFloat64 return the float64 value of a flag with the given name
30 | func (f *FlagSet) GetFloat64(name string) (float64, error) {
31 | val, err := f.getFlagType(name, "float64", float64Conv)
32 | if err != nil {
33 | return 0, err
34 | }
35 | return val.(float64), nil
36 | }
37 |
38 | // Float64Var defines a float64 flag with specified name, default value, and usage string.
39 | // The argument p points to a float64 variable in which to store the value of the flag.
40 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) {
41 | f.VarP(newFloat64Value(value, p), name, "", usage)
42 | }
43 |
44 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
45 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
46 | f.VarP(newFloat64Value(value, p), name, shorthand, usage)
47 | }
48 |
49 | // Float64Var defines a float64 flag with specified name, default value, and usage string.
50 | // The argument p points to a float64 variable in which to store the value of the flag.
51 | func Float64Var(p *float64, name string, value float64, usage string) {
52 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage)
53 | }
54 |
55 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
56 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
57 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage)
58 | }
59 |
60 | // Float64 defines a float64 flag with specified name, default value, and usage string.
61 | // The return value is the address of a float64 variable that stores the value of the flag.
62 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 {
63 | p := new(float64)
64 | f.Float64VarP(p, name, "", value, usage)
65 | return p
66 | }
67 |
68 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
69 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 {
70 | p := new(float64)
71 | f.Float64VarP(p, name, shorthand, value, usage)
72 | return p
73 | }
74 |
75 | // Float64 defines a float64 flag with specified name, default value, and usage string.
76 | // The return value is the address of a float64 variable that stores the value of the flag.
77 | func Float64(name string, value float64, usage string) *float64 {
78 | return CommandLine.Float64P(name, "", value, usage)
79 | }
80 |
81 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
82 | func Float64P(name, shorthand string, value float64, usage string) *float64 {
83 | return CommandLine.Float64P(name, shorthand, value, usage)
84 | }
85 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/golangflag.go:
--------------------------------------------------------------------------------
1 | // Copyright 2009 The Go 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 pflag
6 |
7 | import (
8 | goflag "flag"
9 | "reflect"
10 | "strings"
11 | )
12 |
13 | // flagValueWrapper implements pflag.Value around a flag.Value. The main
14 | // difference here is the addition of the Type method that returns a string
15 | // name of the type. As this is generally unknown, we approximate that with
16 | // reflection.
17 | type flagValueWrapper struct {
18 | inner goflag.Value
19 | flagType string
20 | }
21 |
22 | // We are just copying the boolFlag interface out of goflag as that is what
23 | // they use to decide if a flag should get "true" when no arg is given.
24 | type goBoolFlag interface {
25 | goflag.Value
26 | IsBoolFlag() bool
27 | }
28 |
29 | func wrapFlagValue(v goflag.Value) Value {
30 | // If the flag.Value happens to also be a pflag.Value, just use it directly.
31 | if pv, ok := v.(Value); ok {
32 | return pv
33 | }
34 |
35 | pv := &flagValueWrapper{
36 | inner: v,
37 | }
38 |
39 | t := reflect.TypeOf(v)
40 | if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr {
41 | t = t.Elem()
42 | }
43 |
44 | pv.flagType = strings.TrimSuffix(t.Name(), "Value")
45 | return pv
46 | }
47 |
48 | func (v *flagValueWrapper) String() string {
49 | return v.inner.String()
50 | }
51 |
52 | func (v *flagValueWrapper) Set(s string) error {
53 | return v.inner.Set(s)
54 | }
55 |
56 | func (v *flagValueWrapper) Type() string {
57 | return v.flagType
58 | }
59 |
60 | // PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag
61 | // If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei
62 | // with both `-v` and `--v` in flags. If the golang flag was more than a single
63 | // character (ex: `verbose`) it will only be accessible via `--verbose`
64 | func PFlagFromGoFlag(goflag *goflag.Flag) *Flag {
65 | // Remember the default value as a string; it won't change.
66 | flag := &Flag{
67 | Name: goflag.Name,
68 | Usage: goflag.Usage,
69 | Value: wrapFlagValue(goflag.Value),
70 | // Looks like golang flags don't set DefValue correctly :-(
71 | //DefValue: goflag.DefValue,
72 | DefValue: goflag.Value.String(),
73 | }
74 | // Ex: if the golang flag was -v, allow both -v and --v to work
75 | if len(flag.Name) == 1 {
76 | flag.Shorthand = flag.Name
77 | }
78 | if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() {
79 | flag.NoOptDefVal = "true"
80 | }
81 | return flag
82 | }
83 |
84 | // AddGoFlag will add the given *flag.Flag to the pflag.FlagSet
85 | func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) {
86 | if f.Lookup(goflag.Name) != nil {
87 | return
88 | }
89 | newflag := PFlagFromGoFlag(goflag)
90 | f.AddFlag(newflag)
91 | }
92 |
93 | // AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet
94 | func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) {
95 | if newSet == nil {
96 | return
97 | }
98 | newSet.VisitAll(func(goflag *goflag.Flag) {
99 | f.AddGoFlag(goflag)
100 | })
101 | }
102 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/int.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- int Value
6 | type intValue int
7 |
8 | func newIntValue(val int, p *int) *intValue {
9 | *p = val
10 | return (*intValue)(p)
11 | }
12 |
13 | func (i *intValue) Set(s string) error {
14 | v, err := strconv.ParseInt(s, 0, 64)
15 | *i = intValue(v)
16 | return err
17 | }
18 |
19 | func (i *intValue) Type() string {
20 | return "int"
21 | }
22 |
23 | func (i *intValue) String() string { return strconv.Itoa(int(*i)) }
24 |
25 | func intConv(sval string) (interface{}, error) {
26 | return strconv.Atoi(sval)
27 | }
28 |
29 | // GetInt return the int value of a flag with the given name
30 | func (f *FlagSet) GetInt(name string) (int, error) {
31 | val, err := f.getFlagType(name, "int", intConv)
32 | if err != nil {
33 | return 0, err
34 | }
35 | return val.(int), nil
36 | }
37 |
38 | // IntVar defines an int flag with specified name, default value, and usage string.
39 | // The argument p points to an int variable in which to store the value of the flag.
40 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) {
41 | f.VarP(newIntValue(value, p), name, "", usage)
42 | }
43 |
44 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
45 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) {
46 | f.VarP(newIntValue(value, p), name, shorthand, usage)
47 | }
48 |
49 | // IntVar defines an int flag with specified name, default value, and usage string.
50 | // The argument p points to an int variable in which to store the value of the flag.
51 | func IntVar(p *int, name string, value int, usage string) {
52 | CommandLine.VarP(newIntValue(value, p), name, "", usage)
53 | }
54 |
55 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
56 | func IntVarP(p *int, name, shorthand string, value int, usage string) {
57 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage)
58 | }
59 |
60 | // Int defines an int flag with specified name, default value, and usage string.
61 | // The return value is the address of an int variable that stores the value of the flag.
62 | func (f *FlagSet) Int(name string, value int, usage string) *int {
63 | p := new(int)
64 | f.IntVarP(p, name, "", value, usage)
65 | return p
66 | }
67 |
68 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
69 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int {
70 | p := new(int)
71 | f.IntVarP(p, name, shorthand, value, usage)
72 | return p
73 | }
74 |
75 | // Int defines an int flag with specified name, default value, and usage string.
76 | // The return value is the address of an int variable that stores the value of the flag.
77 | func Int(name string, value int, usage string) *int {
78 | return CommandLine.IntP(name, "", value, usage)
79 | }
80 |
81 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
82 | func IntP(name, shorthand string, value int, usage string) *int {
83 | return CommandLine.IntP(name, shorthand, value, usage)
84 | }
85 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/int32.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- int32 Value
6 | type int32Value int32
7 |
8 | func newInt32Value(val int32, p *int32) *int32Value {
9 | *p = val
10 | return (*int32Value)(p)
11 | }
12 |
13 | func (i *int32Value) Set(s string) error {
14 | v, err := strconv.ParseInt(s, 0, 32)
15 | *i = int32Value(v)
16 | return err
17 | }
18 |
19 | func (i *int32Value) Type() string {
20 | return "int32"
21 | }
22 |
23 | func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) }
24 |
25 | func int32Conv(sval string) (interface{}, error) {
26 | v, err := strconv.ParseInt(sval, 0, 32)
27 | if err != nil {
28 | return 0, err
29 | }
30 | return int32(v), nil
31 | }
32 |
33 | // GetInt32 return the int32 value of a flag with the given name
34 | func (f *FlagSet) GetInt32(name string) (int32, error) {
35 | val, err := f.getFlagType(name, "int32", int32Conv)
36 | if err != nil {
37 | return 0, err
38 | }
39 | return val.(int32), nil
40 | }
41 |
42 | // Int32Var defines an int32 flag with specified name, default value, and usage string.
43 | // The argument p points to an int32 variable in which to store the value of the flag.
44 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) {
45 | f.VarP(newInt32Value(value, p), name, "", usage)
46 | }
47 |
48 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
49 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) {
50 | f.VarP(newInt32Value(value, p), name, shorthand, usage)
51 | }
52 |
53 | // Int32Var defines an int32 flag with specified name, default value, and usage string.
54 | // The argument p points to an int32 variable in which to store the value of the flag.
55 | func Int32Var(p *int32, name string, value int32, usage string) {
56 | CommandLine.VarP(newInt32Value(value, p), name, "", usage)
57 | }
58 |
59 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
60 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) {
61 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage)
62 | }
63 |
64 | // Int32 defines an int32 flag with specified name, default value, and usage string.
65 | // The return value is the address of an int32 variable that stores the value of the flag.
66 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 {
67 | p := new(int32)
68 | f.Int32VarP(p, name, "", value, usage)
69 | return p
70 | }
71 |
72 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
73 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 {
74 | p := new(int32)
75 | f.Int32VarP(p, name, shorthand, value, usage)
76 | return p
77 | }
78 |
79 | // Int32 defines an int32 flag with specified name, default value, and usage string.
80 | // The return value is the address of an int32 variable that stores the value of the flag.
81 | func Int32(name string, value int32, usage string) *int32 {
82 | return CommandLine.Int32P(name, "", value, usage)
83 | }
84 |
85 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
86 | func Int32P(name, shorthand string, value int32, usage string) *int32 {
87 | return CommandLine.Int32P(name, shorthand, value, usage)
88 | }
89 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/int64.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- int64 Value
6 | type int64Value int64
7 |
8 | func newInt64Value(val int64, p *int64) *int64Value {
9 | *p = val
10 | return (*int64Value)(p)
11 | }
12 |
13 | func (i *int64Value) Set(s string) error {
14 | v, err := strconv.ParseInt(s, 0, 64)
15 | *i = int64Value(v)
16 | return err
17 | }
18 |
19 | func (i *int64Value) Type() string {
20 | return "int64"
21 | }
22 |
23 | func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) }
24 |
25 | func int64Conv(sval string) (interface{}, error) {
26 | return strconv.ParseInt(sval, 0, 64)
27 | }
28 |
29 | // GetInt64 return the int64 value of a flag with the given name
30 | func (f *FlagSet) GetInt64(name string) (int64, error) {
31 | val, err := f.getFlagType(name, "int64", int64Conv)
32 | if err != nil {
33 | return 0, err
34 | }
35 | return val.(int64), nil
36 | }
37 |
38 | // Int64Var defines an int64 flag with specified name, default value, and usage string.
39 | // The argument p points to an int64 variable in which to store the value of the flag.
40 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) {
41 | f.VarP(newInt64Value(value, p), name, "", usage)
42 | }
43 |
44 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
45 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) {
46 | f.VarP(newInt64Value(value, p), name, shorthand, usage)
47 | }
48 |
49 | // Int64Var defines an int64 flag with specified name, default value, and usage string.
50 | // The argument p points to an int64 variable in which to store the value of the flag.
51 | func Int64Var(p *int64, name string, value int64, usage string) {
52 | CommandLine.VarP(newInt64Value(value, p), name, "", usage)
53 | }
54 |
55 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
56 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) {
57 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage)
58 | }
59 |
60 | // Int64 defines an int64 flag with specified name, default value, and usage string.
61 | // The return value is the address of an int64 variable that stores the value of the flag.
62 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 {
63 | p := new(int64)
64 | f.Int64VarP(p, name, "", value, usage)
65 | return p
66 | }
67 |
68 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
69 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 {
70 | p := new(int64)
71 | f.Int64VarP(p, name, shorthand, value, usage)
72 | return p
73 | }
74 |
75 | // Int64 defines an int64 flag with specified name, default value, and usage string.
76 | // The return value is the address of an int64 variable that stores the value of the flag.
77 | func Int64(name string, value int64, usage string) *int64 {
78 | return CommandLine.Int64P(name, "", value, usage)
79 | }
80 |
81 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
82 | func Int64P(name, shorthand string, value int64, usage string) *int64 {
83 | return CommandLine.Int64P(name, shorthand, value, usage)
84 | }
85 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/int8.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- int8 Value
6 | type int8Value int8
7 |
8 | func newInt8Value(val int8, p *int8) *int8Value {
9 | *p = val
10 | return (*int8Value)(p)
11 | }
12 |
13 | func (i *int8Value) Set(s string) error {
14 | v, err := strconv.ParseInt(s, 0, 8)
15 | *i = int8Value(v)
16 | return err
17 | }
18 |
19 | func (i *int8Value) Type() string {
20 | return "int8"
21 | }
22 |
23 | func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) }
24 |
25 | func int8Conv(sval string) (interface{}, error) {
26 | v, err := strconv.ParseInt(sval, 0, 8)
27 | if err != nil {
28 | return 0, err
29 | }
30 | return int8(v), nil
31 | }
32 |
33 | // GetInt8 return the int8 value of a flag with the given name
34 | func (f *FlagSet) GetInt8(name string) (int8, error) {
35 | val, err := f.getFlagType(name, "int8", int8Conv)
36 | if err != nil {
37 | return 0, err
38 | }
39 | return val.(int8), nil
40 | }
41 |
42 | // Int8Var defines an int8 flag with specified name, default value, and usage string.
43 | // The argument p points to an int8 variable in which to store the value of the flag.
44 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) {
45 | f.VarP(newInt8Value(value, p), name, "", usage)
46 | }
47 |
48 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
49 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
50 | f.VarP(newInt8Value(value, p), name, shorthand, usage)
51 | }
52 |
53 | // Int8Var defines an int8 flag with specified name, default value, and usage string.
54 | // The argument p points to an int8 variable in which to store the value of the flag.
55 | func Int8Var(p *int8, name string, value int8, usage string) {
56 | CommandLine.VarP(newInt8Value(value, p), name, "", usage)
57 | }
58 |
59 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
60 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
61 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage)
62 | }
63 |
64 | // Int8 defines an int8 flag with specified name, default value, and usage string.
65 | // The return value is the address of an int8 variable that stores the value of the flag.
66 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 {
67 | p := new(int8)
68 | f.Int8VarP(p, name, "", value, usage)
69 | return p
70 | }
71 |
72 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
73 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 {
74 | p := new(int8)
75 | f.Int8VarP(p, name, shorthand, value, usage)
76 | return p
77 | }
78 |
79 | // Int8 defines an int8 flag with specified name, default value, and usage string.
80 | // The return value is the address of an int8 variable that stores the value of the flag.
81 | func Int8(name string, value int8, usage string) *int8 {
82 | return CommandLine.Int8P(name, "", value, usage)
83 | }
84 |
85 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
86 | func Int8P(name, shorthand string, value int8, usage string) *int8 {
87 | return CommandLine.Int8P(name, shorthand, value, usage)
88 | }
89 |
--------------------------------------------------------------------------------
/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 struct {
11 | value *[]int
12 | changed bool
13 | }
14 |
15 | func newIntSliceValue(val []int, p *[]int) *intSliceValue {
16 | isv := new(intSliceValue)
17 | isv.value = p
18 | *isv.value = val
19 | return isv
20 | }
21 |
22 | func (s *intSliceValue) Set(val string) error {
23 | ss := strings.Split(val, ",")
24 | out := make([]int, len(ss))
25 | for i, d := range ss {
26 | var err error
27 | out[i], err = strconv.Atoi(d)
28 | if err != nil {
29 | return err
30 | }
31 |
32 | }
33 | if !s.changed {
34 | *s.value = out
35 | } else {
36 | *s.value = append(*s.value, out...)
37 | }
38 | s.changed = true
39 | return nil
40 | }
41 |
42 | func (s *intSliceValue) Type() string {
43 | return "intSlice"
44 | }
45 |
46 | func (s *intSliceValue) String() string {
47 | out := make([]string, len(*s.value))
48 | for i, d := range *s.value {
49 | out[i] = fmt.Sprintf("%d", d)
50 | }
51 | return "[" + strings.Join(out, ",") + "]"
52 | }
53 |
54 | func intSliceConv(val string) (interface{}, error) {
55 | val = strings.Trim(val, "[]")
56 | // Empty string would cause a slice with one (empty) entry
57 | if len(val) == 0 {
58 | return []int{}, nil
59 | }
60 | ss := strings.Split(val, ",")
61 | out := make([]int, len(ss))
62 | for i, d := range ss {
63 | var err error
64 | out[i], err = strconv.Atoi(d)
65 | if err != nil {
66 | return nil, err
67 | }
68 |
69 | }
70 | return out, nil
71 | }
72 |
73 | // GetIntSlice return the []int value of a flag with the given name
74 | func (f *FlagSet) GetIntSlice(name string) ([]int, error) {
75 | val, err := f.getFlagType(name, "intSlice", intSliceConv)
76 | if err != nil {
77 | return []int{}, err
78 | }
79 | return val.([]int), nil
80 | }
81 |
82 | // IntSliceVar defines a intSlice flag with specified name, default value, and usage string.
83 | // The argument p points to a []int variable in which to store the value of the flag.
84 | func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string) {
85 | f.VarP(newIntSliceValue(value, p), name, "", usage)
86 | }
87 |
88 | // IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
89 | func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) {
90 | f.VarP(newIntSliceValue(value, p), name, shorthand, usage)
91 | }
92 |
93 | // IntSliceVar defines a int[] flag with specified name, default value, and usage string.
94 | // The argument p points to a int[] variable in which to store the value of the flag.
95 | func IntSliceVar(p *[]int, name string, value []int, usage string) {
96 | CommandLine.VarP(newIntSliceValue(value, p), name, "", usage)
97 | }
98 |
99 | // IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
100 | func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) {
101 | CommandLine.VarP(newIntSliceValue(value, p), name, shorthand, usage)
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 (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int {
107 | p := []int{}
108 | f.IntSliceVarP(&p, name, "", value, usage)
109 | return &p
110 | }
111 |
112 | // IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
113 | func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int {
114 | p := []int{}
115 | f.IntSliceVarP(&p, name, shorthand, value, usage)
116 | return &p
117 | }
118 |
119 | // IntSlice defines a []int flag with specified name, default value, and usage string.
120 | // The return value is the address of a []int variable that stores the value of the flag.
121 | func IntSlice(name string, value []int, usage string) *[]int {
122 | return CommandLine.IntSliceP(name, "", value, usage)
123 | }
124 |
125 | // IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
126 | func IntSliceP(name, shorthand string, value []int, usage string) *[]int {
127 | return CommandLine.IntSliceP(name, shorthand, value, usage)
128 | }
129 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/ip.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "net"
6 | "strings"
7 | )
8 |
9 | // -- net.IP value
10 | type ipValue net.IP
11 |
12 | func newIPValue(val net.IP, p *net.IP) *ipValue {
13 | *p = val
14 | return (*ipValue)(p)
15 | }
16 |
17 | func (i *ipValue) String() string { return net.IP(*i).String() }
18 | func (i *ipValue) Set(s string) error {
19 | ip := net.ParseIP(strings.TrimSpace(s))
20 | if ip == nil {
21 | return fmt.Errorf("failed to parse IP: %q", s)
22 | }
23 | *i = ipValue(ip)
24 | return nil
25 | }
26 |
27 | func (i *ipValue) Type() string {
28 | return "ip"
29 | }
30 |
31 | func ipConv(sval string) (interface{}, error) {
32 | ip := net.ParseIP(sval)
33 | if ip != nil {
34 | return ip, nil
35 | }
36 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval)
37 | }
38 |
39 | // GetIP return the net.IP value of a flag with the given name
40 | func (f *FlagSet) GetIP(name string) (net.IP, error) {
41 | val, err := f.getFlagType(name, "ip", ipConv)
42 | if err != nil {
43 | return nil, err
44 | }
45 | return val.(net.IP), nil
46 | }
47 |
48 | // IPVar defines an net.IP flag with specified name, default value, and usage string.
49 | // The argument p points to an net.IP variable in which to store the value of the flag.
50 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) {
51 | f.VarP(newIPValue(value, p), name, "", usage)
52 | }
53 |
54 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
55 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
56 | f.VarP(newIPValue(value, p), name, shorthand, usage)
57 | }
58 |
59 | // IPVar defines an net.IP flag with specified name, default value, and usage string.
60 | // The argument p points to an net.IP variable in which to store the value of the flag.
61 | func IPVar(p *net.IP, name string, value net.IP, usage string) {
62 | CommandLine.VarP(newIPValue(value, p), name, "", usage)
63 | }
64 |
65 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
66 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
67 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage)
68 | }
69 |
70 | // IP defines an net.IP flag with specified name, default value, and usage string.
71 | // The return value is the address of an net.IP variable that stores the value of the flag.
72 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP {
73 | p := new(net.IP)
74 | f.IPVarP(p, name, "", value, usage)
75 | return p
76 | }
77 |
78 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
79 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP {
80 | p := new(net.IP)
81 | f.IPVarP(p, name, shorthand, value, usage)
82 | return p
83 | }
84 |
85 | // IP defines an net.IP flag with specified name, default value, and usage string.
86 | // The return value is the address of an net.IP variable that stores the value of the flag.
87 | func IP(name string, value net.IP, usage string) *net.IP {
88 | return CommandLine.IPP(name, "", value, usage)
89 | }
90 |
91 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
92 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP {
93 | return CommandLine.IPP(name, shorthand, value, usage)
94 | }
95 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/ipnet.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import (
4 | "fmt"
5 | "net"
6 | "strings"
7 | )
8 |
9 | // IPNet adapts net.IPNet for use as a flag.
10 | type ipNetValue net.IPNet
11 |
12 | func (ipnet ipNetValue) String() string {
13 | n := net.IPNet(ipnet)
14 | return n.String()
15 | }
16 |
17 | func (ipnet *ipNetValue) Set(value string) error {
18 | _, n, err := net.ParseCIDR(strings.TrimSpace(value))
19 | if err != nil {
20 | return err
21 | }
22 | *ipnet = ipNetValue(*n)
23 | return nil
24 | }
25 |
26 | func (*ipNetValue) Type() string {
27 | return "ipNet"
28 | }
29 |
30 | func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue {
31 | *p = val
32 | return (*ipNetValue)(p)
33 | }
34 |
35 | func ipNetConv(sval string) (interface{}, error) {
36 | _, n, err := net.ParseCIDR(strings.TrimSpace(sval))
37 | if err == nil {
38 | return *n, nil
39 | }
40 | return nil, fmt.Errorf("invalid string being converted to IPNet: %s", sval)
41 | }
42 |
43 | // GetIPNet return the net.IPNet value of a flag with the given name
44 | func (f *FlagSet) GetIPNet(name string) (net.IPNet, error) {
45 | val, err := f.getFlagType(name, "ipNet", ipNetConv)
46 | if err != nil {
47 | return net.IPNet{}, err
48 | }
49 | return val.(net.IPNet), nil
50 | }
51 |
52 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string.
53 | // The argument p points to an net.IPNet variable in which to store the value of the flag.
54 | func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) {
55 | f.VarP(newIPNetValue(value, p), name, "", usage)
56 | }
57 |
58 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
59 | func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) {
60 | f.VarP(newIPNetValue(value, p), name, shorthand, usage)
61 | }
62 |
63 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string.
64 | // The argument p points to an net.IPNet variable in which to store the value of the flag.
65 | func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) {
66 | CommandLine.VarP(newIPNetValue(value, p), name, "", usage)
67 | }
68 |
69 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
70 | func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) {
71 | CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage)
72 | }
73 |
74 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string.
75 | // The return value is the address of an net.IPNet variable that stores the value of the flag.
76 | func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet {
77 | p := new(net.IPNet)
78 | f.IPNetVarP(p, name, "", value, usage)
79 | return p
80 | }
81 |
82 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
83 | func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet {
84 | p := new(net.IPNet)
85 | f.IPNetVarP(p, name, shorthand, value, usage)
86 | return p
87 | }
88 |
89 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string.
90 | // The return value is the address of an net.IPNet variable that stores the value of the flag.
91 | func IPNet(name string, value net.IPNet, usage string) *net.IPNet {
92 | return CommandLine.IPNetP(name, "", value, usage)
93 | }
94 |
95 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
96 | func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet {
97 | return CommandLine.IPNetP(name, shorthand, value, usage)
98 | }
99 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/string.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | // -- string Value
4 | type stringValue string
5 |
6 | func newStringValue(val string, p *string) *stringValue {
7 | *p = val
8 | return (*stringValue)(p)
9 | }
10 |
11 | func (s *stringValue) Set(val string) error {
12 | *s = stringValue(val)
13 | return nil
14 | }
15 | func (s *stringValue) Type() string {
16 | return "string"
17 | }
18 |
19 | func (s *stringValue) String() string { return string(*s) }
20 |
21 | func stringConv(sval string) (interface{}, error) {
22 | return sval, nil
23 | }
24 |
25 | // GetString return the string value of a flag with the given name
26 | func (f *FlagSet) GetString(name string) (string, error) {
27 | val, err := f.getFlagType(name, "string", stringConv)
28 | if err != nil {
29 | return "", err
30 | }
31 | return val.(string), nil
32 | }
33 |
34 | // StringVar defines a string flag with specified name, default value, and usage string.
35 | // The argument p points to a string variable in which to store the value of the flag.
36 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) {
37 | f.VarP(newStringValue(value, p), name, "", usage)
38 | }
39 |
40 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
41 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) {
42 | f.VarP(newStringValue(value, p), name, shorthand, usage)
43 | }
44 |
45 | // StringVar defines a string flag with specified name, default value, and usage string.
46 | // The argument p points to a string variable in which to store the value of the flag.
47 | func StringVar(p *string, name string, value string, usage string) {
48 | CommandLine.VarP(newStringValue(value, p), name, "", usage)
49 | }
50 |
51 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
52 | func StringVarP(p *string, name, shorthand string, value string, usage string) {
53 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage)
54 | }
55 |
56 | // String defines a string flag with specified name, default value, and usage string.
57 | // The return value is the address of a string variable that stores the value of the flag.
58 | func (f *FlagSet) String(name string, value string, usage string) *string {
59 | p := new(string)
60 | f.StringVarP(p, name, "", value, usage)
61 | return p
62 | }
63 |
64 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash.
65 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string {
66 | p := new(string)
67 | f.StringVarP(p, name, shorthand, value, usage)
68 | return p
69 | }
70 |
71 | // String defines a string flag with specified name, default value, and usage string.
72 | // The return value is the address of a string variable that stores the value of the flag.
73 | func String(name string, value string, usage string) *string {
74 | return CommandLine.StringP(name, "", value, usage)
75 | }
76 |
77 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash.
78 | func StringP(name, shorthand string, value string, usage string) *string {
79 | return CommandLine.StringP(name, shorthand, value, usage)
80 | }
81 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/string_array.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | // -- stringArray Value
4 | type stringArrayValue struct {
5 | value *[]string
6 | changed bool
7 | }
8 |
9 | func newStringArrayValue(val []string, p *[]string) *stringArrayValue {
10 | ssv := new(stringArrayValue)
11 | ssv.value = p
12 | *ssv.value = val
13 | return ssv
14 | }
15 |
16 | func (s *stringArrayValue) Set(val string) error {
17 | if !s.changed {
18 | *s.value = []string{val}
19 | s.changed = true
20 | } else {
21 | *s.value = append(*s.value, val)
22 | }
23 | return nil
24 | }
25 |
26 | func (s *stringArrayValue) Type() string {
27 | return "stringArray"
28 | }
29 |
30 | func (s *stringArrayValue) String() string {
31 | str, _ := writeAsCSV(*s.value)
32 | return "[" + str + "]"
33 | }
34 |
35 | func stringArrayConv(sval string) (interface{}, error) {
36 | sval = sval[1 : len(sval)-1]
37 | // An empty string would cause a array with one (empty) string
38 | if len(sval) == 0 {
39 | return []string{}, nil
40 | }
41 | return readAsCSV(sval)
42 | }
43 |
44 | // GetStringArray return the []string value of a flag with the given name
45 | func (f *FlagSet) GetStringArray(name string) ([]string, error) {
46 | val, err := f.getFlagType(name, "stringArray", stringArrayConv)
47 | if err != nil {
48 | return []string{}, err
49 | }
50 | return val.([]string), nil
51 | }
52 |
53 | // StringArrayVar defines a string flag with specified name, default value, and usage string.
54 | // The argument p points to a []string variable in which to store the values of the multiple flags.
55 | // The value of each argument will not try to be separated by comma
56 | func (f *FlagSet) StringArrayVar(p *[]string, name string, value []string, usage string) {
57 | f.VarP(newStringArrayValue(value, p), name, "", usage)
58 | }
59 |
60 | // StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
61 | func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) {
62 | f.VarP(newStringArrayValue(value, p), name, shorthand, usage)
63 | }
64 |
65 | // StringArrayVar defines a string flag with specified name, default value, and usage string.
66 | // The argument p points to a []string variable in which to store the value of the flag.
67 | // The value of each argument will not try to be separated by comma
68 | func StringArrayVar(p *[]string, name string, value []string, usage string) {
69 | CommandLine.VarP(newStringArrayValue(value, p), name, "", usage)
70 | }
71 |
72 | // StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
73 | func StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) {
74 | CommandLine.VarP(newStringArrayValue(value, p), name, shorthand, usage)
75 | }
76 |
77 | // StringArray 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 | // The value of each argument will not try to be separated by comma
80 | func (f *FlagSet) StringArray(name string, value []string, usage string) *[]string {
81 | p := []string{}
82 | f.StringArrayVarP(&p, name, "", value, usage)
83 | return &p
84 | }
85 |
86 | // StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
87 | func (f *FlagSet) StringArrayP(name, shorthand string, value []string, usage string) *[]string {
88 | p := []string{}
89 | f.StringArrayVarP(&p, name, shorthand, value, usage)
90 | return &p
91 | }
92 |
93 | // StringArray defines a string flag with specified name, default value, and usage string.
94 | // The return value is the address of a []string variable that stores the value of the flag.
95 | // The value of each argument will not try to be separated by comma
96 | func StringArray(name string, value []string, usage string) *[]string {
97 | return CommandLine.StringArrayP(name, "", value, usage)
98 | }
99 |
100 | // StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
101 | func StringArrayP(name, shorthand string, value []string, usage string) *[]string {
102 | return CommandLine.StringArrayP(name, shorthand, value, usage)
103 | }
104 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- uint Value
6 | type uintValue uint
7 |
8 | func newUintValue(val uint, p *uint) *uintValue {
9 | *p = val
10 | return (*uintValue)(p)
11 | }
12 |
13 | func (i *uintValue) Set(s string) error {
14 | v, err := strconv.ParseUint(s, 0, 64)
15 | *i = uintValue(v)
16 | return err
17 | }
18 |
19 | func (i *uintValue) Type() string {
20 | return "uint"
21 | }
22 |
23 | func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) }
24 |
25 | func uintConv(sval string) (interface{}, error) {
26 | v, err := strconv.ParseUint(sval, 0, 0)
27 | if err != nil {
28 | return 0, err
29 | }
30 | return uint(v), nil
31 | }
32 |
33 | // GetUint return the uint value of a flag with the given name
34 | func (f *FlagSet) GetUint(name string) (uint, error) {
35 | val, err := f.getFlagType(name, "uint", uintConv)
36 | if err != nil {
37 | return 0, err
38 | }
39 | return val.(uint), nil
40 | }
41 |
42 | // UintVar defines a uint flag with specified name, default value, and usage string.
43 | // The argument p points to a uint variable in which to store the value of the flag.
44 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) {
45 | f.VarP(newUintValue(value, p), name, "", usage)
46 | }
47 |
48 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
49 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) {
50 | f.VarP(newUintValue(value, p), name, shorthand, usage)
51 | }
52 |
53 | // UintVar defines a uint flag with specified name, default value, and usage string.
54 | // The argument p points to a uint variable in which to store the value of the flag.
55 | func UintVar(p *uint, name string, value uint, usage string) {
56 | CommandLine.VarP(newUintValue(value, p), name, "", usage)
57 | }
58 |
59 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
60 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) {
61 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage)
62 | }
63 |
64 | // Uint defines a uint flag with specified name, default value, and usage string.
65 | // The return value is the address of a uint variable that stores the value of the flag.
66 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint {
67 | p := new(uint)
68 | f.UintVarP(p, name, "", value, usage)
69 | return p
70 | }
71 |
72 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
73 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint {
74 | p := new(uint)
75 | f.UintVarP(p, name, shorthand, value, usage)
76 | return p
77 | }
78 |
79 | // Uint defines a uint flag with specified name, default value, and usage string.
80 | // The return value is the address of a uint variable that stores the value of the flag.
81 | func Uint(name string, value uint, usage string) *uint {
82 | return CommandLine.UintP(name, "", value, usage)
83 | }
84 |
85 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
86 | func UintP(name, shorthand string, value uint, usage string) *uint {
87 | return CommandLine.UintP(name, shorthand, value, usage)
88 | }
89 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint16.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- uint16 value
6 | type uint16Value uint16
7 |
8 | func newUint16Value(val uint16, p *uint16) *uint16Value {
9 | *p = val
10 | return (*uint16Value)(p)
11 | }
12 |
13 | func (i *uint16Value) Set(s string) error {
14 | v, err := strconv.ParseUint(s, 0, 16)
15 | *i = uint16Value(v)
16 | return err
17 | }
18 |
19 | func (i *uint16Value) Type() string {
20 | return "uint16"
21 | }
22 |
23 | func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
24 |
25 | func uint16Conv(sval string) (interface{}, error) {
26 | v, err := strconv.ParseUint(sval, 0, 16)
27 | if err != nil {
28 | return 0, err
29 | }
30 | return uint16(v), nil
31 | }
32 |
33 | // GetUint16 return the uint16 value of a flag with the given name
34 | func (f *FlagSet) GetUint16(name string) (uint16, error) {
35 | val, err := f.getFlagType(name, "uint16", uint16Conv)
36 | if err != nil {
37 | return 0, err
38 | }
39 | return val.(uint16), nil
40 | }
41 |
42 | // Uint16Var defines a uint flag with specified name, default value, and usage string.
43 | // The argument p points to a uint variable in which to store the value of the flag.
44 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) {
45 | f.VarP(newUint16Value(value, p), name, "", usage)
46 | }
47 |
48 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
49 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
50 | f.VarP(newUint16Value(value, p), name, shorthand, usage)
51 | }
52 |
53 | // Uint16Var defines a uint flag with specified name, default value, and usage string.
54 | // The argument p points to a uint variable in which to store the value of the flag.
55 | func Uint16Var(p *uint16, name string, value uint16, usage string) {
56 | CommandLine.VarP(newUint16Value(value, p), name, "", usage)
57 | }
58 |
59 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
60 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
61 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage)
62 | }
63 |
64 | // Uint16 defines a uint flag with specified name, default value, and usage string.
65 | // The return value is the address of a uint variable that stores the value of the flag.
66 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 {
67 | p := new(uint16)
68 | f.Uint16VarP(p, name, "", value, usage)
69 | return p
70 | }
71 |
72 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
73 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
74 | p := new(uint16)
75 | f.Uint16VarP(p, name, shorthand, value, usage)
76 | return p
77 | }
78 |
79 | // Uint16 defines a uint flag with specified name, default value, and usage string.
80 | // The return value is the address of a uint variable that stores the value of the flag.
81 | func Uint16(name string, value uint16, usage string) *uint16 {
82 | return CommandLine.Uint16P(name, "", value, usage)
83 | }
84 |
85 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
86 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
87 | return CommandLine.Uint16P(name, shorthand, value, usage)
88 | }
89 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint32.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- uint32 value
6 | type uint32Value uint32
7 |
8 | func newUint32Value(val uint32, p *uint32) *uint32Value {
9 | *p = val
10 | return (*uint32Value)(p)
11 | }
12 |
13 | func (i *uint32Value) Set(s string) error {
14 | v, err := strconv.ParseUint(s, 0, 32)
15 | *i = uint32Value(v)
16 | return err
17 | }
18 |
19 | func (i *uint32Value) Type() string {
20 | return "uint32"
21 | }
22 |
23 | func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
24 |
25 | func uint32Conv(sval string) (interface{}, error) {
26 | v, err := strconv.ParseUint(sval, 0, 32)
27 | if err != nil {
28 | return 0, err
29 | }
30 | return uint32(v), nil
31 | }
32 |
33 | // GetUint32 return the uint32 value of a flag with the given name
34 | func (f *FlagSet) GetUint32(name string) (uint32, error) {
35 | val, err := f.getFlagType(name, "uint32", uint32Conv)
36 | if err != nil {
37 | return 0, err
38 | }
39 | return val.(uint32), nil
40 | }
41 |
42 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string.
43 | // The argument p points to a uint32 variable in which to store the value of the flag.
44 | func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) {
45 | f.VarP(newUint32Value(value, p), name, "", usage)
46 | }
47 |
48 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
49 | func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
50 | f.VarP(newUint32Value(value, p), name, shorthand, usage)
51 | }
52 |
53 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string.
54 | // The argument p points to a uint32 variable in which to store the value of the flag.
55 | func Uint32Var(p *uint32, name string, value uint32, usage string) {
56 | CommandLine.VarP(newUint32Value(value, p), name, "", usage)
57 | }
58 |
59 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
60 | func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
61 | CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage)
62 | }
63 |
64 | // Uint32 defines a uint32 flag with specified name, default value, and usage string.
65 | // The return value is the address of a uint32 variable that stores the value of the flag.
66 | func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 {
67 | p := new(uint32)
68 | f.Uint32VarP(p, name, "", value, usage)
69 | return p
70 | }
71 |
72 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
73 | func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
74 | p := new(uint32)
75 | f.Uint32VarP(p, name, shorthand, value, usage)
76 | return p
77 | }
78 |
79 | // Uint32 defines a uint32 flag with specified name, default value, and usage string.
80 | // The return value is the address of a uint32 variable that stores the value of the flag.
81 | func Uint32(name string, value uint32, usage string) *uint32 {
82 | return CommandLine.Uint32P(name, "", value, usage)
83 | }
84 |
85 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
86 | func Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
87 | return CommandLine.Uint32P(name, shorthand, value, usage)
88 | }
89 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint64.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- uint64 Value
6 | type uint64Value uint64
7 |
8 | func newUint64Value(val uint64, p *uint64) *uint64Value {
9 | *p = val
10 | return (*uint64Value)(p)
11 | }
12 |
13 | func (i *uint64Value) Set(s string) error {
14 | v, err := strconv.ParseUint(s, 0, 64)
15 | *i = uint64Value(v)
16 | return err
17 | }
18 |
19 | func (i *uint64Value) Type() string {
20 | return "uint64"
21 | }
22 |
23 | func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
24 |
25 | func uint64Conv(sval string) (interface{}, error) {
26 | v, err := strconv.ParseUint(sval, 0, 64)
27 | if err != nil {
28 | return 0, err
29 | }
30 | return uint64(v), nil
31 | }
32 |
33 | // GetUint64 return the uint64 value of a flag with the given name
34 | func (f *FlagSet) GetUint64(name string) (uint64, error) {
35 | val, err := f.getFlagType(name, "uint64", uint64Conv)
36 | if err != nil {
37 | return 0, err
38 | }
39 | return val.(uint64), nil
40 | }
41 |
42 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string.
43 | // The argument p points to a uint64 variable in which to store the value of the flag.
44 | func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) {
45 | f.VarP(newUint64Value(value, p), name, "", usage)
46 | }
47 |
48 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
49 | func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
50 | f.VarP(newUint64Value(value, p), name, shorthand, usage)
51 | }
52 |
53 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string.
54 | // The argument p points to a uint64 variable in which to store the value of the flag.
55 | func Uint64Var(p *uint64, name string, value uint64, usage string) {
56 | CommandLine.VarP(newUint64Value(value, p), name, "", usage)
57 | }
58 |
59 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
60 | func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
61 | CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage)
62 | }
63 |
64 | // Uint64 defines a uint64 flag with specified name, default value, and usage string.
65 | // The return value is the address of a uint64 variable that stores the value of the flag.
66 | func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 {
67 | p := new(uint64)
68 | f.Uint64VarP(p, name, "", value, usage)
69 | return p
70 | }
71 |
72 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
73 | func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
74 | p := new(uint64)
75 | f.Uint64VarP(p, name, shorthand, value, usage)
76 | return p
77 | }
78 |
79 | // Uint64 defines a uint64 flag with specified name, default value, and usage string.
80 | // The return value is the address of a uint64 variable that stores the value of the flag.
81 | func Uint64(name string, value uint64, usage string) *uint64 {
82 | return CommandLine.Uint64P(name, "", value, usage)
83 | }
84 |
85 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
86 | func Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
87 | return CommandLine.Uint64P(name, shorthand, value, usage)
88 | }
89 |
--------------------------------------------------------------------------------
/vendor/github.com/spf13/pflag/uint8.go:
--------------------------------------------------------------------------------
1 | package pflag
2 |
3 | import "strconv"
4 |
5 | // -- uint8 Value
6 | type uint8Value uint8
7 |
8 | func newUint8Value(val uint8, p *uint8) *uint8Value {
9 | *p = val
10 | return (*uint8Value)(p)
11 | }
12 |
13 | func (i *uint8Value) Set(s string) error {
14 | v, err := strconv.ParseUint(s, 0, 8)
15 | *i = uint8Value(v)
16 | return err
17 | }
18 |
19 | func (i *uint8Value) Type() string {
20 | return "uint8"
21 | }
22 |
23 | func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
24 |
25 | func uint8Conv(sval string) (interface{}, error) {
26 | v, err := strconv.ParseUint(sval, 0, 8)
27 | if err != nil {
28 | return 0, err
29 | }
30 | return uint8(v), nil
31 | }
32 |
33 | // GetUint8 return the uint8 value of a flag with the given name
34 | func (f *FlagSet) GetUint8(name string) (uint8, error) {
35 | val, err := f.getFlagType(name, "uint8", uint8Conv)
36 | if err != nil {
37 | return 0, err
38 | }
39 | return val.(uint8), nil
40 | }
41 |
42 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string.
43 | // The argument p points to a uint8 variable in which to store the value of the flag.
44 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) {
45 | f.VarP(newUint8Value(value, p), name, "", usage)
46 | }
47 |
48 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
49 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
50 | f.VarP(newUint8Value(value, p), name, shorthand, usage)
51 | }
52 |
53 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string.
54 | // The argument p points to a uint8 variable in which to store the value of the flag.
55 | func Uint8Var(p *uint8, name string, value uint8, usage string) {
56 | CommandLine.VarP(newUint8Value(value, p), name, "", usage)
57 | }
58 |
59 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
60 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
61 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage)
62 | }
63 |
64 | // Uint8 defines a uint8 flag with specified name, default value, and usage string.
65 | // The return value is the address of a uint8 variable that stores the value of the flag.
66 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 {
67 | p := new(uint8)
68 | f.Uint8VarP(p, name, "", value, usage)
69 | return p
70 | }
71 |
72 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
73 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
74 | p := new(uint8)
75 | f.Uint8VarP(p, name, shorthand, value, usage)
76 | return p
77 | }
78 |
79 | // Uint8 defines a uint8 flag with specified name, default value, and usage string.
80 | // The return value is the address of a uint8 variable that stores the value of the flag.
81 | func Uint8(name string, value uint8, usage string) *uint8 {
82 | return CommandLine.Uint8P(name, "", value, usage)
83 | }
84 |
85 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
86 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
87 | return CommandLine.Uint8P(name, shorthand, value, usage)
88 | }
89 |
--------------------------------------------------------------------------------