Update go dependencies
This commit is contained in:
parent
f9624cbe46
commit
307bf76454
280 changed files with 54728 additions and 2991 deletions
1
vendor/github.com/imkira/go-interpol/.codebeatignore
generated
vendored
Normal file
1
vendor/github.com/imkira/go-interpol/.codebeatignore
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
examples/*
|
||||
8
vendor/github.com/imkira/go-interpol/.gitignore
generated
vendored
Normal file
8
vendor/github.com/imkira/go-interpol/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# MacOSX
|
||||
.DS_Store
|
||||
|
||||
# vim
|
||||
*.swp
|
||||
|
||||
# test
|
||||
coverage.*
|
||||
21
vendor/github.com/imkira/go-interpol/.travis.yml
generated
vendored
Normal file
21
vendor/github.com/imkira/go-interpol/.travis.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
- 1.2
|
||||
- 1.3
|
||||
- 1.4
|
||||
- 1.5
|
||||
- 1.6
|
||||
- 1.7
|
||||
- tip
|
||||
|
||||
before_install:
|
||||
if [[ $TRAVIS_GO_VERSION == 1.7* ]]; then make deps; fi
|
||||
|
||||
script:
|
||||
- if [[ $TRAVIS_GO_VERSION == 1.7* ]]; then make gometalinter; fi
|
||||
- make test
|
||||
- make cover
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
20
vendor/github.com/imkira/go-interpol/LICENSE
generated
vendored
Normal file
20
vendor/github.com/imkira/go-interpol/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2016 Mario Freitas (imkira@gmail.com)
|
||||
|
||||
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.
|
||||
21
vendor/github.com/imkira/go-interpol/Makefile
generated
vendored
Normal file
21
vendor/github.com/imkira/go-interpol/Makefile
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
.PHONY: all deps gometalinter test cover
|
||||
|
||||
all: gometalinter test cover
|
||||
|
||||
deps:
|
||||
go get -u github.com/alecthomas/gometalinter
|
||||
gometalinter --install
|
||||
|
||||
gometalinter:
|
||||
gometalinter --vendor --deadline=1m --tests \
|
||||
--enable=gofmt \
|
||||
--enable=goimports \
|
||||
--enable=lll \
|
||||
--enable=misspell \
|
||||
--enable=unused
|
||||
|
||||
test:
|
||||
go test -v -race -cpu=1,2,4 -coverprofile=coverage.txt -covermode=atomic -benchmem -bench .
|
||||
|
||||
cover:
|
||||
go tool cover -html=coverage.txt -o coverage.html
|
||||
74
vendor/github.com/imkira/go-interpol/README.md
generated
vendored
Normal file
74
vendor/github.com/imkira/go-interpol/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# interpol
|
||||
|
||||
[](https://github.com/imkira/go-interpol/blob/master/LICENSE.txt)
|
||||
[](https://godoc.org/github.com/imkira/go-interpol)
|
||||
[](https://travis-ci.org/imkira/go-interpol)
|
||||
[](https://codecov.io/gh/imkira/go-interpol)
|
||||
[](https://codebeat.co/projects/github-com-imkira-go-interpol)
|
||||
[](https://goreportcard.com/report/github.com/imkira/go-interpol)
|
||||
|
||||
interpol is a [Go](http://golang.org) package for doing format-string like
|
||||
string interpolation using named parameters.
|
||||
|
||||
Currently, a template only accepts variable placeholders delimited by brace
|
||||
characters (eg. "Hello {foo} {bar}").
|
||||
|
||||
## Install
|
||||
|
||||
First, you need to install the package:
|
||||
|
||||
```go
|
||||
go get -u github.com/imkira/go-interpol
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
For advanced usage, make sure to check the
|
||||
[available documentation here](http://godoc.org/github.com/imkira/go-interpol).
|
||||
|
||||
## Example
|
||||
|
||||
The following code should use `interpol.WithMap` function, which simply
|
||||
replaces every key with the corresponding value of the specified map.
|
||||
When run, it should output `Hello World!!!`.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/imkira/go-interpol"
|
||||
)
|
||||
|
||||
func main() {
|
||||
m := map[string]string{
|
||||
"foo": "Hello",
|
||||
"bar": "World",
|
||||
}
|
||||
str, err := interpol.WithMap("{foo} {bar}!!!", m)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(str)
|
||||
}
|
||||
```
|
||||
|
||||
## Contribute
|
||||
|
||||
Found a bug? Want to contribute and add a new feature?
|
||||
|
||||
Please fork this project and send me a pull request!
|
||||
|
||||
## License
|
||||
|
||||
go-interpol is licensed under the MIT license:
|
||||
|
||||
www.opensource.org/licenses/MIT
|
||||
|
||||
## Copyright
|
||||
|
||||
Copyright (c) 2016 Mario Freitas. See
|
||||
[LICENSE](http://github.com/imkira/go-interpol/blob/master/LICENSE)
|
||||
for further details.
|
||||
171
vendor/github.com/imkira/go-interpol/interpol.go
generated
vendored
Normal file
171
vendor/github.com/imkira/go-interpol/interpol.go
generated
vendored
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
// Package interpol provides utility functions for doing format-string like
|
||||
// string interpolation using named parameters.
|
||||
// Currently, a template only accepts variable placeholders delimited by brace
|
||||
// characters (eg. "Hello {foo} {bar}").
|
||||
package interpol
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Errors returned when formatting templates.
|
||||
var (
|
||||
ErrUnexpectedClose = errors.New("interpol: unexpected close in template")
|
||||
ErrExpectingClose = errors.New("interpol: expecting close in template")
|
||||
ErrKeyNotFound = errors.New("interpol: key not found")
|
||||
ErrReadByteFailed = errors.New("interpol: read byte failed")
|
||||
)
|
||||
|
||||
// Func receives the placeholder key and writes to the io.Writer. If an error
|
||||
// happens, the function can return an error, in which case the interpolation
|
||||
// will be aborted.
|
||||
type Func func(key string, w io.Writer) error
|
||||
|
||||
// New creates a new interpolator with the given list of options.
|
||||
// You can use options such as the ones returned by WithTemplate, WithFormat
|
||||
// and WithOutput.
|
||||
func New(opts ...Option) *Interpolator {
|
||||
opts2 := &Options{}
|
||||
setOptions(opts, newOptionSetter(opts2))
|
||||
return NewWithOptions(opts2)
|
||||
}
|
||||
|
||||
// NewWithOptions creates a new interpolator with the given options.
|
||||
func NewWithOptions(opts *Options) *Interpolator {
|
||||
return &Interpolator{
|
||||
template: templateReader(opts),
|
||||
output: outputWriter(opts),
|
||||
format: opts.Format,
|
||||
rb: make([]rune, 0, 64),
|
||||
start: -1,
|
||||
closing: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Interpolator interpolates Template to Output, according to Format.
|
||||
type Interpolator struct {
|
||||
template io.RuneReader
|
||||
output runeWriter
|
||||
format Func
|
||||
rb []rune
|
||||
start int
|
||||
closing bool
|
||||
}
|
||||
|
||||
// Interpolate reads runes from Template and writes them to Output, with the
|
||||
// exception of placeholders which are passed to Format.
|
||||
func (i *Interpolator) Interpolate() error {
|
||||
for pos := 0; ; pos++ {
|
||||
r, _, err := i.template.ReadRune()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
return err
|
||||
}
|
||||
if err := i.parse(r, pos); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return i.finish()
|
||||
}
|
||||
|
||||
func (i *Interpolator) parse(r rune, pos int) error {
|
||||
switch r {
|
||||
case '{':
|
||||
return i.open(pos)
|
||||
case '}':
|
||||
return i.close()
|
||||
default:
|
||||
return i.append(r)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Interpolator) open(pos int) error {
|
||||
if i.closing {
|
||||
return ErrUnexpectedClose
|
||||
}
|
||||
if i.start >= 0 {
|
||||
if _, err := i.output.WriteRune('{'); err != nil {
|
||||
return err
|
||||
}
|
||||
i.start = -1
|
||||
} else {
|
||||
i.start = pos + 1
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Interpolator) close() error {
|
||||
if i.start >= 0 {
|
||||
if err := i.format(string(i.rb), i.output); err != nil {
|
||||
return err
|
||||
}
|
||||
i.rb = i.rb[:0]
|
||||
i.start = -1
|
||||
} else if i.closing {
|
||||
i.closing = false
|
||||
if _, err := i.output.WriteRune('}'); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
i.closing = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Interpolator) append(r rune) error {
|
||||
if i.closing {
|
||||
return ErrUnexpectedClose
|
||||
}
|
||||
if i.start < 0 {
|
||||
_, err := i.output.WriteRune(r)
|
||||
return err
|
||||
}
|
||||
i.rb = append(i.rb, r)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Interpolator) finish() error {
|
||||
if i.start >= 0 {
|
||||
return ErrExpectingClose
|
||||
}
|
||||
if i.closing {
|
||||
return ErrUnexpectedClose
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithFunc interpolates the specified template with replacements using the
|
||||
// given function.
|
||||
func WithFunc(template string, format Func) (string, error) {
|
||||
buffer := bytes.NewBuffer(make([]byte, 0, len(template)))
|
||||
opts := &Options{
|
||||
Template: strings.NewReader(template),
|
||||
Output: buffer,
|
||||
Format: format,
|
||||
}
|
||||
i := NewWithOptions(opts)
|
||||
if err := i.Interpolate(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buffer.String(), nil
|
||||
}
|
||||
|
||||
// WithMap interpolates the specified template with replacements using the
|
||||
// given map. If a placeholder is used for which a value is not found, an error
|
||||
// is returned.
|
||||
func WithMap(template string, m map[string]string) (string, error) {
|
||||
format := func(key string, w io.Writer) error {
|
||||
value, ok := m[key]
|
||||
if !ok {
|
||||
return ErrKeyNotFound
|
||||
}
|
||||
_, err := w.Write([]byte(value))
|
||||
return err
|
||||
}
|
||||
return WithFunc(template, format)
|
||||
}
|
||||
52
vendor/github.com/imkira/go-interpol/io.go
generated
vendored
Normal file
52
vendor/github.com/imkira/go-interpol/io.go
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package interpol
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type runeWriter interface {
|
||||
io.Writer
|
||||
WriteRune(r rune) (int, error)
|
||||
}
|
||||
|
||||
func templateReader(opts *Options) io.RuneReader {
|
||||
if rr, ok := opts.Template.(io.RuneReader); ok {
|
||||
return rr
|
||||
}
|
||||
return bufio.NewReaderSize(opts.Template, utf8.UTFMax)
|
||||
}
|
||||
|
||||
func outputWriter(opts *Options) runeWriter {
|
||||
if rw, ok := opts.Output.(runeWriter); ok {
|
||||
return rw
|
||||
}
|
||||
return &simpleRuneWriter{w: opts.Output}
|
||||
}
|
||||
|
||||
type simpleRuneWriter struct {
|
||||
runeEncoder
|
||||
w io.Writer
|
||||
}
|
||||
|
||||
func (rw *simpleRuneWriter) Write(b []byte) (int, error) {
|
||||
return rw.w.Write(b)
|
||||
}
|
||||
|
||||
func (rw *simpleRuneWriter) WriteRune(r rune) (int, error) {
|
||||
return rw.w.Write(rw.encode(r))
|
||||
}
|
||||
|
||||
type runeEncoder struct {
|
||||
b [utf8.UTFMax]byte
|
||||
}
|
||||
|
||||
func (re *runeEncoder) encode(r rune) []byte {
|
||||
if r < utf8.RuneSelf {
|
||||
re.b[0] = byte(r)
|
||||
return re.b[:1]
|
||||
}
|
||||
n := utf8.EncodeRune(re.b[:], r)
|
||||
return re.b[:n]
|
||||
}
|
||||
68
vendor/github.com/imkira/go-interpol/options.go
generated
vendored
Normal file
68
vendor/github.com/imkira/go-interpol/options.go
generated
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
package interpol
|
||||
|
||||
import "io"
|
||||
|
||||
// Options contains all options supported by an Interpolator.
|
||||
type Options struct {
|
||||
Template io.Reader
|
||||
Format Func
|
||||
Output io.Writer
|
||||
}
|
||||
|
||||
// Option is an option that can be applied to an Interpolator.
|
||||
type Option func(OptionSetter)
|
||||
|
||||
// OptionSetter is an interface that contains the setters for all options
|
||||
// supported by Interpolator.
|
||||
type OptionSetter interface {
|
||||
SetTemplate(template io.Reader)
|
||||
SetFormat(format Func)
|
||||
SetOutput(output io.Writer)
|
||||
}
|
||||
|
||||
// WithTemplate assigns Template to Options.
|
||||
func WithTemplate(template io.Reader) Option {
|
||||
return func(setter OptionSetter) {
|
||||
setter.SetTemplate(template)
|
||||
}
|
||||
}
|
||||
|
||||
// WithFormat assigns Format to Options.
|
||||
func WithFormat(format Func) Option {
|
||||
return func(setter OptionSetter) {
|
||||
setter.SetFormat(format)
|
||||
}
|
||||
}
|
||||
|
||||
// WithOutput assigns Output to Options.
|
||||
func WithOutput(output io.Writer) Option {
|
||||
return func(setter OptionSetter) {
|
||||
setter.SetOutput(output)
|
||||
}
|
||||
}
|
||||
|
||||
type optionSetter struct {
|
||||
opts *Options
|
||||
}
|
||||
|
||||
func newOptionSetter(opts *Options) *optionSetter {
|
||||
return &optionSetter{opts: opts}
|
||||
}
|
||||
|
||||
func (s *optionSetter) SetTemplate(template io.Reader) {
|
||||
s.opts.Template = template
|
||||
}
|
||||
|
||||
func (s *optionSetter) SetFormat(format Func) {
|
||||
s.opts.Format = format
|
||||
}
|
||||
|
||||
func (s *optionSetter) SetOutput(output io.Writer) {
|
||||
s.opts.Output = output
|
||||
}
|
||||
|
||||
func setOptions(opts []Option, setter OptionSetter) {
|
||||
for _, opt := range opts {
|
||||
opt(setter)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue