forked from forgejo/forgejo
[Vendor] update go-swagger v0.21.0 -> v0.25.0 (#12670)
* Update go-swagger * vendor
This commit is contained in:
parent
66843f2237
commit
3270e7a443
350 changed files with 26353 additions and 5552 deletions
1
vendor/github.com/subosito/gotenv/.env
generated
vendored
Normal file
1
vendor/github.com/subosito/gotenv/.env
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
HELLO=world
|
1
vendor/github.com/subosito/gotenv/.env.invalid
generated
vendored
Normal file
1
vendor/github.com/subosito/gotenv/.env.invalid
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
lol$wut
|
3
vendor/github.com/subosito/gotenv/.gitignore
generated
vendored
Normal file
3
vendor/github.com/subosito/gotenv/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.test
|
||||
*.out
|
||||
annotate.json
|
10
vendor/github.com/subosito/gotenv/.travis.yml
generated
vendored
Normal file
10
vendor/github.com/subosito/gotenv/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.x
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
script:
|
||||
- go test -test.v -coverprofile=coverage.out -covermode=count
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
47
vendor/github.com/subosito/gotenv/CHANGELOG.md
generated
vendored
Normal file
47
vendor/github.com/subosito/gotenv/CHANGELOG.md
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Changelog
|
||||
|
||||
## [1.2.0] - 2019-08-03
|
||||
|
||||
### Added
|
||||
|
||||
- Add `Must` helper to raise an error as panic. It can be used with `Load` and `OverLoad`.
|
||||
- Add more tests to be 100% coverage.
|
||||
- Add CHANGELOG
|
||||
- Add more OS for the test: OSX and Windows
|
||||
|
||||
### Changed
|
||||
|
||||
- Reduce complexity and improve source code for having `A+` score in [goreportcard](https://goreportcard.com/report/github.com/subosito/gotenv).
|
||||
- Updated README with mentions to all available functions
|
||||
|
||||
### Removed
|
||||
|
||||
- Remove `ErrFormat`
|
||||
- Remove `MustLoad` and `MustOverload`, replaced with `Must` helper.
|
||||
|
||||
## [1.1.1] - 2018-06-05
|
||||
|
||||
### Changed
|
||||
|
||||
- Replace `os.Getenv` with `os.LookupEnv` to ensure that the environment variable is not set, by [radding](https://github.com/radding)
|
||||
|
||||
## [1.1.0] - 2017-03-20
|
||||
|
||||
### Added
|
||||
|
||||
- Supports carriage return in env
|
||||
- Handle files with UTF-8 BOM
|
||||
|
||||
### Changed
|
||||
|
||||
- Whitespace handling
|
||||
|
||||
### Fixed
|
||||
|
||||
- Incorrect variable expansion
|
||||
- Handling escaped '$' characters
|
||||
|
||||
## [1.0.0] - 2014-10-05
|
||||
|
||||
First stable release.
|
||||
|
21
vendor/github.com/subosito/gotenv/LICENSE
generated
vendored
Normal file
21
vendor/github.com/subosito/gotenv/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Alif Rachmawadi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
131
vendor/github.com/subosito/gotenv/README.md
generated
vendored
Normal file
131
vendor/github.com/subosito/gotenv/README.md
generated
vendored
Normal file
|
@ -0,0 +1,131 @@
|
|||
# gotenv
|
||||
|
||||
[](https://travis-ci.org/subosito/gotenv)
|
||||
[](https://ci.appveyor.com/project/subosito/gotenv/branch/master)
|
||||
[](https://codecov.io/gh/subosito/gotenv)
|
||||
[](https://goreportcard.com/report/github.com/subosito/gotenv)
|
||||
[](https://godoc.org/github.com/subosito/gotenv)
|
||||
|
||||
Load environment variables dynamically in Go.
|
||||
|
||||
## Usage
|
||||
|
||||
Put the gotenv package on your `import` statement:
|
||||
|
||||
```go
|
||||
import "github.com/subosito/gotenv"
|
||||
```
|
||||
|
||||
To modify your app environment variables, `gotenv` expose 2 main functions:
|
||||
|
||||
- `gotenv.Load`
|
||||
- `gotenv.Apply`
|
||||
|
||||
By default, `gotenv.Load` will look for a file called `.env` in the current working directory.
|
||||
|
||||
Behind the scene, it will then load `.env` file and export the valid variables to the environment variables. Make sure you call the method as soon as possible to ensure it loads all variables, say, put it on `init()` function.
|
||||
|
||||
Once loaded you can use `os.Getenv()` to get the value of the variable.
|
||||
|
||||
Let's say you have `.env` file:
|
||||
|
||||
```
|
||||
APP_ID=1234567
|
||||
APP_SECRET=abcdef
|
||||
```
|
||||
|
||||
Here's the example of your app:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/subosito/gotenv"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
gotenv.Load()
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println(os.Getenv("APP_ID")) // "1234567"
|
||||
log.Println(os.Getenv("APP_SECRET")) // "abcdef"
|
||||
}
|
||||
```
|
||||
|
||||
You can also load other than `.env` file if you wish. Just supply filenames when calling `Load()`. It will load them in order and the first value set for a variable will win.:
|
||||
|
||||
```go
|
||||
gotenv.Load(".env.production", "credentials")
|
||||
```
|
||||
|
||||
While `gotenv.Load` loads entries from `.env` file, `gotenv.Apply` allows you to use any `io.Reader`:
|
||||
|
||||
```go
|
||||
gotenv.Apply(strings.NewReader("APP_ID=1234567"))
|
||||
|
||||
log.Println(os.Getenv("APP_ID"))
|
||||
// Output: "1234567"
|
||||
```
|
||||
|
||||
Both `gotenv.Load` and `gotenv.Apply` **DO NOT** overrides existing environment variables. If you want to override existing ones, you can see section below.
|
||||
|
||||
### Environment Overrides
|
||||
|
||||
Besides above functions, `gotenv` also provides another functions that overrides existing:
|
||||
|
||||
- `gotenv.OverLoad`
|
||||
- `gotenv.OverApply`
|
||||
|
||||
|
||||
Here's the example of this overrides behavior:
|
||||
|
||||
```go
|
||||
os.Setenv("HELLO", "world")
|
||||
|
||||
// NOTE: using Apply existing value will be reserved
|
||||
gotenv.Apply(strings.NewReader("HELLO=universe"))
|
||||
fmt.Println(os.Getenv("HELLO"))
|
||||
// Output: "world"
|
||||
|
||||
// NOTE: using OverApply existing value will be overridden
|
||||
gotenv.OverApply(strings.NewReader("HELLO=universe"))
|
||||
fmt.Println(os.Getenv("HELLO"))
|
||||
// Output: "universe"
|
||||
```
|
||||
|
||||
### Throw a Panic
|
||||
|
||||
Both `gotenv.Load` and `gotenv.OverLoad` returns an error on something wrong occurred, like your env file is not exist, and so on. To make it easier to use, `gotenv` also provides `gotenv.Must` helper, to let it panic when an error returned.
|
||||
|
||||
```go
|
||||
err := gotenv.Load(".env-is-not-exist")
|
||||
fmt.Println("error", err)
|
||||
// error: open .env-is-not-exist: no such file or directory
|
||||
|
||||
gotenv.Must(gotenv.Load, ".env-is-not-exist")
|
||||
// it will throw a panic
|
||||
// panic: open .env-is-not-exist: no such file or directory
|
||||
```
|
||||
|
||||
### Another Scenario
|
||||
|
||||
Just in case you want to parse environment variables from any `io.Reader`, gotenv keeps its `Parse` and `StrictParse` function as public API so you can use that.
|
||||
|
||||
```go
|
||||
// import "strings"
|
||||
|
||||
pairs := gotenv.Parse(strings.NewReader("FOO=test\nBAR=$FOO"))
|
||||
// gotenv.Env{"FOO": "test", "BAR": "test"}
|
||||
|
||||
err, pairs = gotenv.StrictParse(strings.NewReader(`FOO="bar"`))
|
||||
// gotenv.Env{"FOO": "bar"}
|
||||
```
|
||||
|
||||
`Parse` ignores invalid lines and returns `Env` of valid environment variables, while `StrictParse` returns an error for invalid lines.
|
||||
|
||||
## Notes
|
||||
|
||||
The gotenv package is a Go port of [`dotenv`](https://github.com/bkeepers/dotenv) project with some additions made for Go. For general features, it aims to be compatible as close as possible.
|
9
vendor/github.com/subosito/gotenv/appveyor.yml
generated
vendored
Normal file
9
vendor/github.com/subosito/gotenv/appveyor.yml
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
build: off
|
||||
clone_folder: c:\gopath\src\github.com\subosito\gotenv
|
||||
environment:
|
||||
GOPATH: c:\gopath
|
||||
stack: go 1.10
|
||||
before_test:
|
||||
- go get -t
|
||||
test_script:
|
||||
- go test -v -cover -race
|
265
vendor/github.com/subosito/gotenv/gotenv.go
generated
vendored
Normal file
265
vendor/github.com/subosito/gotenv/gotenv.go
generated
vendored
Normal file
|
@ -0,0 +1,265 @@
|
|||
// Package gotenv provides functionality to dynamically load the environment variables
|
||||
package gotenv
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// Pattern for detecting valid line format
|
||||
linePattern = `\A\s*(?:export\s+)?([\w\.]+)(?:\s*=\s*|:\s+?)('(?:\'|[^'])*'|"(?:\"|[^"])*"|[^#\n]+)?\s*(?:\s*\#.*)?\z`
|
||||
|
||||
// Pattern for detecting valid variable within a value
|
||||
variablePattern = `(\\)?(\$)(\{?([A-Z0-9_]+)?\}?)`
|
||||
)
|
||||
|
||||
// Env holds key/value pair of valid environment variable
|
||||
type Env map[string]string
|
||||
|
||||
/*
|
||||
Load is a function to load a file or multiple files and then export the valid variables into environment variables if they do not exist.
|
||||
When it's called with no argument, it will load `.env` file on the current path and set the environment variables.
|
||||
Otherwise, it will loop over the filenames parameter and set the proper environment variables.
|
||||
*/
|
||||
func Load(filenames ...string) error {
|
||||
return loadenv(false, filenames...)
|
||||
}
|
||||
|
||||
/*
|
||||
OverLoad is a function to load a file or multiple files and then export and override the valid variables into environment variables.
|
||||
*/
|
||||
func OverLoad(filenames ...string) error {
|
||||
return loadenv(true, filenames...)
|
||||
}
|
||||
|
||||
/*
|
||||
Must is wrapper function that will panic when supplied function returns an error.
|
||||
*/
|
||||
func Must(fn func(filenames ...string) error, filenames ...string) {
|
||||
if err := fn(filenames...); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Apply is a function to load an io Reader then export the valid variables into environment variables if they do not exist.
|
||||
*/
|
||||
func Apply(r io.Reader) error {
|
||||
return parset(r, false)
|
||||
}
|
||||
|
||||
/*
|
||||
OverApply is a function to load an io Reader then export and override the valid variables into environment variables.
|
||||
*/
|
||||
func OverApply(r io.Reader) error {
|
||||
return parset(r, true)
|
||||
}
|
||||
|
||||
func loadenv(override bool, filenames ...string) error {
|
||||
if len(filenames) == 0 {
|
||||
filenames = []string{".env"}
|
||||
}
|
||||
|
||||
for _, filename := range filenames {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = parset(f, override)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// parse and set :)
|
||||
func parset(r io.Reader, override bool) error {
|
||||
env, err := StrictParse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, val := range env {
|
||||
setenv(key, val, override)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func setenv(key, val string, override bool) {
|
||||
if override {
|
||||
os.Setenv(key, val)
|
||||
} else {
|
||||
if _, present := os.LookupEnv(key); !present {
|
||||
os.Setenv(key, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse is a function to parse line by line any io.Reader supplied and returns the valid Env key/value pair of valid variables.
|
||||
// It expands the value of a variable from the environment variable but does not set the value to the environment itself.
|
||||
// This function is skipping any invalid lines and only processing the valid one.
|
||||
func Parse(r io.Reader) Env {
|
||||
env, _ := StrictParse(r)
|
||||
return env
|
||||
}
|
||||
|
||||
// StrictParse is a function to parse line by line any io.Reader supplied and returns the valid Env key/value pair of valid variables.
|
||||
// It expands the value of a variable from the environment variable but does not set the value to the environment itself.
|
||||
// This function is returning an error if there are any invalid lines.
|
||||
func StrictParse(r io.Reader) (Env, error) {
|
||||
env := make(Env)
|
||||
scanner := bufio.NewScanner(r)
|
||||
|
||||
i := 1
|
||||
bom := string([]byte{239, 187, 191})
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
if i == 1 {
|
||||
line = strings.TrimPrefix(line, bom)
|
||||
}
|
||||
|
||||
i++
|
||||
|
||||
err := parseLine(line, env)
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
}
|
||||
|
||||
return env, nil
|
||||
}
|
||||
|
||||
func parseLine(s string, env Env) error {
|
||||
rl := regexp.MustCompile(linePattern)
|
||||
rm := rl.FindStringSubmatch(s)
|
||||
|
||||
if len(rm) == 0 {
|
||||
return checkFormat(s, env)
|
||||
}
|
||||
|
||||
key := rm[1]
|
||||
val := rm[2]
|
||||
|
||||
// determine if string has quote prefix
|
||||
hdq := strings.HasPrefix(val, `"`)
|
||||
|
||||
// determine if string has single quote prefix
|
||||
hsq := strings.HasPrefix(val, `'`)
|
||||
|
||||
// trim whitespace
|
||||
val = strings.Trim(val, " ")
|
||||
|
||||
// remove quotes '' or ""
|
||||
rq := regexp.MustCompile(`\A(['"])(.*)(['"])\z`)
|
||||
val = rq.ReplaceAllString(val, "$2")
|
||||
|
||||
if hdq {
|
||||
val = strings.Replace(val, `\n`, "\n", -1)
|
||||
val = strings.Replace(val, `\r`, "\r", -1)
|
||||
|
||||
// Unescape all characters except $ so variables can be escaped properly
|
||||
re := regexp.MustCompile(`\\([^$])`)
|
||||
val = re.ReplaceAllString(val, "$1")
|
||||
}
|
||||
|
||||
rv := regexp.MustCompile(variablePattern)
|
||||
fv := func(s string) string {
|
||||
return varReplacement(s, hsq, env)
|
||||
}
|
||||
|
||||
val = rv.ReplaceAllStringFunc(val, fv)
|
||||
val = parseVal(val, env)
|
||||
|
||||
env[key] = val
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseExport(st string, env Env) error {
|
||||
if strings.HasPrefix(st, "export") {
|
||||
vs := strings.SplitN(st, " ", 2)
|
||||
|
||||
if len(vs) > 1 {
|
||||
if _, ok := env[vs[1]]; !ok {
|
||||
return fmt.Errorf("line `%s` has an unset variable", st)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func varReplacement(s string, hsq bool, env Env) string {
|
||||
if strings.HasPrefix(s, "\\") {
|
||||
return strings.TrimPrefix(s, "\\")
|
||||
}
|
||||
|
||||
if hsq {
|
||||
return s
|
||||
}
|
||||
|
||||
sn := `(\$)(\{?([A-Z0-9_]+)\}?)`
|
||||
rn := regexp.MustCompile(sn)
|
||||
mn := rn.FindStringSubmatch(s)
|
||||
|
||||
if len(mn) == 0 {
|
||||
return s
|
||||
}
|
||||
|
||||
v := mn[3]
|
||||
|
||||
replace, ok := env[v]
|
||||
if !ok {
|
||||
replace = os.Getenv(v)
|
||||
}
|
||||
|
||||
return replace
|
||||
}
|
||||
|
||||
func checkFormat(s string, env Env) error {
|
||||
st := strings.TrimSpace(s)
|
||||
|
||||
if (st == "") || strings.HasPrefix(st, "#") {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := parseExport(st, env); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return fmt.Errorf("line `%s` doesn't match format", s)
|
||||
}
|
||||
|
||||
func parseVal(val string, env Env) string {
|
||||
if strings.Contains(val, "=") {
|
||||
if !(val == "\n" || val == "\r") {
|
||||
kv := strings.Split(val, "\n")
|
||||
|
||||
if len(kv) == 1 {
|
||||
kv = strings.Split(val, "\r")
|
||||
}
|
||||
|
||||
if len(kv) > 1 {
|
||||
val = kv[0]
|
||||
|
||||
for i := 1; i < len(kv); i++ {
|
||||
parseLine(kv[i], env)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue