updated dip

This commit is contained in:
Paul 2020-01-26 16:38:57 +01:00
parent f595597fc0
commit b831074864
196 changed files with 26267 additions and 801 deletions

5
.gitignore vendored
View File

@ -12,5 +12,8 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# VIM swap files
*.swp
*.ini
dip
dip

View File

@ -6,17 +6,23 @@ dip is a small webservice designed to return public ip address
### Build
Generate embedded static files and templates
```bash
go get github.com/gobuffalo/packr/v2
$GOPATH/bin/packr2
```
```bash
go build -mod vendor
```
### Play
Query webservice with html output
Query webservice with json output
curl http://localhost:8080/
Query webservice with json output
curl http://localhost:8080/json
Query webservice with html output
curl -H "Accept: text/html" http://localhost:8080/
## Todo
@ -38,4 +44,4 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the fuelprices project.
```
```

27
dip.go
View File

@ -3,9 +3,13 @@ package main
import (
"flag"
"fmt"
//"io/ioutil"
//"os"
//"strings"
"github.com/gobuffalo/packr"
"github.com/gobuffalo/packr/v2"
"github.com/labstack/echo/v4"
//"github.com/markbates/pkger"
)
func main() {
@ -13,22 +17,29 @@ func main() {
e.HideBanner = true
var host, port string
var templatesbox packr.Box
//var staticbox packr.Box
flag.Usage = Usage
flag.StringVar(&host, "host", "[::]", "Listen host")
flag.StringVar(&port, "port", "8080", "Listen port")
flag.Parse()
templatesbox = packr.NewBox("templates")
//staticbox = packr.NewBox("static")
templatesbox := packr.New("templates", "./templates")
staticbox := packr.New("static", "./static")
builttemplates, _ := BuildTemplates(templatesbox)
e.Renderer = builttemplates
//t := pkger.Dir("/templatefiles")
//fmt.Println(t)
//test2,_ := t.Open("index.html")
//test3,_ := ioutil.ReadAll(test2)
//fmt.Println(string(test3))
//io.Copy(os.Stdout,test2)
builtTemplates, _ := BuildTemplates(templatesbox)
e.Renderer = builtTemplates
e.GET("/", Dip)
e.GET("/test", Static)
e.GET("/static/*", func(c echo.Context) error {
return Static(staticbox, c)
})
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%s", host, port)))
}

View File

@ -9,6 +9,7 @@ import (
"os"
"strings"
"github.com/gobuffalo/packr/v2"
"github.com/labstack/echo/v4"
"github.com/likexian/whois-go"
whoisparser "github.com/likexian/whois-parser-go"
@ -48,10 +49,16 @@ func Dip(c echo.Context) (err error) {
}
}
// Static returns static files
func Static(c echo.Context) (err error) {
//static := c.Param("static")
return c.Render(http.StatusOK, "static/js/uikit-icons.js", "")
// Static ...
func Static(box *packr.Box, c echo.Context) (err error) {
name := c.Param("*")
cnt, _ := box.FindString(name)
if strings.HasSuffix(name, ".js") {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScript)
} else if strings.HasSuffix(name, ".css") {
c.Response().Header().Set(echo.HeaderContentType, "text/css")
}
return c.String(http.StatusOK, cnt)
}
// CheckIPAddress check if ip is an IP address, return err if there's an error
@ -96,4 +103,6 @@ func Usage() {
type IP struct {
IP string `json:"ip"`
Hostname string `json:"hostname"`
City string `json:"city"`
Country string `json:"country"`
}

3
go.mod
View File

@ -3,7 +3,7 @@ module dip
go 1.13
require (
github.com/gobuffalo/packr v1.30.1
github.com/gobuffalo/packr/v2 v2.7.1
github.com/labstack/echo/v4 v4.1.11
github.com/likexian/whois-go v1.3.1
github.com/likexian/whois-parser-go v1.10.2
@ -11,4 +11,5 @@ require (
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
)

25
go.sum
View File

@ -12,18 +12,20 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gobuffalo/envy v1.7.0 h1:GlXgaiBkmrYMHco6t4j7SacKO4XUjvh5pwXh0f4uxXU=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/logger v1.0.0/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs=
github.com/gobuffalo/envy v1.7.1 h1:OQl5ys5MBea7OGCdvPbBJWRgnhC/fGona6QKfvFeau8=
github.com/gobuffalo/envy v1.7.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
github.com/gobuffalo/logger v1.0.1 h1:ZEgyRGgAm4ZAhAO45YXMs5Fp+bzGLESFewzAVBMKuTg=
github.com/gobuffalo/logger v1.0.1/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs=
github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4=
github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q=
github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg=
github.com/gobuffalo/packr v1.30.1/go.mod h1:ljMyFO2EcrnzsHsN99cvbq055Y9OhRrIaviy289eRuk=
github.com/gobuffalo/packr/v2 v2.5.1/go.mod h1:8f9c96ITobJlPzI44jj+4tHnEKNt0xXWSVlXRN9X1Iw=
github.com/gobuffalo/packr/v2 v2.7.1 h1:n3CIW5T17T8v4GGK5sWXLVWJhCz7b5aNLSxW6gYim4o=
github.com/gobuffalo/packr/v2 v2.7.1/go.mod h1:qYEvAazPaVxy7Y7KR0W8qYEE+RymX74kETFqjFoFlOc=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@ -54,7 +56,11 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.4.0 h1:LUa41nrWTQNGhzdsZ5lTnkwbNjj6rXTdazA1cSdjkOY=
github.com/rogpeppe/go-internal v1.4.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
@ -81,12 +87,13 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49N
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -103,7 +110,9 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3 h1:2AmBLzhAfXj+2HCW09VCkJtHIYgHTIPcTeYqgP7Bwt0=
golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
@ -111,3 +120,5 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

8
main-packr.go Normal file
View File

@ -0,0 +1,8 @@
// +build !skippackr
// Code generated by github.com/gobuffalo/packr/v2. DO NOT EDIT.
// You can use the "packr clean" command to clean up this,
// and any other packr generated files.
package main
import _ "dip/packrd"

61
packrd/packed-packr.go Normal file

File diff suppressed because one or more lines are too long

4
static/css/font-awesome.min.css vendored Normal file

File diff suppressed because one or more lines are too long

32
static/css/main.css Normal file
View File

@ -0,0 +1,32 @@
/* Style buttons */
.buttonload {
background-color: #4CAF50; /* Green background */
border: none; /* Remove borders */
color: white; /* White text */
padding: 12px 16px; /* Some padding */
font-size: 16px /* Set a font size */
}
.btn {
background-color: #ddd;
border: none;
color: black;
padding: 16px 32px;
text-align: center;
font-size: 16px;
margin: 4px 2px;
transition: 0.3s;
}
.btn:hover {
background-color: #3e8e41;
color: white;
}
#dip_main_div {
margin: 10px;
}
.dip_p {
color: grey;
}

3
static/js/main.js Normal file
View File

@ -0,0 +1,3 @@
function page_refresh() {
location.reload();
}

View File

@ -1,11 +1,14 @@
package main
import (
//"bytes"
//"fmt"
"html/template"
"io"
"strings"
"github.com/gobuffalo/packr"
//"github.com/gobuffalo/packr"
"github.com/gobuffalo/packr/v2"
"github.com/labstack/echo/v4"
)
@ -15,20 +18,16 @@ type Template struct {
}
// Render is a method that render templates
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) (err error) {
if strings.HasSuffix(name, ".html") {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
} else if strings.HasSuffix(name, ".js") {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextPlain)
} else if strings.HasSuffix(name, ".css") {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextPlain)
}
return t.templates.ExecuteTemplate(w, name, data)
}
// BuildTemplates converts packr packages to html/template
func BuildTemplates(box packr.Box) (builttemplates *Template, err error) {
tmpl := template.New("template")
func BuildTemplates(box *packr.Box) (builttemplates *Template, err error) {
tmpl := template.New("templates")
for _, filename := range box.List() {
tmplContent, _ := box.FindString(filename)

View File

@ -1,6 +1,9 @@
<title>Public IP Address</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/uikit.min.css" />
<script src="js/uikit.min.js"></script>
<script src="js/uikit-icons.min.js"></script>
<title>Public IP Address</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/css/main.css" />
<link rel="stylesheet" href="static/css/uikit.min.css" />
<link rel="stylesheet" href="static/css/font-awesome.min.css" />
<script src="static/js/main.js"></script>
<script src="static/js/uikit.min.js"></script>
<script src="static/js/uikit-icons.min.js"></script>

View File

@ -1,9 +1,29 @@
<html>
<head>
{{ template "head.html" .}}
</head>
<body>
<h1>IP : {{ .IP }}</h1>
<h2>Reverse DNS : {{ .Hostname }}</h2>
</body>
<head>
{{ template "head.html" .}}
</head>
<body>
<div id="dip_main_div">
<h1 class="dip_h1">Public IP Address Service</h1>
<table class="uk-table uk-table-striped uk-table-hover">
<caption>IP informations</caption>
<tr>
<td>IP</td>
<td>{{ .IP }}</td>
</tr>
<tr>
<td>Reverse DNS</td>
<td>{{ .Hostname }}</td>
</tr>
<tr>
<td>City</td>
<td>{{ .City }}</td>
</tr>
<tr>
<td>Country</td>
<td>{{ .Country }}</td>
</tr>
<button class="dip_btn" onclick="page_refresh()">Refresh</button>
</div>
</body>
</html>

5
vendor/github.com/gobuffalo/envy/.env generated vendored Normal file
View File

@ -0,0 +1,5 @@
# This is a comment
# We can use equal or colon notation
DIR: root
FLAVOUR: none
INSIDE_FOLDER=false

View File

@ -3,7 +3,6 @@
doc
tmp
pkg
*.gem
*.pid
coverage
coverage.data
@ -14,8 +13,6 @@ build/*
profile
.console_history
.sass-cache/*
.rake_tasks~
*.log.lck
solr/
.jhw-cache/
jhw.*
@ -27,4 +24,4 @@ generated/
bin/*
gin-bin
.idea/
.env
.vscode

21
vendor/github.com/gobuffalo/envy/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 Mark Bates
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.

View File

@ -1,46 +1,62 @@
TAGS ?= "sqlite"
GO_BIN ?= go
TAGS ?= ""
GO_BIN ?= "go"
GO_ENV ?= "test"
install:
packr2
$(GO_BIN) install -v .
$(GO_BIN) install -tags ${TAGS} -v .
make tidy
deps:
$(GO_BIN) get github.com/gobuffalo/release
$(GO_BIN) get github.com/gobuffalo/packr/v2/packr2
$(GO_BIN) get -tags ${TAGS} -t ./...
tidy:
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
else
echo skipping go mod tidy
endif
deps:
$(GO_BIN) get -tags ${TAGS} -t ./...
make tidy
build:
packr2
$(GO_BIN) build -v .
make tidy
test:
packr2
$(GO_BIN) test -tags ${TAGS} ./...
$(GO_BIN) test -cover -tags ${TAGS} ./...
make tidy
ci-deps:
$(GO_BIN) get -tags ${TAGS} -t ./...
ci-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
lint:
gometalinter --vendor ./... --deadline=1m --skip=internal
go get github.com/golangci/golangci-lint/cmd/golangci-lint
golangci-lint run --enable-all
make tidy
update:
$(GO_BIN) get -u -tags ${TAGS}
ifeq ($(GO111MODULE),on)
rm go.*
$(GO_BIN) mod init
$(GO_BIN) mod tidy
else
$(GO_BIN) get -u -tags ${TAGS}
endif
packr2
make test
make install
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
endif
make tidy
release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy
release:
release -y -f version.go
$(GO_BIN) get github.com/gobuffalo/release
make tidy
release -y -f version.go --skip-packr
make tidy

View File

@ -9,6 +9,22 @@ Thank you to the following **GIANTS**:
* [github.com/joho/godotenv](https://godoc.org/github.com/joho/godotenv)
* [github.com/kr/pretty](https://godoc.org/github.com/kr/pretty)
* [github.com/kr/pty](https://godoc.org/github.com/kr/pty)
* [github.com/kr/text](https://godoc.org/github.com/kr/text)
* [github.com/pmezard/go-difflib](https://godoc.org/github.com/pmezard/go-difflib)
* [github.com/rogpeppe/go-internal](https://godoc.org/github.com/rogpeppe/go-internal)
* [github.com/stretchr/objx](https://godoc.org/github.com/stretchr/objx)
* [github.com/stretchr/testify](https://godoc.org/github.com/stretchr/testify)
* [gopkg.in/check.v1](https://godoc.org/gopkg.in/check.v1)
* [gopkg.in/errgo.v2](https://godoc.org/gopkg.in/errgo.v2)
* [gopkg.in/yaml.v2](https://godoc.org/gopkg.in/yaml.v2)

View File

@ -1,4 +1,5 @@
variables:
GOPROXY: "https://proxy.golang.org"
GOBIN: "$(GOPATH)/bin" # Go binaries path
GOPATH: "$(system.defaultWorkingDirectory)/gopath" # Go workspace path
modulePath: "$(GOPATH)/src/github.com/$(build.repository.name)" # Path to the module"s code
@ -9,15 +10,17 @@ jobs:
vmImage: "vs2017-win2016"
strategy:
matrix:
go 1.9:
go_version: "1.9"
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11"
go 1.12 (on):
go_version: "1.12.9"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11"
go 1.12 (off):
go_version: "1.12.9"
GO111MODULE: "off"
go 1.13 (on):
go_version: "1.13"
GO111MODULE: "on"
go 1.13 (off):
go_version: "1.13"
GO111MODULE: "off"
steps:
- template: azure-tests.yml
@ -27,15 +30,17 @@ jobs:
vmImage: "macOS-10.13"
strategy:
matrix:
go 1.9:
go_version: "1.9"
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11"
go 1.12 (on):
go_version: "1.12.9"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11"
go 1.12 (off):
go_version: "1.12.9"
GO111MODULE: "off"
go 1.13 (on):
go_version: "1.13"
GO111MODULE: "on"
go 1.13 (off):
go_version: "1.13"
GO111MODULE: "off"
steps:
- template: azure-tests.yml
@ -45,15 +50,17 @@ jobs:
vmImage: "ubuntu-16.04"
strategy:
matrix:
go 1.9:
go_version: "1.9"
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11"
go 1.12 (on):
go_version: "1.12.9"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11"
go 1.12 (off):
go_version: "1.12.9"
GO111MODULE: "off"
go 1.13 (on):
go_version: "1.13"
GO111MODULE: "on"
go 1.13 (off):
go_version: "1.13"
GO111MODULE: "off"
steps:
- template: azure-tests.yml

View File

@ -1,8 +1,10 @@
module github.com/gobuffalo/envy
go 1.13
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/joho/godotenv v1.3.0
github.com/rogpeppe/go-internal v1.1.0
github.com/stretchr/testify v1.3.0
github.com/rogpeppe/go-internal v1.3.2
github.com/stretchr/testify v1.4.0
)

View File

@ -1,17 +1,24 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.1.0 h1:g0fH8RicVgNl+zVZDCDfbdWxAWoAEJyI7I3TZYXFiig=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.2 h1:XU784Pr0wdahMY2bYcyK6N1KuaRAdLtqD4qd8D18Bfs=
github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -1,3 +1,3 @@
package envy
const Version = "v1.7.0"
const Version = "v1.7.1"

View File

@ -1,5 +1,4 @@
*.log
./packr2
.DS_Store
doc
tmp
@ -27,10 +26,4 @@ generated/
.vendor/
bin/*
gin-bin
/packr_darwin_amd64
/packr_linux_amd64
.vscode/
debug.test
.grifter/
*-packr.go
.idea/

21
vendor/github.com/gobuffalo/logger/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 Mark Bates
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.

61
vendor/github.com/gobuffalo/logger/Makefile generated vendored Normal file
View File

@ -0,0 +1,61 @@
TAGS ?= ""
GO_BIN ?= "go"
install:
$(GO_BIN) install -tags ${TAGS} -v .
make tidy
tidy:
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
else
echo skipping go mod tidy
endif
deps:
$(GO_BIN) get -tags ${TAGS} -t ./...
make tidy
build:
$(GO_BIN) build -v .
make tidy
test:
$(GO_BIN) test -cover -tags ${TAGS} ./...
make tidy
ci-deps:
$(GO_BIN) get -tags ${TAGS} -t ./...
ci-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
lint:
go get github.com/golangci/golangci-lint/cmd/golangci-lint
golangci-lint run --enable-all
make tidy
update:
ifeq ($(GO111MODULE),on)
rm go.*
$(GO_BIN) mod init
$(GO_BIN) mod tidy
else
$(GO_BIN) get -u -tags ${TAGS}
endif
make test
make install
make tidy
release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy
release:
$(GO_BIN) get github.com/gobuffalo/release
make tidy
release -y -f version.go --skip-packr
make tidy

22
vendor/github.com/gobuffalo/logger/README.md generated vendored Normal file
View File

@ -0,0 +1,22 @@
<p align="center"><img src="https://github.com/gobuffalo/buffalo/blob/master/logo.svg" width="360"></p>
<p align="center">
<a href="https://godoc.org/github.com/gobuffalo/logger"><img src="https://godoc.org/github.com/gobuffalo/logger?status.svg" alt="GoDoc" /></a>
<a href="https://travis-ci.org/gobuffalo/logger"><img src="https://travis-ci.org/gobuffalo/logger.svg?branch=master" alt="Build Status" /></a>
<a href="https://goreportcard.com/report/github.com/gobuffalo/logger"><img src="https://goreportcard.com/badge/github.com/gobuffalo/logger" alt="Go Report Card" /></a>
</p>
# Logger
The [`logger.Logger`](https://godoc.org/github.com/gobuffalo/logger#Logger) interface is used throughout Buffalo apps, and other systems, to log a whole manner of things.
## Installation
```bash
$ go get -u github.com/gobuffalo/logger
```
## Documentation
* [GoDoc](https://godoc.org/github.com/gobuffalo/logger)
* [General Buffalo Documentation](https://gobuffalo.io)

18
vendor/github.com/gobuffalo/logger/SHOULDERS.md generated vendored Normal file
View File

@ -0,0 +1,18 @@
# github.com/gobuffalo/logger Stands on the Shoulders of Giants
github.com/gobuffalo/logger does not try to reinvent the wheel! Instead, it uses the already great wheels developed by the Go community and puts them all together in the best way possible. Without these giants, this project would not be possible. Please make sure to check them out and thank them for all of their hard work.
Thank you to the following **GIANTS**:
* [github.com/gobuffalo/envy](https://godoc.org/github.com/gobuffalo/envy)
* [github.com/konsorten/go-windows-terminal-sequences](https://godoc.org/github.com/konsorten/go-windows-terminal-sequences)
* [github.com/rogpeppe/go-internal](https://godoc.org/github.com/rogpeppe/go-internal)
* [github.com/sirupsen/logrus](https://godoc.org/github.com/sirupsen/logrus)
* [golang.org/x/crypto](https://godoc.org/golang.org/x/crypto)
* [golang.org/x/sys](https://godoc.org/golang.org/x/sys)

View File

@ -15,10 +15,5 @@ steps:
- script: |
go get -t -v ./...
go test -race ./...
go install -v ./packr
cd v2
go get -t -v ./...
go test -race ./...
go install -v ./packr2
workingDirectory: "$(modulePath)"
displayName: "Tests"

154
vendor/github.com/gobuffalo/logger/formatter.go generated vendored Normal file
View File

@ -0,0 +1,154 @@
package logger
// I really don't want to have this, but until (if) https://github.com/sirupsen/logrus/pull/606 is merged we're stuck with all this code. And yes, this is ALL needed just to remove some blank space in the logs
import (
"bytes"
"fmt"
"sort"
"strings"
"sync"
"time"
"github.com/sirupsen/logrus"
)
const (
red = 31
yellow = 33
blue = 36
gray = 37
)
// textFormatter formats logs into text
type textFormatter struct {
ForceColors bool
isTerminal bool
sync.Once
}
func (f *textFormatter) init(entry *logrus.Entry) {
if entry.Logger != nil {
f.isTerminal = checkIfTerminal(entry.Logger.Out)
}
}
const defaultTimestampFormat = time.RFC3339
// Format renders a single log entry
func (f *textFormatter) Format(entry *logrus.Entry) ([]byte, error) {
prefixFieldClashes(entry.Data)
keys := make([]string, 0, len(entry.Data))
for k := range entry.Data {
keys = append(keys, k)
}
sort.Strings(keys)
var b *bytes.Buffer
if entry.Buffer != nil {
b = entry.Buffer
} else {
b = &bytes.Buffer{}
}
f.Do(func() { f.init(entry) })
isColored := (f.ForceColors || f.isTerminal)
if isColored {
f.printColored(b, entry, keys)
} else {
f.appendKeyValue(b, "level", entry.Level.String())
f.appendKeyValue(b, "time", entry.Time.Format(defaultTimestampFormat))
if entry.Message != "" {
f.appendKeyValue(b, "msg", entry.Message)
}
for _, key := range keys {
f.appendKeyValue(b, key, entry.Data[key])
}
}
b.WriteByte('\n')
return b.Bytes(), nil
}
func (f *textFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry, keys []string) {
var levelColor int
switch entry.Level {
case logrus.DebugLevel:
levelColor = gray
case logrus.WarnLevel:
levelColor = yellow
case logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel:
levelColor = red
default:
levelColor = blue
}
levelText := strings.ToUpper(entry.Level.String())[0:4]
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s]", levelColor, levelText, entry.Time.Format(defaultTimestampFormat))
if entry.Message != "" {
fmt.Fprintf(b, " %s", entry.Message)
}
for _, k := range keys {
v := entry.Data[k]
fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k)
f.appendValue(b, v)
}
}
func (f *textFormatter) needsQuoting(text string) bool {
if len(text) == 0 {
return true
}
for _, ch := range text {
if !((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9') ||
ch == '-' || ch == '.' || ch == '_' || ch == '/' || ch == '@' || ch == '^' || ch == '+') {
return true
}
}
return false
}
func (f *textFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) {
if b.Len() > 0 {
b.WriteByte(' ')
}
b.WriteString(key)
b.WriteByte('=')
f.appendValue(b, value)
}
func (f *textFormatter) appendValue(b *bytes.Buffer, value interface{}) {
stringVal, ok := value.(string)
if !ok {
stringVal = fmt.Sprint(value)
}
if !f.needsQuoting(stringVal) {
b.WriteString(stringVal)
} else {
b.WriteString(fmt.Sprintf("%q", stringVal))
}
}
func prefixFieldClashes(data logrus.Fields) {
if t, ok := data["time"]; ok {
data["fields.time"] = t
}
if m, ok := data["msg"]; ok {
data["fields.msg"] = m
}
if l, ok := data["level"]; ok {
data["fields.level"] = l
}
}

12
vendor/github.com/gobuffalo/logger/go.mod generated vendored Normal file
View File

@ -0,0 +1,12 @@
module github.com/gobuffalo/logger
go 1.12
require (
github.com/gobuffalo/envy v1.7.0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/rogpeppe/go-internal v1.3.0 // indirect
github.com/sirupsen/logrus v1.4.2
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 // indirect
)

40
vendor/github.com/gobuffalo/logger/go.sum generated vendored Normal file
View File

@ -0,0 +1,40 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gobuffalo/envy v1.7.0 h1:GlXgaiBkmrYMHco6t4j7SacKO4XUjvh5pwXh0f4uxXU=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.1.0 h1:g0fH8RicVgNl+zVZDCDfbdWxAWoAEJyI7I3TZYXFiig=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 h1:khxRGsvPk4n2y8I/mLLjp7e5dMTJmH75wvqS6nMwUtY=
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=

25
vendor/github.com/gobuffalo/logger/level.go generated vendored Normal file
View File

@ -0,0 +1,25 @@
package logger
import "github.com/sirupsen/logrus"
// Level of the logger
type Level = logrus.Level
const (
// PanicLevel level, highest level of severity. Logs and then calls panic with the
// message passed to Debug, Info, ...
PanicLevel = logrus.PanicLevel
// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
// logging level is set to Panic.
FatalLevel = logrus.FatalLevel
// ErrorLevel level. Logs. Used for errors that should definitely be noted.
// Commonly used for hooks to send errors to an error tracking service.
ErrorLevel = logrus.ErrorLevel
// WarnLevel level. Non-critical entries that deserve eyes.
WarnLevel = logrus.WarnLevel
// InfoLevel level. General operational entries about what's going on inside the
// application.
InfoLevel = logrus.InfoLevel
// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
DebugLevel = logrus.DebugLevel
)

64
vendor/github.com/gobuffalo/logger/logger.go generated vendored Normal file
View File

@ -0,0 +1,64 @@
package logger
import (
"os"
"github.com/gobuffalo/envy"
"github.com/sirupsen/logrus"
)
// FieldLogger interface
type FieldLogger interface {
Logger
WithField(string, interface{}) FieldLogger
WithFields(map[string]interface{}) FieldLogger
}
// Logger interface is used throughout Buffalo
// apps to log a whole manner of things.
type Logger interface {
Debugf(string, ...interface{})
Infof(string, ...interface{})
Printf(string, ...interface{})
Warnf(string, ...interface{})
Errorf(string, ...interface{})
Fatalf(string, ...interface{})
Debug(...interface{})
Info(...interface{})
Warn(...interface{})
Error(...interface{})
Fatal(...interface{})
Panic(...interface{})
}
func ParseLevel(level string) (Level, error) {
l, err := logrus.ParseLevel(level)
return Level(l), err
}
// NewLogger based on the specified log level, defaults to "debug".
// See `New` for more details.
func NewLogger(level string) FieldLogger {
lvl, err := logrus.ParseLevel(level)
if err != nil {
lvl = logrus.DebugLevel
}
return New(lvl)
}
// New based on the specified log level, defaults to "debug".
// This logger will log to the STDOUT in a human readable,
// but parseable form.
/*
Example: time="2016-12-01T21:02:07-05:00" level=info duration=225.283µs human_size="106 B" method=GET path="/" render=199.79µs request_id=2265736089 size=106 status=200
*/
func New(lvl Level) FieldLogger {
dev := envy.Get("GO_ENV", "development") == "development"
l := logrus.New()
l.SetOutput(os.Stdout)
l.Level = lvl
l.Formatter = &textFormatter{
ForceColors: dev,
}
return Logrus{l}
}

34
vendor/github.com/gobuffalo/logger/logrus.go generated vendored Normal file
View File

@ -0,0 +1,34 @@
package logger
import (
"io"
"github.com/sirupsen/logrus"
)
var _ Logger = Logrus{}
var _ FieldLogger = Logrus{}
var _ Outable = Logrus{}
// Logrus is a Logger implementation backed by sirupsen/logrus
type Logrus struct {
logrus.FieldLogger
}
// SetOutput will try and set the output of the underlying
// logrus.FieldLogger if it can
func (l Logrus) SetOutput(w io.Writer) {
if lg, ok := l.FieldLogger.(Outable); ok {
lg.SetOutput(w)
}
}
// WithField returns a new Logger with the field added
func (l Logrus) WithField(s string, i interface{}) FieldLogger {
return Logrus{l.FieldLogger.WithField(s, i)}
}
// WithFields returns a new Logger with the fields added
func (l Logrus) WithFields(m map[string]interface{}) FieldLogger {
return Logrus{l.FieldLogger.WithFields(m)}
}

8
vendor/github.com/gobuffalo/logger/outable.go generated vendored Normal file
View File

@ -0,0 +1,8 @@
package logger
import "io"
// Outable interface for loggers that allow setting the output writer
type Outable interface {
SetOutput(out io.Writer)
}

19
vendor/github.com/gobuffalo/logger/terminal_check.go generated vendored Normal file
View File

@ -0,0 +1,19 @@
// +build !appengine
package logger
import (
"io"
"os"
"golang.org/x/crypto/ssh/terminal"
)
func checkIfTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
return terminal.IsTerminal(int(v.Fd()))
default:
return false
}
}

View File

@ -0,0 +1,11 @@
// +build appengine
package logger
import (
"io"
)
func checkIfTerminal(w io.Writer) bool {
return true
}

4
vendor/github.com/gobuffalo/logger/version.go generated vendored Normal file
View File

@ -0,0 +1,4 @@
package logger
// Version of the logger
const Version = "v1.0.1"

View File

@ -1,20 +0,0 @@
---
engines:
golint:
enabled: true
checks:
GoLint/Naming/MixedCaps:
enabled: false
govet:
enabled: true
gofmt:
enabled: true
fixme:
enabled: true
ratings:
paths:
- "**.go"
exclude_paths:
- "**/*_test.go"
- "*_test.go"
- "fixtures/"

View File

@ -1,205 +0,0 @@
# packr (v1)
[![GoDoc](https://godoc.org/github.com/gobuffalo/packr?status.svg)](https://godoc.org/github.com/gobuffalo/packr)
## Packr has been updated to `v2`! Please read the `./v2/README.md` file for more details.
---
Packr is a simple solution for bundling static assets inside of Go binaries. Most importantly it does it in a way that is friendly to developers while they are developing.
## Intro Video
To get an idea of the what and why of packr, please enjoy this short video: [https://vimeo.com/219863271](https://vimeo.com/219863271).
## Installation
To install Packr utility
```text
$ go get -u github.com/gobuffalo/packr/packr
```
To get the dependency
```text
$ go get -u github.com/gobuffalo/packr
```
## Usage
### In Code
The first step in using Packr is to create a new box. A box represents a folder on disk. Once you have a box you can get `string` or `[]byte` representations of the file.
```go
// set up a new box by giving it a (relative) path to a folder on disk:
box := packr.NewBox("./templates")
// Get the string representation of a file, or an error if it doesn't exist:
html, err := box.FindString("index.html")
// Get the []byte representation of a file, or an error if it doesn't exist:
html, err := box.FindBytes("index.html")
```
### What is a Box?
A box represents a folder, and any sub-folders, on disk that you want to have access to in your binary. When compiling a binary using the `packr` CLI the contents of the folder will be converted into Go files that can be compiled inside of a "standard" go binary. Inside of the compiled binary the files will be read from memory. When working locally the files will be read directly off of disk. This is a seamless switch that doesn't require any special attention on your part.
#### Example
Assume the follow directory structure:
```
├── main.go
└── templates
├── admin
│   └── index.html
└── index.html
```
The following program will read the `./templates/admin/index.html` file and print it out.
```go
package main
import (
"fmt"
"github.com/gobuffalo/packr"
)
func main() {
box := packr.NewBox("./templates")
s, err := box.FindString("admin/index.html")
if err != nil {
log.Fatal(err)
}
fmt.Println(s)
}
```
### Development Made Easy
In order to get static files into a Go binary, those files must first be converted to Go code. To do that, Packr, ships with a few tools to help build binaries. See below.
During development, however, it is painful to have to keep running a tool to compile those files.
Packr uses the following resolution rules when looking for a file:
1. Look for the file in-memory (inside a Go binary)
1. Look for the file on disk (during development)
Because Packr knows how to fall through to the file system, developers don't need to worry about constantly compiling their static files into a binary. They can work unimpeded.
Packr takes file resolution a step further. When declaring a new box you use a relative path, `./templates`. When Packr receives this call it calculates out the absolute path to that directory. By doing this it means you can be guaranteed that Packr can find your files correctly, even if you're not running in the directory that the box was created in. This helps with the problem of testing, where Go changes the `pwd` for each package, making relative paths difficult to work with. This is not a problem when using Packr.
---
## Usage with HTTP
A box implements the [`http.FileSystem`](https://golang.org/pkg/net/http/#FileSystem) interface, meaning it can be used to serve static files.
```go
package main
import (
"net/http"
"github.com/gobuffalo/packr"
)
func main() {
box := packr.NewBox("./templates")
http.Handle("/", http.FileServer(box))
http.ListenAndServe(":3000", nil)
}
```
---
## Building a Binary (the easy way)
When it comes time to build, or install, your Go binary, simply use `packr build` or `packr install` just as you would `go build` or `go install`. All flags for the `go` tool are supported and everything works the way you expect, the only difference is your static assets are now bundled in the generated binary. If you want more control over how this happens, looking at the following section on building binaries (the hard way).
## Building a Binary (the hard way)
Before you build your Go binary, run the `packr` command first. It will look for all the boxes in your code and then generate `.go` files that pack the static files into bytes that can be bundled into the Go binary.
```
$ packr
```
Then run your `go build command` like normal.
*NOTE*: It is not recommended to check-in these generated `-packr.go` files. They can be large, and can easily become out of date if not careful. It is recommended that you always run `packr clean` after running the `packr` tool.
#### Cleaning Up
When you're done it is recommended that you run the `packr clean` command. This will remove all of the generated files that Packr created for you.
```
$ packr clean
```
Why do you want to do this? Packr first looks to the information stored in these generated files, if the information isn't there it looks to disk. This makes it easy to work with in development.
---
## Building/Moving a portable release
When it comes to building multiple releases you typically want that release to be built in a specific directory.
For example: `./releases`
However, because passing a `.go` file requires absolute paths, we must compile the release in the appropriate absolute path.
```bash
GOOS=linux GOARCH=amd64 packr build
```
Now your `project_name` binary will be built at the root of your project dir. Great!
All that is left to do is to move that binary to your release dir:
Linux/macOS/Windows (bash)
```bash
mv ./project_name ./releases
```
Windows (cmd):
```cmd
move ./project_name ./releases
```
Powershell:
```powershell
Move-Item -Path .\project_name -Destination .\releases\
```
If you _target_ for Windows when building don't forget that it's `project_name.exe`
Now you can make multiple releases and all of your needed static files will be available!
#### Summing it up:
Example Script for building to 3 common targets:
```bash
GOOS=darwin GOARCH=amd64 packr build && mv ./project_name ./releases/darwin-project_name \
&& GOOS=linux GOARCH=amd64 packr build && mv ./project_name ./releases/linux-project_name \
&& GOOS=windows GOARCH=386 packr build && mv ./project_name.exe ./releases/project_name.exe \
&& packr clean
```
---
## Debugging
The `packr` command passes all arguments down to the underlying `go` command, this includes the `-v` flag to print out `go build` information. Packr looks for the `-v` flag, and will turn on its own verbose logging. This is very useful for trying to understand what the `packr` command is doing when it is run.

View File

@ -1,18 +0,0 @@
# github.com/gobuffalo/packr Stands on the Shoulders of Giants
github.com/gobuffalo/packr does not try to reinvent the wheel! Instead, it uses the already great wheels developed by the Go community and puts them all together in the best way possible. Without these giants, this project would not be possible. Please make sure to check them out and thank them for all of their hard work.
Thank you to the following **GIANTS**:
* [github.com/gobuffalo/envy](https://godoc.org/github.com/gobuffalo/envy)
* [github.com/gobuffalo/packd](https://godoc.org/github.com/gobuffalo/packd)
* [github.com/gobuffalo/packr/v2](https://godoc.org/github.com/gobuffalo/packr/v2)
* [github.com/spf13/cobra](https://godoc.org/github.com/spf13/cobra)
* [github.com/stretchr/testify](https://godoc.org/github.com/stretchr/testify)
* [golang.org/x/sync](https://godoc.org/golang.org/x/sync)

View File

@ -1,228 +0,0 @@
package packr
import (
"bytes"
"compress/gzip"
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"github.com/gobuffalo/packd"
)
var (
// ErrResOutsideBox gets returned in case of the requested resources being outside the box
ErrResOutsideBox = fmt.Errorf("Can't find a resource outside the box")
)
var _ packd.Box = Box{}
var _ packd.HTTPBox = Box{}
var _ packd.Lister = Box{}
var _ packd.Addable = Box{}
var _ packd.Walkable = Box{}
var _ packd.Finder = Box{}
var _ packd.LegacyBox = Box{}
// NewBox returns a Box that can be used to
// retrieve files from either disk or the embedded
// binary.
func NewBox(path string) Box {
var cd string
if !filepath.IsAbs(path) {
_, filename, _, _ := runtime.Caller(1)
cd = filepath.Dir(filename)
}
// this little hack courtesy of the `-cover` flag!!
cov := filepath.Join("_test", "_obj_test")
cd = strings.Replace(cd, string(filepath.Separator)+cov, "", 1)
if !filepath.IsAbs(cd) && cd != "" {
cd = filepath.Join(GoPath(), "src", cd)
}
return Box{
Path: path,
callingDir: cd,
data: map[string][]byte{},
}
}
// Box represent a folder on a disk you want to
// have access to in the built Go binary.
type Box struct {
Path string
callingDir string
data map[string][]byte
directories map[string]bool
}
// AddString converts t to a byteslice and delegates to AddBytes to add to b.data
func (b Box) AddString(path string, t string) error {
b.AddBytes(path, []byte(t))
return nil
}
// AddBytes sets t in b.data by the given path
func (b Box) AddBytes(path string, t []byte) error {
b.data[path] = t
return nil
}
// Deprecated: Use FindString instead.
func (b Box) String(name string) string {
bb, _ := b.FindString(name)
return bb
}
// Deprecated: Use FindString instead.
func (b Box) MustString(name string) (string, error) {
return b.FindString(name)
}
// Deprecated: Use Find instead.
func (b Box) Bytes(name string) []byte {
bb, _ := b.Find(name)
return bb
}
// Deprecated: Use Find instead.
func (b Box) MustBytes(name string) ([]byte, error) {
return b.Find(name)
}
// FindString returns either the string of the requested
// file or an error if it can not be found.
func (b Box) FindString(name string) (string, error) {
bb, err := b.Find(name)
return string(bb), err
}
// Find returns either the byte slice of the requested
// file or an error if it can not be found.
func (b Box) Find(name string) ([]byte, error) {
f, err := b.find(name)
if err == nil {
bb := &bytes.Buffer{}
bb.ReadFrom(f)
return bb.Bytes(), err
}
return nil, err
}
// Has returns true if the resource exists in the box
func (b Box) Has(name string) bool {
_, err := b.find(name)
if err != nil {
return false
}
return true
}
func (b Box) decompress(bb []byte) []byte {
reader, err := gzip.NewReader(bytes.NewReader(bb))
if err != nil {
return bb
}
defer reader.Close()
data, err := ioutil.ReadAll(reader)
if err != nil {
return bb
}
return data
}
func (b Box) find(name string) (File, error) {
if bb, ok := b.data[name]; ok {
return packd.NewFile(name, bytes.NewReader(bb))
}
if b.directories == nil {
b.indexDirectories()
}
cleanName := filepath.ToSlash(filepath.Clean(name))
// Ensure name is not outside the box
if strings.HasPrefix(cleanName, "../") {
return nil, ErrResOutsideBox
}
// Absolute name is considered as relative to the box root
cleanName = strings.TrimPrefix(cleanName, "/")
if _, ok := data[b.Path]; ok {
if bb, ok := data[b.Path][cleanName]; ok {
bb = b.decompress(bb)
return packd.NewFile(cleanName, bytes.NewReader(bb))
}
if _, ok := b.directories[cleanName]; ok {
return packd.NewDir(cleanName)
}
if filepath.Ext(cleanName) != "" {
// The Handler created by http.FileSystem checks for those errors and
// returns http.StatusNotFound instead of http.StatusInternalServerError.
return nil, os.ErrNotExist
}
return nil, os.ErrNotExist
}
// Not found in the box virtual fs, try to get it from the file system
cleanName = filepath.FromSlash(cleanName)
p := filepath.Join(b.callingDir, b.Path, cleanName)
return fileFor(p, cleanName)
}
// Open returns a File using the http.File interface
func (b Box) Open(name string) (http.File, error) {
return b.find(name)
}
// List shows "What's in the box?"
func (b Box) List() []string {
var keys []string
if b.data == nil || len(b.data) == 0 {
b.Walk(func(path string, info File) error {
finfo, _ := info.FileInfo()
if !finfo.IsDir() {
keys = append(keys, finfo.Name())
}
return nil
})
} else {
for k := range b.data {
keys = append(keys, k)
}
}
return keys
}
func (b *Box) indexDirectories() {
b.directories = map[string]bool{}
if _, ok := data[b.Path]; ok {
for name := range data[b.Path] {
prefix, _ := path.Split(name)
// Even on Windows the suffix appears to be a /
prefix = strings.TrimSuffix(prefix, "/")
b.directories[prefix] = true
}
}
}
func fileFor(p string, name string) (File, error) {
fi, err := os.Stat(p)
if err != nil {
return nil, err
}
if fi.IsDir() {
return packd.NewDir(p)
}
if bb, err := ioutil.ReadFile(p); err == nil {
return packd.NewFile(name, bytes.NewReader(bb))
}
return nil, os.ErrNotExist
}

View File

@ -1,13 +0,0 @@
package packr
import (
"github.com/gobuffalo/envy"
)
// GoPath returns the current GOPATH env var
// or if it's missing, the default.
var GoPath = envy.GoPath
// GoBin returns the current GO_BIN env var
// or if it's missing, a default of "go"
var GoBin = envy.GoBin

View File

@ -1,5 +0,0 @@
package packr
import "github.com/gobuffalo/packd"
type File = packd.File

View File

@ -1,12 +0,0 @@
module github.com/gobuffalo/packr
go 1.12
require (
github.com/gobuffalo/envy v1.7.0
github.com/gobuffalo/packd v0.3.0
github.com/gobuffalo/packr/v2 v2.5.1
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.3.0
golang.org/x/sync v0.0.0-20190423024810-112230192c58
)

View File

@ -1,74 +0,0 @@
package packr
import (
"bytes"
"compress/gzip"
"encoding/json"
"runtime"
"strings"
"sync"
)
var gil = &sync.Mutex{}
var data = map[string]map[string][]byte{}
// PackBytes packs bytes for a file into a box.
func PackBytes(box string, name string, bb []byte) {
gil.Lock()
defer gil.Unlock()
if _, ok := data[box]; !ok {
data[box] = map[string][]byte{}
}
data[box][name] = bb
}
// PackBytesGzip packets the gzipped compressed bytes into a box.
func PackBytesGzip(box string, name string, bb []byte) error {
var buf bytes.Buffer
w := gzip.NewWriter(&buf)
_, err := w.Write(bb)
if err != nil {
return err
}
err = w.Close()
if err != nil {
return err
}
PackBytes(box, name, buf.Bytes())
return nil
}
// PackJSONBytes packs JSON encoded bytes for a file into a box.
func PackJSONBytes(box string, name string, jbb string) error {
var bb []byte
err := json.Unmarshal([]byte(jbb), &bb)
if err != nil {
return err
}
PackBytes(box, name, bb)
return nil
}
// UnpackBytes unpacks bytes for specific box.
func UnpackBytes(box string) {
gil.Lock()
defer gil.Unlock()
delete(data, box)
}
func osPaths(paths ...string) []string {
if runtime.GOOS == "windows" {
for i, path := range paths {
paths[i] = strings.Replace(path, "/", "\\", -1)
}
}
return paths
}
func osPath(path string) string {
if runtime.GOOS == "windows" {
return strings.Replace(path, "/", "\\", -1)
}
return path
}

View File

@ -7,10 +7,19 @@ builds:
- darwin
- linux
- windows
goarch:
- ppc64le
- 386
- amd64
env:
- CGO_ENABLED=0
main: ./packr/main.go
binary: packr
ignore:
- goos: darwin
goarch: ppc64le
- goos: windows
goarch: ppc64le
main: ./packr2/main.go
binary: packr2
checksum:
name_template: 'checksums.txt'
@ -25,8 +34,9 @@ changelog:
- '^docs:'
- '^test:'
brew:
github:
owner: gobuffalo
name: homebrew-tap
brews:
-
github:
owner: gobuffalo
name: homebrew-tap

View File

@ -4,10 +4,19 @@ builds:
- darwin
- linux
- windows
goarch:
- ppc64le
- 386
- amd64
env:
- CGO_ENABLED=0
main: ./packr/main.go
binary: packr
ignore:
- goos: darwin
goarch: ppc64le
- goos: windows
goarch: ppc64le
main: ./packr2/main.go
binary: packr2
checksum:
name_template: 'checksums.txt'
@ -22,8 +31,9 @@ changelog:
- '^docs:'
- '^test:'
<%= if (brew) { %>
brew:
github:
owner: gobuffalo
name: homebrew-tap
brews:
-
github:
owner: gobuffalo
name: homebrew-tap
<% } %>

47
vendor/github.com/gobuffalo/packr/v2/Makefile generated vendored Normal file
View File

@ -0,0 +1,47 @@
TAGS ?= "sqlite"
GO_BIN ?= go
install: deps
echo "installing packr v2"
packr2
$(GO_BIN) install -v ./packr2
tidy:
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
else
echo skipping go mod tidy
endif
deps:
$(GO_BIN) get github.com/gobuffalo/release
$(GO_BIN) get -tags ${TAGS} -t ./...
$(GO_BIN) install -v ./packr2
make tidy
build: deps
packr2
$(GO_BIN) build -v ./packr2
make tidy
test:
packr2
$(GO_BIN) test -tags ${TAGS} ./...
make tidy
lint:
gometalinter --vendor ./... --deadline=1m --skip=internal
update:
$(GO_BIN) get -u -tags ${TAGS} ./...
make tidy
make install
make test
make tidy
release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
release:
release -y -f version.go
make tidy

235
vendor/github.com/gobuffalo/packr/v2/README.md generated vendored Normal file
View File

@ -0,0 +1,235 @@
# Packr (v2)
[![GoDoc](https://godoc.org/github.com/gobuffalo/packr/v2?status.svg)](https://godoc.org/github.com/gobuffalo/packr/v2)
Packr is a simple solution for bundling static assets inside of Go binaries. Most importantly it does it in a way that is friendly to developers while they are developing.
## Intro Video
To get an idea of the what and why of Packr, please enjoy this short video: [https://vimeo.com/219863271](https://vimeo.com/219863271).
## Library Installation
```text
$ go get -u github.com/gobuffalo/packr/v2/...
```
## Binary Installation
```text
$ go get -u github.com/gobuffalo/packr/v2/packr2
```
## New File Format FAQs
In version `v2.0.0` the file format changed and is not backward compatible with the `packr-v1.x` library.
#### Can `packr-v1.x` read the new format?
No, it can not. Because of the way the new file format works porting it to `packr-v1.x` would be difficult. PRs are welcome though. :)
#### Can `packr-v2.x` read `packr-v1.x` files?
Yes it can, but that ability will eventually be phased out. Because of that we recommend moving to the new format.
#### Can `packr-v2.x` generate `packr-v1.x` files?
Yes it can, but that ability will eventually be phased out. Because of that we recommend moving to the new format.
The `--legacy` command is available on all commands that generate `-packr.go` files.
```bash
$ packr2 --legacy
```
## Usage
### In Code
The first step in using Packr is to create a new box. A box represents a folder on disk. Once you have a box you can get `string` or `[]byte` representations of the file.
```go
// set up a new box by giving it a name and an optional (relative) path to a folder on disk:
box := packr.New("My Box", "./templates")
// Get the string representation of a file, or an error if it doesn't exist:
html, err := box.FindString("index.html")
// Get the []byte representation of a file, or an error if it doesn't exist:
html, err := box.Find("index.html")
```
### What is a Box?
A box represents a folder, and any sub-folders, on disk that you want to have access to in your binary. When compiling a binary using the `packr2` CLI the contents of the folder will be converted into Go files that can be compiled inside of a "standard" go binary. Inside of the compiled binary the files will be read from memory. When working locally the files will be read directly off of disk. This is a seamless switch that doesn't require any special attention on your part.
#### Example
Assume the follow directory structure:
```
├── main.go
└── templates
├── admin
│   └── index.html
└── index.html
```
The following program will read the `./templates/admin/index.html` file and print it out.
```go
package main
import (
"fmt"
"github.com/gobuffalo/packr/v2"
)
func main() {
box := packr.New("myBox", "./templates")
s, err := box.FindString("admin/index.html")
if err != nil {
log.Fatal(err)
}
fmt.Println(s)
}
```
### Development Made Easy
In order to get static files into a Go binary, those files must first be converted to Go code. To do that, Packr, ships with a few tools to help build binaries. See below.
During development, however, it is painful to have to keep running a tool to compile those files.
Packr uses the following resolution rules when looking for a file:
1. Look for the file in-memory (inside a Go binary)
1. Look for the file on disk (during development)
Because Packr knows how to fall through to the file system, developers don't need to worry about constantly compiling their static files into a binary. They can work unimpeded.
Packr takes file resolution a step further. When declaring a new box you use a relative path, `./templates`. When Packr receives this call it calculates out the absolute path to that directory. By doing this it means you can be guaranteed that Packr can find your files correctly, even if you're not running in the directory that the box was created in. This helps with the problem of testing, where Go changes the `pwd` for each package, making relative paths difficult to work with. This is not a problem when using Packr.
---
## Usage with HTTP
A box implements the [`http.FileSystem`](https://golang.org/pkg/net/http/#FileSystem) interface, meaning it can be used to serve static files.
```go
package main
import (
"net/http"
"github.com/gobuffalo/packr/v2"
)
func main() {
box := packr.New("someBoxName", "./templates")
http.Handle("/", http.FileServer(box))
http.ListenAndServe(":3000", nil)
}
```
---
## Building a Binary
Before you build your Go binary, run the `packr2` command first. It will look for all the boxes in your code and then generate `.go` files that pack the static files into bytes that can be bundled into the Go binary.
```
$ packr2
```
Then run your `go build command` like normal.
*NOTE*: It is not recommended to check-in these generated `-packr.go` files. They can be large, and can easily become out of date if not careful. It is recommended that you always run `packr2 clean` after running the `packr2` tool.
#### Cleaning Up
When you're done it is recommended that you run the `packr2 clean` command. This will remove all of the generated files that Packr created for you.
```
$ packr2 clean
```
Why do you want to do this? Packr first looks to the information stored in these generated files, if the information isn't there it looks to disk. This makes it easy to work with in development.
---
## Debugging
The `packr2` command passes all arguments down to the underlying `go` command, this includes the `-v` flag to print out `go build` information. Packr looks for the `-v` flag, and will turn on its own verbose logging. This is very useful for trying to understand what the `packr` command is doing when it is run.
---
## FAQ
### Compilation Errors with Go Templates
Q: I have a program with Go template files, those files are named `foo.go` and look like the following:
```
// Copyright {{.Year}} {{.Author}}. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package {{.Project}}
```
When I run `packr2` I get errors like:
```
expected 'IDENT', found '{'
```
A: Packr works by searching your `.go` files for [`github.com/gobuffalo/packr/v2#New`](https://godoc.org/github.com/gobuffalo/packr/v2#New) or [`github.com/gobuffalo/packr/v2#NewBox`](https://godoc.org/github.com/gobuffalo/packr/v2#NewBox) calls. Because those files aren't "proper" Go files, Packr can't parse them to find the box declarations. To fix this you need to tell Packr to ignore those files when searching for boxes. A couple solutions to this problem are:
* Name the files something else. The `.tmpl` extension is the idiomatic way of naming these types of files.
* Rename the folder containing these files to start with an `_`, for example `_templates`. Packr, like Go, will ignore folders starting with the `_` character when searching for boxes.
### Dynamic Box Paths
Q: I need to set the path of a box using a variable, but `packr.New("foo", myVar)` doesn't work correctly.
A: Packr attempts to "automagically" set it's resolution directory when using [`github.com/gobuffalo/packr/v2#New`](https://godoc.org/github.com/gobuffalo/packr/v2#New), however, for dynamic paths you need to set it manually:
```go
box := packr.New("foo", "|")
box.ResolutionDir = myVar
```
### I don't want to pack files, but still use the Packr interface.
Q: I want to write code that using the Packr tools, but doesn't actually pack the files into my binary. How can I do that?
A: Using [`github.com/gobuffalo/packr/v2#Folder`](https://godoc.org/github.com/gobuffalo/packr/v2#Folder) gives you back a `*packr.Box` that can be used as normal, but is excluded by the Packr tool when compiling.
### Packr Finds No Boxes
Q: I run `packr2 -v` but it doesn't find my boxes:
```
DEBU[2019-03-18T18:48:52+01:00] *parser.Parser#NewFromRoots found prospects=0
DEBU[2019-03-18T18:48:52+01:00] found 0 boxes
```
A: Packr works by parsing `.go` files to find [`github.com/gobuffalo/packr/v2#Box`](https://godoc.org/github.com/gobuffalo/packr/v2#Box) and [`github.com/gobuffalo/packr/v2#NewBox`](https://godoc.org/github.com/gobuffalo/packr/v2#NewBox) declarations. If there aren't any `.go` in the folder that `packr2` is run in it can not find those declarations. To fix this problem run the `packr2` command in the directory containing your `.go` files.
### Box Interfaces
Q: I want to be able to easily test my applications by passing in mock boxes. How do I do that?
A: Packr boxes and files conform to the interfaces found at [`github.com/gobuffalo/packd`](https://godoc.org/github.com/gobuffalo/packd). Change your application to use those interfaces instead of the concrete Packr types.
```go
// using concrete type
func myFunc(box *packr.Box) {}
// using interfaces
func myFunc(box packd.Box) {}
```

98
vendor/github.com/gobuffalo/packr/v2/SHOULDERS.md generated vendored Normal file
View File

@ -0,0 +1,98 @@
# github.com/gobuffalo/packr/v2 Stands on the Shoulders of Giants
github.com/gobuffalo/packr/v2 does not try to reinvent the wheel! Instead, it uses the already great wheels developed by the Go community and puts them all together in the best way possible. Without these giants, this project would not be possible. Please make sure to check them out and thank them for all of their hard work.
Thank you to the following **GIANTS**:
* [github.com/BurntSushi/toml](https://godoc.org/github.com/BurntSushi/toml)
* [github.com/armon/consul-api](https://godoc.org/github.com/armon/consul-api)
* [github.com/coreos/etcd](https://godoc.org/github.com/coreos/etcd)
* [github.com/coreos/go-etcd](https://godoc.org/github.com/coreos/go-etcd)
* [github.com/coreos/go-semver](https://godoc.org/github.com/coreos/go-semver)
* [github.com/cpuguy83/go-md2man](https://godoc.org/github.com/cpuguy83/go-md2man)
* [github.com/davecgh/go-spew](https://godoc.org/github.com/davecgh/go-spew)
* [github.com/fsnotify/fsnotify](https://godoc.org/github.com/fsnotify/fsnotify)
* [github.com/gobuffalo/envy](https://godoc.org/github.com/gobuffalo/envy)
* [github.com/gobuffalo/logger](https://godoc.org/github.com/gobuffalo/logger)
* [github.com/gobuffalo/packd](https://godoc.org/github.com/gobuffalo/packd)
* [github.com/hashicorp/hcl](https://godoc.org/github.com/hashicorp/hcl)
* [github.com/inconshreveable/mousetrap](https://godoc.org/github.com/inconshreveable/mousetrap)
* [github.com/joho/godotenv](https://godoc.org/github.com/joho/godotenv)
* [github.com/konsorten/go-windows-terminal-sequences](https://godoc.org/github.com/konsorten/go-windows-terminal-sequences)
* [github.com/kr/pretty](https://godoc.org/github.com/kr/pretty)
* [github.com/kr/pty](https://godoc.org/github.com/kr/pty)
* [github.com/kr/text](https://godoc.org/github.com/kr/text)
* [github.com/magiconair/properties](https://godoc.org/github.com/magiconair/properties)
* [github.com/mitchellh/go-homedir](https://godoc.org/github.com/mitchellh/go-homedir)
* [github.com/mitchellh/mapstructure](https://godoc.org/github.com/mitchellh/mapstructure)
* [github.com/pelletier/go-toml](https://godoc.org/github.com/pelletier/go-toml)
* [github.com/pmezard/go-difflib](https://godoc.org/github.com/pmezard/go-difflib)
* [github.com/rogpeppe/go-internal](https://godoc.org/github.com/rogpeppe/go-internal)
* [github.com/russross/blackfriday](https://godoc.org/github.com/russross/blackfriday)
* [github.com/sirupsen/logrus](https://godoc.org/github.com/sirupsen/logrus)
* [github.com/spf13/afero](https://godoc.org/github.com/spf13/afero)
* [github.com/spf13/cast](https://godoc.org/github.com/spf13/cast)
* [github.com/spf13/cobra](https://godoc.org/github.com/spf13/cobra)
* [github.com/spf13/jwalterweatherman](https://godoc.org/github.com/spf13/jwalterweatherman)
* [github.com/spf13/pflag](https://godoc.org/github.com/spf13/pflag)
* [github.com/spf13/viper](https://godoc.org/github.com/spf13/viper)
* [github.com/stretchr/objx](https://godoc.org/github.com/stretchr/objx)
* [github.com/stretchr/testify](https://godoc.org/github.com/stretchr/testify)
* [github.com/ugorji/go/codec](https://godoc.org/github.com/ugorji/go/codec)
* [github.com/xordataexchange/crypt](https://godoc.org/github.com/xordataexchange/crypt)
* [golang.org/x/crypto](https://godoc.org/golang.org/x/crypto)
* [golang.org/x/net](https://godoc.org/golang.org/x/net)
* [golang.org/x/sync](https://godoc.org/golang.org/x/sync)
* [golang.org/x/sys](https://godoc.org/golang.org/x/sys)
* [golang.org/x/text](https://godoc.org/golang.org/x/text)
* [golang.org/x/tools](https://godoc.org/golang.org/x/tools)
* [golang.org/x/xerrors](https://godoc.org/golang.org/x/xerrors)
* [gopkg.in/check.v1](https://godoc.org/gopkg.in/check.v1)
* [gopkg.in/errgo.v2](https://godoc.org/gopkg.in/errgo.v2)
* [gopkg.in/yaml.v2](https://godoc.org/gopkg.in/yaml.v2)

240
vendor/github.com/gobuffalo/packr/v2/box.go generated vendored Normal file
View File

@ -0,0 +1,240 @@
package packr
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"sort"
"strings"
"github.com/gobuffalo/packd"
"github.com/gobuffalo/packr/v2/file"
"github.com/gobuffalo/packr/v2/file/resolver"
"github.com/gobuffalo/packr/v2/internal/takeon/github.com/markbates/oncer"
"github.com/gobuffalo/packr/v2/plog"
)
var _ packd.Box = &Box{}
var _ packd.HTTPBox = &Box{}
var _ packd.Addable = &Box{}
var _ packd.Walkable = &Box{}
var _ packd.Finder = &Box{}
// Box represent a folder on a disk you want to
// have access to in the built Go binary.
type Box struct {
Path string `json:"path"`
Name string `json:"name"`
ResolutionDir string `json:"resolution_dir"`
DefaultResolver resolver.Resolver `json:"default_resolver"`
resolvers resolversMap
dirs dirsMap
}
// NewBox returns a Box that can be used to
// retrieve files from either disk or the embedded
// binary.
// Deprecated: Use New instead.
func NewBox(path string) *Box {
oncer.Deprecate(0, "packr.NewBox", "Use packr.New instead.")
return New(path, path)
}
// New returns a new Box with the name of the box
// and the path of the box.
func New(name string, path string) *Box {
plog.Debug("packr", "New", "name", name, "path", path)
b, _ := findBox(name)
if b != nil {
return b
}
b = construct(name, path)
plog.Debug(b, "New", "Box", b, "ResolutionDir", b.ResolutionDir)
b, err := placeBox(b)
if err != nil {
panic(err)
}
return b
}
// Folder returns a Box that will NOT be packed.
// This is useful for writing tests or tools that
// need to work with a folder at runtime.
func Folder(path string) *Box {
return New(path, path)
}
// SetResolver allows for the use of a custom resolver for
// the specified file
func (b *Box) SetResolver(file string, res resolver.Resolver) {
d := filepath.Dir(file)
b.dirs.Store(d, true)
plog.Debug(b, "SetResolver", "file", file, "resolver", fmt.Sprintf("%T", res))
b.resolvers.Store(resolver.Key(file), res)
}
// AddString converts t to a byteslice and delegates to AddBytes to add to b.data
func (b *Box) AddString(path string, t string) error {
return b.AddBytes(path, []byte(t))
}
// AddBytes sets t in b.data by the given path
func (b *Box) AddBytes(path string, t []byte) error {
m := map[string]file.File{}
f, err := file.NewFile(path, t)
if err != nil {
return err
}
m[resolver.Key(path)] = f
res := resolver.NewInMemory(m)
b.SetResolver(path, res)
return nil
}
// FindString returns either the string of the requested
// file or an error if it can not be found.
func (b *Box) FindString(name string) (string, error) {
bb, err := b.Find(name)
return string(bb), err
}
// Find returns either the byte slice of the requested
// file or an error if it can not be found.
func (b *Box) Find(name string) ([]byte, error) {
f, err := b.Resolve(name)
if err != nil {
return []byte(""), err
}
bb := &bytes.Buffer{}
io.Copy(bb, f)
return bb.Bytes(), nil
}
// Has returns true if the resource exists in the box
func (b *Box) Has(name string) bool {
_, err := b.Find(name)
return err == nil
}
// HasDir returns true if the directory exists in the box
func (b *Box) HasDir(name string) bool {
oncer.Do("packr2/box/HasDir"+b.Name, func() {
for _, f := range b.List() {
for d := filepath.Dir(f); d != "."; d = filepath.Dir(d) {
b.dirs.Store(d, true)
}
}
})
if name == "/" {
return b.Has("index.html")
}
_, ok := b.dirs.Load(name)
return ok
}
// Open returns a File using the http.File interface
func (b *Box) Open(name string) (http.File, error) {
plog.Debug(b, "Open", "name", name)
f, err := b.Resolve(name)
if err != nil {
if len(filepath.Ext(name)) == 0 {
return b.openWoExt(name)
}
return f, err
}
f, err = file.NewFileR(name, f)
plog.Debug(b, "Open", "name", f.Name(), "file", f.Name())
return f, err
}
func (b *Box) openWoExt(name string) (http.File, error) {
if !b.HasDir(name) {
id := path.Join(name, "index.html")
if b.Has(id) {
return b.Open(id)
}
return nil, os.ErrNotExist
}
d, err := file.NewDir(name)
plog.Debug(b, "Open", "name", name, "dir", d)
return d, err
}
// List shows "What's in the box?"
func (b *Box) List() []string {
var keys []string
b.Walk(func(path string, info File) error {
if info == nil {
return nil
}
finfo, _ := info.FileInfo()
if !finfo.IsDir() {
keys = append(keys, path)
}
return nil
})
sort.Strings(keys)
return keys
}
// Resolve will attempt to find the file in the box,
// returning an error if the find can not be found.
func (b *Box) Resolve(key string) (file.File, error) {
key = strings.TrimPrefix(key, "/")
var r resolver.Resolver
b.resolvers.Range(func(k string, vr resolver.Resolver) bool {
lk := strings.ToLower(resolver.Key(k))
lkey := strings.ToLower(resolver.Key(key))
if lk == lkey {
r = vr
return false
}
return true
})
if r == nil {
r = b.DefaultResolver
if r == nil {
r = resolver.DefaultResolver
if r == nil {
return nil, fmt.Errorf("resolver.DefaultResolver is nil")
}
}
}
plog.Debug(r, "Resolve", "box", b.Name, "key", key)
f, err := r.Resolve(b.Name, key)
if err != nil {
z, err := resolver.ResolvePathInBase(resolver.OsPath(b.ResolutionDir), filepath.FromSlash(path.Clean("/"+resolver.OsPath(key))))
if err != nil {
plog.Debug(r, "Resolve", "box", b.Name, "key", key, "err", err)
return f, err
}
f, err = r.Resolve(b.Name, z)
if err != nil {
plog.Debug(r, "Resolve", "box", b.Name, "key", z, "err", err)
return f, err
}
b, err := ioutil.ReadAll(f)
if err != nil {
return f, err
}
f, err = file.NewFile(key, b)
if err != nil {
return f, err
}
}
plog.Debug(r, "Resolve", "box", b.Name, "key", key, "file", f.Name())
return f, nil
}

73
vendor/github.com/gobuffalo/packr/v2/box_map.go generated vendored Normal file
View File

@ -0,0 +1,73 @@
//go:generate mapgen -name "box" -zero "nil" -go-type "*Box" -pkg "" -a "New(`test-a`, ``)" -b "New(`test-b`, ``)" -c "New(`test-c`, ``)" -bb "New(`test-bb`, ``)" -destination "packr"
// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT.
package packr
import (
"sort"
"sync"
)
// boxMap wraps sync.Map and uses the following types:
// key: string
// value: *Box
type boxMap struct {
data sync.Map
}
// Delete the key from the map
func (m *boxMap) Delete(key string) {
m.data.Delete(key)
}
// Load the key from the map.
// Returns *Box or bool.
// A false return indicates either the key was not found
// or the value is not of type *Box
func (m *boxMap) Load(key string) (*Box, bool) {
i, ok := m.data.Load(key)
if !ok {
return nil, false
}
s, ok := i.(*Box)
return s, ok
}
// LoadOrStore will return an existing key or
// store the value if not already in the map
func (m *boxMap) LoadOrStore(key string, value *Box) (*Box, bool) {
i, _ := m.data.LoadOrStore(key, value)
s, ok := i.(*Box)
return s, ok
}
// Range over the *Box values in the map
func (m *boxMap) Range(f func(key string, value *Box) bool) {
m.data.Range(func(k, v interface{}) bool {
key, ok := k.(string)
if !ok {
return false
}
value, ok := v.(*Box)
if !ok {
return false
}
return f(key, value)
})
}
// Store a *Box in the map
func (m *boxMap) Store(key string, value *Box) {
m.data.Store(key, value)
}
// Keys returns a list of keys in the map
func (m *boxMap) Keys() []string {
var keys []string
m.Range(func(key string, value *Box) bool {
keys = append(keys, key)
return true
})
sort.Strings(keys)
return keys
}

79
vendor/github.com/gobuffalo/packr/v2/deprecated.go generated vendored Normal file
View File

@ -0,0 +1,79 @@
package packr
import (
"encoding/json"
"fmt"
"github.com/gobuffalo/packr/v2/file"
"github.com/gobuffalo/packr/v2/file/resolver"
"github.com/gobuffalo/packr/v2/internal/takeon/github.com/markbates/oncer"
)
// File has been deprecated and file.File should be used instead
type File = file.File
var (
// ErrResOutsideBox gets returned in case of the requested resources being outside the box
// Deprecated
ErrResOutsideBox = fmt.Errorf("can't find a resource outside the box")
)
// PackBytes packs bytes for a file into a box.
// Deprecated
func PackBytes(box string, name string, bb []byte) {
b := NewBox(box)
d := resolver.NewInMemory(map[string]file.File{})
f, err := file.NewFile(name, bb)
if err != nil {
panic(err)
}
if err := d.Pack(name, f); err != nil {
panic(err)
}
b.SetResolver(name, d)
}
// PackBytesGzip packets the gzipped compressed bytes into a box.
// Deprecated
func PackBytesGzip(box string, name string, bb []byte) error {
// TODO: this function never did what it was supposed to do!
PackBytes(box, name, bb)
return nil
}
// PackJSONBytes packs JSON encoded bytes for a file into a box.
// Deprecated
func PackJSONBytes(box string, name string, jbb string) error {
var bb []byte
err := json.Unmarshal([]byte(jbb), &bb)
if err != nil {
return err
}
PackBytes(box, name, bb)
return nil
}
// Bytes is deprecated. Use Find instead
func (b *Box) Bytes(name string) []byte {
bb, _ := b.Find(name)
oncer.Deprecate(0, "github.com/gobuffalo/packr/v2#Box.Bytes", "Use github.com/gobuffalo/packr/v2#Box.Find instead.")
return bb
}
// MustBytes is deprecated. Use Find instead.
func (b *Box) MustBytes(name string) ([]byte, error) {
oncer.Deprecate(0, "github.com/gobuffalo/packr/v2#Box.MustBytes", "Use github.com/gobuffalo/packr/v2#Box.Find instead.")
return b.Find(name)
}
// String is deprecated. Use FindString instead
func (b *Box) String(name string) string {
oncer.Deprecate(0, "github.com/gobuffalo/packr/v2#Box.String", "Use github.com/gobuffalo/packr/v2#Box.FindString instead.")
return string(b.Bytes(name))
}
// MustString is deprecated. Use FindString instead
func (b *Box) MustString(name string) (string, error) {
oncer.Deprecate(0, "github.com/gobuffalo/packr/v2#Box.MustString", "Use github.com/gobuffalo/packr/v2#Box.FindString instead.")
return b.FindString(name)
}

82
vendor/github.com/gobuffalo/packr/v2/dirs_map.go generated vendored Normal file
View File

@ -0,0 +1,82 @@
//go:generate mapgen -name "dirs" -zero "false" -go-type "bool" -pkg "" -a "nil" -b "nil" -c "nil" -bb "nil" -destination "packr"
// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT.
package packr
import (
"sort"
"strings"
"sync"
)
// dirsMap wraps sync.Map and uses the following types:
// key: string
// value: bool
type dirsMap struct {
data sync.Map
}
// Delete the key from the map
func (m *dirsMap) Delete(key string) {
m.data.Delete(m.normalizeKey(key))
}
// Load the key from the map.
// Returns bool or bool.
// A false return indicates either the key was not found
// or the value is not of type bool
func (m *dirsMap) Load(key string) (bool, bool) {
i, ok := m.data.Load(m.normalizeKey(key))
if !ok {
return false, false
}
s, ok := i.(bool)
return s, ok
}
// LoadOrStore will return an existing key or
// store the value if not already in the map
func (m *dirsMap) LoadOrStore(key string, value bool) (bool, bool) {
i, _ := m.data.LoadOrStore(m.normalizeKey(key), value)
s, ok := i.(bool)
return s, ok
}
// Range over the bool values in the map
func (m *dirsMap) Range(f func(key string, value bool) bool) {
m.data.Range(func(k, v interface{}) bool {
key, ok := k.(string)
if !ok {
return false
}
value, ok := v.(bool)
if !ok {
return false
}
return f(key, value)
})
}
// Store a bool in the map
func (m *dirsMap) Store(key string, value bool) {
d := m.normalizeKey(key)
m.data.Store(d, value)
m.data.Store(strings.TrimPrefix(d, "/"), value)
}
// Keys returns a list of keys in the map
func (m *dirsMap) Keys() []string {
var keys []string
m.Range(func(key string, value bool) bool {
keys = append(keys, key)
return true
})
sort.Strings(keys)
return keys
}
func (m *dirsMap) normalizeKey(key string) string {
key = strings.Replace(key, "\\", "/", -1)
return key
}

32
vendor/github.com/gobuffalo/packr/v2/file/file.go generated vendored Normal file
View File

@ -0,0 +1,32 @@
package file
import (
"bytes"
"io"
"github.com/gobuffalo/packd"
)
// File represents a virtual, or physical, backing of
// a file object in a Box
type File = packd.File
// FileMappable types are capable of returning a map of
// path => File
type FileMappable interface {
FileMap() map[string]File
}
// NewFile returns a virtual File implementation
func NewFile(name string, b []byte) (File, error) {
return packd.NewFile(name, bytes.NewReader(b))
}
// NewDir returns a virtual dir implementation
func NewDir(name string) (File, error) {
return packd.NewDir(name)
}
func NewFileR(name string, r io.Reader) (File, error) {
return packd.NewFile(name, r)
}

38
vendor/github.com/gobuffalo/packr/v2/file/info.go generated vendored Normal file
View File

@ -0,0 +1,38 @@
package file
import (
"os"
"time"
)
type info struct {
Path string
Contents []byte
size int64
modTime time.Time
isDir bool
}
func (f info) Name() string {
return f.Path
}
func (f info) Size() int64 {
return f.size
}
func (f info) Mode() os.FileMode {
return 0444
}
func (f info) ModTime() time.Time {
return f.modTime
}
func (f info) IsDir() bool {
return f.isDir
}
func (f info) Sys() interface{} {
return nil
}

View File

@ -0,0 +1,111 @@
package resolver
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"github.com/gobuffalo/packr/v2/file"
"github.com/gobuffalo/packr/v2/internal/takeon/github.com/karrick/godirwalk"
"github.com/gobuffalo/packr/v2/plog"
)
var _ Resolver = &Disk{}
type Disk struct {
Root string
}
func (d Disk) String() string {
return String(&d)
}
func (d *Disk) Resolve(box string, name string) (file.File, error) {
var err error
path := OsPath(name)
if !filepath.IsAbs(path) {
path, err = ResolvePathInBase(OsPath(d.Root), path)
if err != nil {
return nil, err
}
}
fi, err := os.Stat(path)
if err != nil {
return nil, err
}
if fi.IsDir() {
return nil, os.ErrNotExist
}
if bb, err := ioutil.ReadFile(path); err == nil {
return file.NewFile(OsPath(name), bb)
}
return nil, os.ErrNotExist
}
// ResolvePathInBase returns a path that is guaranteed to be inside of the base directory or an error
func ResolvePathInBase(base, path string) (string, error) {
// Determine the absolute file path of the base directory
d, err := filepath.Abs(base)
if err != nil {
return "", err
}
// Return the base directory if no file was requested
if path == "/" || path == "\\" {
return d, nil
}
// Resolve the absolute file path after combining the key with base
p, err := filepath.Abs(filepath.Join(d, path))
if err != nil {
return "", err
}
// Verify that the resolved path is inside of the base directory
if !strings.HasPrefix(p, d+string(filepath.Separator)) {
return "", os.ErrNotExist
}
return p, nil
}
var _ file.FileMappable = &Disk{}
func (d *Disk) FileMap() map[string]file.File {
moot := &sync.Mutex{}
m := map[string]file.File{}
root := OsPath(d.Root)
if _, err := os.Stat(root); err != nil {
return m
}
callback := func(path string, de *godirwalk.Dirent) error {
if _, err := os.Stat(root); err != nil {
return nil
}
if !de.IsRegular() {
return nil
}
moot.Lock()
name := strings.TrimPrefix(path, root+string(filepath.Separator))
b, err := ioutil.ReadFile(path)
if err != nil {
return err
}
m[name], err = file.NewFile(name, b)
if err != nil {
return err
}
moot.Unlock()
return nil
}
err := godirwalk.Walk(root, &godirwalk.Options{
FollowSymbolicLinks: true,
Callback: callback,
})
if err != nil {
plog.Logger.Errorf("[%s] error walking %v", root, err)
}
return m
}

View File

@ -0,0 +1,314 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package hex implements hexadecimal encoding and decoding.
package hex
import (
"bytes"
"fmt"
"io"
)
const hextable = "0123456789abcdef"
// EncodedLen returns the length of an encoding of n source bytes.
// Specifically, it returns n * 2.
func EncodedLen(n int) int { return n * 2 }
// Encode encodes src into EncodedLen(len(src))
// bytes of dst. As a convenience, it returns the number
// of bytes written to dst, but this value is always EncodedLen(len(src)).
// Encode implements hexadecimal encoding.
func Encode(dst, src []byte) int {
for i, v := range src {
dst[i*2] = hextable[v>>4]
dst[i*2+1] = hextable[v&0x0f]
}
return len(src) * 2
}
// ErrLength reports an attempt to decode an odd-length input
// using Decode or DecodeString.
// The stream-based Decoder returns io.ErrUnexpectedEOF instead of ErrLength.
var ErrLength = fmt.Errorf("encoding/hex: odd length hex string")
// InvalidByteError values describe errors resulting from an invalid byte in a hex string.
type InvalidByteError byte
func (e InvalidByteError) Error() string {
return fmt.Sprintf("encoding/hex: invalid byte: %#U", rune(e))
}
// DecodedLen returns the length of a decoding of x source bytes.
// Specifically, it returns x / 2.
func DecodedLen(x int) int { return x / 2 }
// Decode decodes src into DecodedLen(len(src)) bytes,
// returning the actual number of bytes written to dst.
//
// Decode expects that src contains only hexadecimal
// characters and that src has even length.
// If the input is malformed, Decode returns the number
// of bytes decoded before the error.
func Decode(dst, src []byte) (int, error) {
var i int
for i = 0; i < len(src)/2; i++ {
a, ok := fromHexChar(src[i*2])
if !ok {
return i, InvalidByteError(src[i*2])
}
b, ok := fromHexChar(src[i*2+1])
if !ok {
return i, InvalidByteError(src[i*2+1])
}
dst[i] = (a << 4) | b
}
if len(src)%2 == 1 {
// Check for invalid char before reporting bad length,
// since the invalid char (if present) is an earlier problem.
if _, ok := fromHexChar(src[i*2]); !ok {
return i, InvalidByteError(src[i*2])
}
return i, ErrLength
}
return i, nil
}
// fromHexChar converts a hex character into its value and a success flag.
func fromHexChar(c byte) (byte, bool) {
switch {
case '0' <= c && c <= '9':
return c - '0', true
case 'a' <= c && c <= 'f':
return c - 'a' + 10, true
case 'A' <= c && c <= 'F':
return c - 'A' + 10, true
}
return 0, false
}
// EncodeToString returns the hexadecimal encoding of src.
func EncodeToString(src []byte) string {
dst := make([]byte, EncodedLen(len(src)))
Encode(dst, src)
return string(dst)
}
// DecodeString returns the bytes represented by the hexadecimal string s.
//
// DecodeString expects that src contains only hexadecimal
// characters and that src has even length.
// If the input is malformed, DecodeString returns
// the bytes decoded before the error.
func DecodeString(s string) ([]byte, error) {
src := []byte(s)
// We can use the source slice itself as the destination
// because the decode loop increments by one and then the 'seen' byte is not used anymore.
n, err := Decode(src, src)
return src[:n], err
}
// Dump returns a string that contains a hex dump of the given data. The format
// of the hex dump matches the output of `hexdump -C` on the command line.
func Dump(data []byte) string {
var buf bytes.Buffer
dumper := Dumper(&buf)
dumper.Write(data)
dumper.Close()
return buf.String()
}
// bufferSize is the number of hexadecimal characters to buffer in encoder and decoder.
const bufferSize = 1024
type encoder struct {
w io.Writer
err error
out [bufferSize]byte // output buffer
}
// NewEncoder returns an io.Writer that writes lowercase hexadecimal characters to w.
func NewEncoder(w io.Writer) io.Writer {
return &encoder{w: w}
}
func (e *encoder) Write(p []byte) (n int, err error) {
for len(p) > 0 && e.err == nil {
chunkSize := bufferSize / 2
if len(p) < chunkSize {
chunkSize = len(p)
}
var written int
encoded := Encode(e.out[:], p[:chunkSize])
written, e.err = e.w.Write(e.out[:encoded])
n += written / 2
p = p[chunkSize:]
}
return n, e.err
}
type decoder struct {
r io.Reader
err error
in []byte // input buffer (encoded form)
arr [bufferSize]byte // backing array for in
}
// NewDecoder returns an io.Reader that decodes hexadecimal characters from r.
// NewDecoder expects that r contain only an even number of hexadecimal characters.
func NewDecoder(r io.Reader) io.Reader {
return &decoder{r: r}
}
func (d *decoder) Read(p []byte) (n int, err error) {
// Fill internal buffer with sufficient bytes to decode
if len(d.in) < 2 && d.err == nil {
var numCopy, numRead int
numCopy = copy(d.arr[:], d.in) // Copies either 0 or 1 bytes
numRead, d.err = d.r.Read(d.arr[numCopy:])
d.in = d.arr[:numCopy+numRead]
if d.err == io.EOF && len(d.in)%2 != 0 {
if _, ok := fromHexChar(d.in[len(d.in)-1]); !ok {
d.err = InvalidByteError(d.in[len(d.in)-1])
} else {
d.err = io.ErrUnexpectedEOF
}
}
}
// Decode internal buffer into output buffer
if numAvail := len(d.in) / 2; len(p) > numAvail {
p = p[:numAvail]
}
numDec, err := Decode(p, d.in[:len(p)*2])
d.in = d.in[2*numDec:]
if err != nil {
d.in, d.err = nil, err // Decode error; discard input remainder
}
if len(d.in) < 2 {
return numDec, d.err // Only expose errors when buffer fully consumed
}
return numDec, nil
}
// Dumper returns a WriteCloser that writes a hex dump of all written data to
// w. The format of the dump matches the output of `hexdump -C` on the command
// line.
func Dumper(w io.Writer) io.WriteCloser {
return &dumper{w: w}
}
type dumper struct {
w io.Writer
rightChars [18]byte
buf [14]byte
used int // number of bytes in the current line
n uint // number of bytes, total
closed bool
}
func toChar(b byte) byte {
if b < 32 || b > 126 {
return '.'
}
return b
}
func (h *dumper) Write(data []byte) (n int, err error) {
if h.closed {
return 0, fmt.Errorf("encoding/hex: dumper closed")
}
// Output lines look like:
// 00000010 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d |./0123456789:;<=|
// ^ offset ^ extra space ^ ASCII of line.
for i := range data {
if h.used == 0 {
// At the beginning of a line we print the current
// offset in hex.
h.buf[0] = byte(h.n >> 24)
h.buf[1] = byte(h.n >> 16)
h.buf[2] = byte(h.n >> 8)
h.buf[3] = byte(h.n)
Encode(h.buf[4:], h.buf[:4])
h.buf[12] = ' '
h.buf[13] = ' '
_, err = h.w.Write(h.buf[4:])
if err != nil {
return
}
}
Encode(h.buf[:], data[i:i+1])
h.buf[2] = ' '
l := 3
if h.used == 7 {
// There's an additional space after the 8th byte.
h.buf[3] = ' '
l = 4
} else if h.used == 15 {
// At the end of the line there's an extra space and
// the bar for the right column.
h.buf[3] = ' '
h.buf[4] = '|'
l = 5
}
_, err = h.w.Write(h.buf[:l])
if err != nil {
return
}
n++
h.rightChars[h.used] = toChar(data[i])
h.used++
h.n++
if h.used == 16 {
h.rightChars[16] = '|'
h.rightChars[17] = '\n'
_, err = h.w.Write(h.rightChars[:])
if err != nil {
return
}
h.used = 0
}
}
return
}
func (h *dumper) Close() (err error) {
// See the comments in Write() for the details of this format.
if h.closed {
return
}
h.closed = true
if h.used == 0 {
return
}
h.buf[0] = ' '
h.buf[1] = ' '
h.buf[2] = ' '
h.buf[3] = ' '
h.buf[4] = '|'
nBytes := h.used
for h.used < 16 {
l := 3
if h.used == 7 {
l = 4
} else if h.used == 15 {
l = 5
}
_, err = h.w.Write(h.buf[:l])
if err != nil {
return
}
h.used++
}
h.rightChars[nBytes] = '|'
h.rightChars[nBytes+1] = '\n'
_, err = h.w.Write(h.rightChars[:nBytes+2])
return
}

View File

@ -0,0 +1,112 @@
package resolver
import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"os"
"strings"
"sync"
"github.com/gobuffalo/packr/v2/file/resolver/encoding/hex"
"github.com/gobuffalo/packr/v2/plog"
"github.com/gobuffalo/packr/v2/file"
)
var _ Resolver = &HexGzip{}
type HexGzip struct {
packed map[string]string
unpacked map[string]string
moot *sync.RWMutex
}
func (hg HexGzip) String() string {
return String(&hg)
}
var _ file.FileMappable = &HexGzip{}
func (hg *HexGzip) FileMap() map[string]file.File {
hg.moot.RLock()
var names []string
for k := range hg.packed {
names = append(names, k)
}
hg.moot.RUnlock()
m := map[string]file.File{}
for _, n := range names {
if f, err := hg.Resolve("", n); err == nil {
m[n] = f
}
}
return m
}
func (hg *HexGzip) Resolve(box string, name string) (file.File, error) {
plog.Debug(hg, "Resolve", "box", box, "name", name)
hg.moot.Lock()
defer hg.moot.Unlock()
if s, ok := hg.unpacked[name]; ok {
return file.NewFile(name, []byte(s))
}
packed, ok := hg.packed[name]
if !ok {
return nil, os.ErrNotExist
}
unpacked, err := UnHexGzipString(packed)
if err != nil {
return nil, err
}
f, err := file.NewFile(OsPath(name), []byte(unpacked))
if err != nil {
return nil, err
}
hg.unpacked[name] = f.String()
return f, nil
}
func NewHexGzip(files map[string]string) (*HexGzip, error) {
if files == nil {
files = map[string]string{}
}
hg := &HexGzip{
packed: files,
unpacked: map[string]string{},
moot: &sync.RWMutex{},
}
return hg, nil
}
func HexGzipString(s string) (string, error) {
bb := &bytes.Buffer{}
enc := hex.NewEncoder(bb)
zw := gzip.NewWriter(enc)
io.Copy(zw, strings.NewReader(s))
zw.Close()
return bb.String(), nil
}
func UnHexGzipString(packed string) (string, error) {
br := bytes.NewBufferString(packed)
dec := hex.NewDecoder(br)
zr, err := gzip.NewReader(dec)
if err != nil {
return "", err
}
defer zr.Close()
b, err := ioutil.ReadAll(zr)
if err != nil {
return "", err
}
return string(b), nil
}

View File

@ -0,0 +1,21 @@
package resolver
import (
"path/filepath"
"runtime"
"strings"
)
func Key(s string) string {
s = strings.Replace(s, "\\", "/", -1)
return s
}
func OsPath(s string) string {
if runtime.GOOS == "windows" {
s = strings.Replace(s, "/", string(filepath.Separator), -1)
} else {
s = strings.Replace(s, "\\", string(filepath.Separator), -1)
}
return s
}

View File

@ -0,0 +1,63 @@
package resolver
import (
"io/ioutil"
"github.com/gobuffalo/packd"
"github.com/gobuffalo/packr/v2/file"
"github.com/gobuffalo/packr/v2/plog"
)
var _ Resolver = &InMemory{}
type InMemory struct {
*packd.MemoryBox
}
func (d InMemory) String() string {
return String(&d)
}
func (d *InMemory) Resolve(box string, name string) (file.File, error) {
b, err := d.MemoryBox.Find(name)
if err != nil {
return nil, err
}
return file.NewFile(name, b)
}
func (d *InMemory) Pack(name string, f file.File) error {
plog.Debug(d, "Pack", "name", name)
b, err := ioutil.ReadAll(f)
if err != nil {
return err
}
d.AddBytes(name, b)
return nil
}
func (d *InMemory) FileMap() map[string]file.File {
m := map[string]file.File{}
d.Walk(func(path string, file file.File) error {
m[path] = file
return nil
})
return m
}
func NewInMemory(files map[string]file.File) *InMemory {
if files == nil {
files = map[string]file.File{}
}
box := packd.NewMemoryBox()
for p, f := range files {
if b, err := ioutil.ReadAll(f); err == nil {
box.AddBytes(p, b)
}
}
return &InMemory{
MemoryBox: box,
}
}

View File

@ -0,0 +1,7 @@
package resolver
import "github.com/gobuffalo/packr/v2/file"
type Packable interface {
Pack(name string, f file.File) error
}

View File

@ -0,0 +1,33 @@
package resolver
import (
"encoding/json"
"fmt"
"os"
"github.com/gobuffalo/packr/v2/file"
)
type Resolver interface {
Resolve(string, string) (file.File, error)
}
func defaultResolver() Resolver {
pwd, _ := os.Getwd()
return &Disk{
Root: pwd,
}
}
var DefaultResolver = defaultResolver()
func String(r Resolver) string {
m := map[string]interface{}{
"name": fmt.Sprintf("%T", r),
}
if fm, ok := r.(file.FileMappable); ok {
m["files"] = fm
}
b, _ := json.Marshal(m)
return string(b)
}

15
vendor/github.com/gobuffalo/packr/v2/go.mod generated vendored Normal file
View File

@ -0,0 +1,15 @@
module github.com/gobuffalo/packr/v2
go 1.13
require (
github.com/gobuffalo/envy v1.7.1
github.com/gobuffalo/logger v1.0.1
github.com/gobuffalo/packd v0.3.0
github.com/rogpeppe/go-internal v1.4.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3
)

View File

@ -8,26 +8,25 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gobuffalo/envy v1.7.0 h1:GlXgaiBkmrYMHco6t4j7SacKO4XUjvh5pwXh0f4uxXU=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/logger v1.0.0 h1:xw9Ko9EcC5iAFprrjJ6oZco9UpzS5MQ4jAwghsLHdy4=
github.com/gobuffalo/logger v1.0.0/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs=
github.com/gobuffalo/envy v1.7.1 h1:OQl5ys5MBea7OGCdvPbBJWRgnhC/fGona6QKfvFeau8=
github.com/gobuffalo/envy v1.7.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
github.com/gobuffalo/logger v1.0.1 h1:ZEgyRGgAm4ZAhAO45YXMs5Fp+bzGLESFewzAVBMKuTg=
github.com/gobuffalo/logger v1.0.1/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs=
github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4=
github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q=
github.com/gobuffalo/packr/v2 v2.5.1 h1:TFOeY2VoGamPjQLiNDT3mn//ytzk236VMO2j7iHxJR4=
github.com/gobuffalo/packr/v2 v2.5.1/go.mod h1:8f9c96ITobJlPzI44jj+4tHnEKNt0xXWSVlXRN9X1Iw=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/karrick/godirwalk v1.10.12 h1:BqUm+LuJcXjGv1d2mj3gBiQyrQ57a0rYoAmhvJQ7RDU=
github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
@ -36,8 +35,10 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.4.0 h1:LUa41nrWTQNGhzdsZ5lTnkwbNjj6rXTdazA1cSdjkOY=
github.com/rogpeppe/go-internal v1.4.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
@ -52,18 +53,21 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -71,9 +75,12 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 h1:khxRGsvPk4n2y8I/mLLjp7e5dMTJmH75wvqS6nMwUtY=
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c h1:KfpJVdWhuRqNk4XVXzjXf2KAV4TBEP77SYdFGjeGuIE=
golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3 h1:2AmBLzhAfXj+2HCW09VCkJtHIYgHTIPcTeYqgP7Bwt0=
golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

73
vendor/github.com/gobuffalo/packr/v2/helpers.go generated vendored Normal file
View File

@ -0,0 +1,73 @@
package packr
import (
"os"
"path/filepath"
"runtime"
"strings"
"github.com/gobuffalo/envy"
"github.com/gobuffalo/packr/v2/plog"
)
func construct(name string, path string) *Box {
return &Box{
Path: path,
Name: name,
ResolutionDir: resolutionDir(path),
resolvers: resolversMap{},
dirs: dirsMap{},
}
}
func resolutionDirTestFilename(filename, og string) (string, bool) {
ng := filepath.Join(filepath.Dir(filename), og)
// // this little hack courtesy of the `-cover` flag!!
cov := filepath.Join("_test", "_obj_test")
ng = strings.Replace(ng, string(filepath.Separator)+cov, "", 1)
if resolutionDirExists(ng, og) {
return ng, true
}
ng = filepath.Join(envy.GoPath(), "src", ng)
if resolutionDirExists(ng, og) {
return ng, true
}
return og, false
}
func resolutionDirExists(s, og string) bool {
_, err := os.Stat(s)
if err != nil {
return false
}
plog.Debug("packr", "resolutionDir", "original", og, "resolved", s)
return true
}
func resolutionDir(og string) string {
ng, _ := filepath.Abs(og)
if resolutionDirExists(ng, og) {
return ng
}
// packr.New
_, filename, _, _ := runtime.Caller(3)
ng, ok := resolutionDirTestFilename(filename, og)
if ok {
return ng
}
// packr.NewBox (deprecated)
_, filename, _, _ = runtime.Caller(4)
ng, ok = resolutionDirTestFilename(filename, og)
if ok {
return ng
}
return og
}

View File

@ -0,0 +1,25 @@
BSD 2-Clause License
Copyright (c) 2017, Karrick McDermott
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,215 @@
# godirwalk
`godirwalk` is a library for traversing a directory tree on a file
system.
[![GoDoc](https://godoc.org/github.com/karrick/godirwalk?status.svg)](https://godoc.org/github.com/karrick/godirwalk) [![Build Status](https://dev.azure.com/microsoft0235/microsoft/_apis/build/status/karrick.godirwalk?branchName=master)](https://dev.azure.com/microsoft0235/microsoft/_build/latest?definitionId=1&branchName=master)
In short, why do I use this library?
1. It's faster than `filepath.Walk`.
1. It's more correct on Windows than `filepath.Walk`.
1. It's more easy to use than `filepath.Walk`.
1. It's more flexible than `filepath.Walk`.
## Usage Example
Additional examples are provided in the `examples/` subdirectory.
This library will normalize the provided top level directory name
based on the os-specific path separator by calling `filepath.Clean` on
its first argument. However it always provides the pathname created by
using the correct os-specific path separator when invoking the
provided callback function.
```Go
dirname := "some/directory/root"
err := godirwalk.Walk(dirname, &godirwalk.Options{
Callback: func(osPathname string, de *godirwalk.Dirent) error {
fmt.Printf("%s %s\n", de.ModeType(), osPathname)
return nil
},
Unsorted: true, // (optional) set true for faster yet non-deterministic enumeration (see godoc)
})
```
This library not only provides functions for traversing a file system
directory tree, but also for obtaining a list of immediate descendants
of a particular directory, typically much more quickly than using
`os.ReadDir` or `os.ReadDirnames`.
## Description
Here's why I use `godirwalk` in preference to `filepath.Walk`,
`os.ReadDir`, and `os.ReadDirnames`.
### It's faster than `filepath.Walk`
When compared against `filepath.Walk` in benchmarks, it has been
observed to run between five and ten times the speed on darwin, at
speeds comparable to the that of the unix `find` utility; about twice
the speed on linux; and about four times the speed on Windows.
How does it obtain this performance boost? It does less work to give
you nearly the same output. This library calls the same `syscall`
functions to do the work, but it makes fewer calls, does not throw
away information that it might need, and creates less memory churn
along the way by reusing the same scratch buffer for reading from a
directory rather than reallocating a new buffer every time it reads
file system entry data from the operating system.
While traversing a file system directory tree, `filepath.Walk` obtains
the list of immediate descendants of a directory, and throws away the
file system node type information provided by the operating system
that comes with the node's name. Then, immediately prior to invoking
the callback function, `filepath.Walk` invokes `os.Stat` for each
node, and passes the returned `os.FileInfo` information to the
callback.
While the `os.FileInfo` information provided by `os.Stat` is extremely
helpful--and even includes the `os.FileMode` data--providing it
requires an additional system call for each node.
Because most callbacks only care about what the node type is, this
library does not throw the type information away, but rather provides
that information to the callback function in the form of a
`os.FileMode` value. Note that the provided `os.FileMode` value that
this library provides only has the node type information, and does not
have the permission bits, sticky bits, or other information from the
file's mode. If the callback does care about a particular node's
entire `os.FileInfo` data structure, the callback can easiy invoke
`os.Stat` when needed, and only when needed.
#### Benchmarks
##### macOS
```Bash
$ go test -bench=. -benchmem
goos: darwin
goarch: amd64
pkg: github.com/karrick/godirwalk
BenchmarkReadDirnamesStandardLibrary-12 50000 26250 ns/op 10360 B/op 16 allocs/op
BenchmarkReadDirnamesThisLibrary-12 50000 24372 ns/op 5064 B/op 20 allocs/op
BenchmarkFilepathWalk-12 1 1099524875 ns/op 228415912 B/op 416952 allocs/op
BenchmarkGodirwalk-12 2 526754589 ns/op 103110464 B/op 451442 allocs/op
BenchmarkGodirwalkUnsorted-12 3 509219296 ns/op 100751400 B/op 378800 allocs/op
BenchmarkFlameGraphFilepathWalk-12 1 7478618820 ns/op 2284138176 B/op 4169453 allocs/op
BenchmarkFlameGraphGodirwalk-12 1 4977264058 ns/op 1031105328 B/op 4514423 allocs/op
PASS
ok github.com/karrick/godirwalk 21.219s
```
##### Linux
```Bash
$ go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/karrick/godirwalk
BenchmarkReadDirnamesStandardLibrary-12 100000 15458 ns/op 10360 B/op 16 allocs/op
BenchmarkReadDirnamesThisLibrary-12 100000 14646 ns/op 5064 B/op 20 allocs/op
BenchmarkFilepathWalk-12 2 631034745 ns/op 228210216 B/op 416939 allocs/op
BenchmarkGodirwalk-12 3 358714883 ns/op 102988664 B/op 451437 allocs/op
BenchmarkGodirwalkUnsorted-12 3 355363915 ns/op 100629234 B/op 378796 allocs/op
BenchmarkFlameGraphFilepathWalk-12 1 6086913991 ns/op 2282104720 B/op 4169417 allocs/op
BenchmarkFlameGraphGodirwalk-12 1 3456398824 ns/op 1029886400 B/op 4514373 allocs/op
PASS
ok github.com/karrick/godirwalk 19.179s
```
### It's more correct on Windows than `filepath.Walk`
I did not previously care about this either, but humor me. We all love
how we can write once and run everywhere. It is essential for the
language's adoption, growth, and success, that the software we create
can run unmodified on all architectures and operating systems
supported by Go.
When the traversed file system has a logical loop caused by symbolic
links to directories, on unix `filepath.Walk` ignores symbolic links
and traverses the entire directory tree without error. On Windows
however, `filepath.Walk` will continue following directory symbolic
links, even though it is not supposed to, eventually causing
`filepath.Walk` to terminate early and return an error when the
pathname gets too long from concatenating endless loops of symbolic
links onto the pathname. This error comes from Windows, passes through
`filepath.Walk`, and to the upstream client running `filepath.Walk`.
The takeaway is that behavior is different based on which platform
`filepath.Walk` is running. While this is clearly not intentional,
until it is fixed in the standard library, it presents a compatibility
problem.
This library correctly identifies symbolic links that point to
directories and will only follow them when `FollowSymbolicLinks` is
set to true. Behavior on Windows and other operating systems is
identical.
### It's more easy to use than `filepath.Walk`
Since this library does not invoke `os.Stat` on every file system node
it encounters, there is no possible error event for the callback
function to filter on. The third argument in the `filepath.WalkFunc`
function signature to pass the error from `os.Stat` to the callback
function is no longer necessary, and thus eliminated from signature of
the callback function from this library.
Also, `filepath.Walk` invokes the callback function with a solidus
delimited pathname regardless of the os-specific path separator. This
library invokes the callback function with the os-specific pathname
separator, obviating a call to `filepath.Clean` in the callback
function for each node prior to actually using the provided pathname.
In other words, even on Windows, `filepath.Walk` will invoke the
callback with `some/path/to/foo.txt`, requiring well written clients
to perform pathname normalization for every file prior to working with
the specified file. In truth, many clients developed on unix and not
tested on Windows neglect this subtlety, and will result in software
bugs when running on Windows. This library would invoke the callback
function with `some\path\to\foo.txt` for the same file when running on
Windows, eliminating the need to normalize the pathname by the client,
and lessen the likelyhood that a client will work on unix but not on
Windows.
### It's more flexible than `filepath.Walk`
#### Configurable Handling of Symbolic Links
The default behavior of this library is to ignore symbolic links to
directories when walking a directory tree, just like `filepath.Walk`
does. However, it does invoke the callback function with each node it
finds, including symbolic links. If a particular use case exists to
follow symbolic links when traversing a directory tree, this library
can be invoked in manner to do so, by setting the
`FollowSymbolicLinks` parameter to true.
#### Configurable Sorting of Directory Children
The default behavior of this library is to always sort the immediate
descendants of a directory prior to visiting each node, just like
`filepath.Walk` does. This is usually the desired behavior. However,
this does come at slight performance and memory penalties required to
sort the names when a directory node has many entries. Additionally if
caller specifies `Unsorted` enumeration, reading directories is lazily
performed as the caller consumes entries. If a particular use case
exists that does not require sorting the directory's immediate
descendants prior to visiting its nodes, this library will skip the
sorting step when the `Unsorted` parameter is set to true.
#### Configurable Post Children Callback
This library provides upstream code with the ability to specify a
callback to be invoked for each directory after its children are
processed. This has been used to recursively delete empty directories
after traversing the file system in a more efficient manner. See the
`examples/clean-empties` directory for an example of this usage.
#### Configurable Error Callback
This library provides upstream code with the ability to specify a
callback to be invoked for errors that the operating system returns,
allowing the upstream code to determine the next course of action to
take, whether to halt walking the hierarchy, as it would do were no
error callback provided, or skip the node that caused the error. See
the `examples/walk-fast` directory for an example of this usage.

View File

@ -0,0 +1,14 @@
// +build godirwalk_debug
package godirwalk
import (
"fmt"
"os"
)
// debug formats and prints arguments to stderr for development builds
func debug(f string, a ...interface{}) {
// fmt.Fprintf(os.Stderr, f, a...)
os.Stderr.Write([]byte("godirwalk: " + fmt.Sprintf(f, a...)))
}

View File

@ -0,0 +1,6 @@
// +build !godirwalk_debug
package godirwalk
// debug is a no-op for release builds
func debug(_ string, _ ...interface{}) {}

View File

@ -0,0 +1,90 @@
package godirwalk
import (
"os"
"path/filepath"
)
// Dirent stores the name and file system mode type of discovered file system
// entries.
type Dirent struct {
name string // name is the basename of the file system entry.
modeType os.FileMode // modeType is the type of file system entry.
}
// NewDirent returns a newly initialized Dirent structure, or an error. This
// function does not follow symbolic links.
//
// This function is rarely used, as Dirent structures are provided by other
// functions in this library that read and walk directories, but is provided,
// however, for the occasion when a program needs to create a Dirent.
func NewDirent(osPathname string) (*Dirent, error) {
modeType, err := modeType(osPathname)
if err != nil {
return nil, err
}
return &Dirent{
name: filepath.Base(osPathname),
modeType: modeType,
}, nil
}
// // dup returns a duplicate of the directory entry.
// func (de Dirent) dup() *Dirent {
// return &Dirent{
// name: de.name,
// modeType: de.modeType,
// }
// }
// Name returns the basename of the file system entry.
func (de Dirent) Name() string { return de.name }
// ModeType returns the mode bits that specify the file system node type. We
// could make our own enum-like data type for encoding the file type, but Go's
// runtime already gives us architecture independent file modes, as discussed in
// `os/types.go`:
//
// Go's runtime FileMode type has same definition on all systems, so that
// information about files can be moved from one system to another portably.
func (de Dirent) ModeType() os.FileMode { return de.modeType }
// IsDir returns true if and only if the Dirent represents a file system
// directory. Note that on some operating systems, more than one file mode bit
// may be set for a node. For instance, on Windows, a symbolic link that points
// to a directory will have both the directory and the symbolic link bits set.
func (de Dirent) IsDir() bool { return de.modeType&os.ModeDir != 0 }
// IsRegular returns true if and only if the Dirent represents a regular file.
// That is, it ensures that no mode type bits are set.
func (de Dirent) IsRegular() bool { return de.modeType&os.ModeType == 0 }
// IsSymlink returns true if and only if the Dirent represents a file system
// symbolic link. Note that on some operating systems, more than one file mode
// bit may be set for a node. For instance, on Windows, a symbolic link that
// points to a directory will have both the directory and the symbolic link bits
// set.
func (de Dirent) IsSymlink() bool { return de.modeType&os.ModeSymlink != 0 }
// IsDevice returns true if and only if the Dirent represents a device file.
func (de Dirent) IsDevice() bool { return de.modeType&os.ModeDevice != 0 }
// reset releases memory held by entry err and name, and resets mode type to 0.
func (de *Dirent) reset() {
de.name = ""
de.modeType = 0
}
// Dirents represents a slice of Dirent pointers, which are sortable by
// name. This type satisfies the `sort.Interface` interface.
type Dirents []*Dirent
// Len returns the count of Dirent structures in the slice.
func (l Dirents) Len() int { return len(l) }
// Less returns true if and only if the Name of the element specified by the
// first index is lexicographically less than that of the second index.
func (l Dirents) Less(i, j int) bool { return l[i].name < l[j].name }
// Swap exchanges the two Dirent entries specified by the two provided indexes.
func (l Dirents) Swap(i, j int) { l[i], l[j] = l[j], l[i] }

View File

@ -0,0 +1,37 @@
/*
Package godirwalk provides functions to read and traverse directory trees.
In short, why do I use this library?
* It's faster than `filepath.Walk`.
* It's more correct on Windows than `filepath.Walk`.
* It's more easy to use than `filepath.Walk`.
* It's more flexible than `filepath.Walk`.
USAGE
This library will normalize the provided top level directory name based on the
os-specific path separator by calling `filepath.Clean` on its first
argument. However it always provides the pathname created by using the correct
os-specific path separator when invoking the provided callback function.
dirname := "some/directory/root"
err := godirwalk.Walk(dirname, &godirwalk.Options{
Callback: func(osPathname string, de *godirwalk.Dirent) error {
fmt.Printf("%s %s\n", de.ModeType(), osPathname)
return nil
},
})
This library not only provides functions for traversing a file system directory
tree, but also for obtaining a list of immediate descendants of a particular
directory, typically much more quickly than using `os.ReadDir` or
`os.ReadDirnames`.
dirname := "some/directory"
names, err := godirwalk.ReadDirnames()
*/
package godirwalk

View File

@ -0,0 +1,9 @@
// +build dragonfly freebsd openbsd netbsd
package godirwalk
import "syscall"
func inoFromDirent(de *syscall.Dirent) uint64 {
return uint64(de.Fileno)
}

View File

@ -0,0 +1,10 @@
// +build aix darwin linux nacl solaris
package godirwalk
import "syscall"
func inoFromDirent(de *syscall.Dirent) uint64 {
// cast necessary on file systems that store ino as different type
return uint64(de.Ino)
}

View File

@ -0,0 +1,22 @@
package godirwalk
import (
"os"
)
// modeType returns the mode type of the file system entry identified by
// osPathname by calling os.LStat function, to intentionally not follow symbolic
// links.
//
// Even though os.LStat provides all file mode bits, we want to ensure same
// values returned to caller regardless of whether we obtained file mode bits
// from syscall or stat call. Therefore mask out the additional file mode bits
// that are provided by stat but not by the syscall, so users can rely on their
// values.
func modeType(osPathname string) (os.FileMode, error) {
fi, err := os.Lstat(osPathname)
if err == nil {
return fi.Mode() & os.ModeType, nil
}
return 0, err
}

View File

@ -0,0 +1,37 @@
// +build darwin dragonfly freebsd linux netbsd openbsd
package godirwalk
import (
"os"
"path/filepath"
"syscall"
)
// modeTypeFromDirent converts a syscall defined constant, which is in purview
// of OS, to a constant defined by Go, assumed by this project to be stable.
//
// When the syscall constant is not recognized, this function falls back to a
// Stat on the file system.
func modeTypeFromDirent(de *syscall.Dirent, osDirname, osBasename string) (os.FileMode, error) {
switch de.Type {
case syscall.DT_REG:
return 0, nil
case syscall.DT_DIR:
return os.ModeDir, nil
case syscall.DT_LNK:
return os.ModeSymlink, nil
case syscall.DT_CHR:
return os.ModeDevice | os.ModeCharDevice, nil
case syscall.DT_BLK:
return os.ModeDevice, nil
case syscall.DT_FIFO:
return os.ModeNamedPipe, nil
case syscall.DT_SOCK:
return os.ModeSocket, nil
default:
// If syscall returned unknown type (e.g., DT_UNKNOWN, DT_WHT), then
// resolve actual mode by reading file information.
return modeType(filepath.Join(osDirname, osBasename))
}
}

View File

@ -0,0 +1,18 @@
// +build aix js nacl solaris
package godirwalk
import (
"os"
"path/filepath"
"syscall"
)
// modeTypeFromDirent converts a syscall defined constant, which is in purview
// of OS, to a constant defined by Go, assumed by this project to be stable.
//
// Because some operating system syscall.Dirent structures do not include a Type
// field, fall back on Stat of the file system.
func modeTypeFromDirent(_ *syscall.Dirent, osDirname, osBasename string) (os.FileMode, error) {
return modeType(filepath.Join(osDirname, osBasename))
}

View File

@ -0,0 +1,29 @@
// +build aix darwin dragonfly freebsd netbsd openbsd
package godirwalk
import (
"reflect"
"syscall"
"unsafe"
)
func nameFromDirent(de *syscall.Dirent) []byte {
// Because this GOOS' syscall.Dirent provides a Namlen field that says how
// long the name is, this function does not need to search for the NULL
// byte.
ml := int(de.Namlen)
// Convert syscall.Dirent.Name, which is array of int8, to []byte, by
// overwriting Cap, Len, and Data slice header fields to values from
// syscall.Dirent fields. Setting the Cap, Len, and Data field values for
// the slice header modifies what the slice header points to, and in this
// case, the name buffer.
var name []byte
sh := (*reflect.SliceHeader)(unsafe.Pointer(&name))
sh.Cap = ml
sh.Len = ml
sh.Data = uintptr(unsafe.Pointer(&de.Name[0]))
return name
}

View File

@ -0,0 +1,42 @@
// +build nacl linux js solaris
package godirwalk
import (
"bytes"
"reflect"
"syscall"
"unsafe"
)
// nameOffset is a compile time constant
const nameOffset = int(unsafe.Offsetof(syscall.Dirent{}.Name))
func nameFromDirent(de *syscall.Dirent) (name []byte) {
// Because this GOOS' syscall.Dirent does not provide a field that specifies
// the name length, this function must first calculate the max possible name
// length, and then search for the NULL byte.
ml := int(de.Reclen) - nameOffset
// Convert syscall.Dirent.Name, which is array of int8, to []byte, by
// overwriting Cap, Len, and Data slice header fields to the max possible
// name length computed above, and finding the terminating NULL byte.
sh := (*reflect.SliceHeader)(unsafe.Pointer(&name))
sh.Cap = ml
sh.Len = ml
sh.Data = uintptr(unsafe.Pointer(&de.Name[0]))
if index := bytes.IndexByte(name, 0); index >= 0 {
// Found NULL byte; set slice's cap and len accordingly.
sh.Cap = index
sh.Len = index
return
}
// NOTE: This branch is not expected, but included for defensive
// programming, and provides a hard stop on the name based on the structure
// field array size.
sh.Cap = len(de.Name)
sh.Len = sh.Cap
return
}

View File

@ -0,0 +1,73 @@
package godirwalk
// ReadDirents returns a sortable slice of pointers to Dirent structures, each
// representing the file system name and mode type for one of the immediate
// descendant of the specified directory. If the specified directory is a
// symbolic link, it will be resolved.
//
// The second parameter was an optional scratch buffer, but is no longer used
// because ReadDirents invokes Scanner to enumerate the contents of the
// directory.
//
// children, err := godirwalk.ReadDirents(osDirname, nil)
// if err != nil {
// return nil, errors.Wrap(err, "cannot get list of directory children")
// }
// sort.Sort(children)
// for _, child := range children {
// fmt.Printf("%s %s\n", child.ModeType, child.Name)
// }
func ReadDirents(osDirname string, _ []byte) (Dirents, error) {
var entries Dirents
scanner, err := NewScanner(osDirname)
if err != nil {
return nil, err
}
for scanner.Scan() {
if dirent, err := scanner.Dirent(); err == nil {
entries = append(entries, dirent)
}
}
if err = scanner.Err(); err != nil {
return nil, err
}
return entries, nil
}
// ReadDirnames returns a slice of strings, representing the immediate
// descendants of the specified directory. If the specified directory is a
// symbolic link, it will be resolved.
//
// The second parameter was an optional scratch buffer, but is no longer used
// because ReadDirents invokes Scanner to enumerate the contents of the
// directory.
//
// Note that this function, depending on operating system, may or may not invoke
// the ReadDirents function, in order to prepare the list of immediate
// descendants. Therefore, if your program needs both the names and the file
// system mode types of descendants, it will always be faster to invoke
// ReadDirents directly, rather than calling this function, then looping over
// the results and calling os.Stat or os.LStat for each entry.
//
// children, err := godirwalk.ReadDirnames(osDirname, nil)
// if err != nil {
// return nil, errors.Wrap(err, "cannot get list of directory children")
// }
// sort.Strings(children)
// for _, child := range children {
// fmt.Printf("%s\n", child)
// }
func ReadDirnames(osDirname string, _ []byte) ([]string, error) {
var entries []string
scanner, err := NewScanner(osDirname)
if err != nil {
return nil, err
}
for scanner.Scan() {
entries = append(entries, scanner.Name())
}
if err = scanner.Err(); err != nil {
return nil, err
}
return entries, nil
}

View File

@ -0,0 +1,140 @@
// +build !windows
package godirwalk
import (
"io"
"os"
"syscall"
"unsafe"
)
// MinimumScratchBufferSize specifies the minimum size of the scratch buffer
// that Walk, ReadDirents, ReadDirnames, and Scandir will use when reading file
// entries from the operating system. It is initialized to the result from
// calling `os.Getpagesize()` during program startup.
var MinimumScratchBufferSize = os.Getpagesize()
// Scanner is an iterator to enumerate the contents of a directory.
type Scanner struct {
scratchBuffer []byte // read directory bytes from file system into this buffer
workBuffer []byte // points into scratchBuffer, from which we chunk out directory entries
osDirname string
childName string
err error // err is the error associated with scanning directory
statErr error // statErr is any error return while attempting to stat an entry
dh *os.File // used to close directory after done reading
de *Dirent // most recently decoded directory entry
sde *syscall.Dirent
fd int // file descriptor used to read entries from directory
}
// NewScanner returns a new directory Scanner.
func NewScanner(osDirname string) (*Scanner, error) {
dh, err := os.Open(osDirname)
if err != nil {
return nil, err
}
scanner := &Scanner{
scratchBuffer: make([]byte, MinimumScratchBufferSize),
osDirname: osDirname,
dh: dh,
fd: int(dh.Fd()),
}
return scanner, nil
}
// Dirent returns the current directory entry while scanning a directory.
func (s *Scanner) Dirent() (*Dirent, error) {
if s.de == nil {
s.de = &Dirent{name: s.childName}
s.de.modeType, s.statErr = modeTypeFromDirent(s.sde, s.osDirname, s.childName)
}
return s.de, s.statErr
}
// done is called when directory scanner unable to continue, with either the
// triggering error, or nil when there are simply no more entries to read from
// the directory.
func (s *Scanner) done(err error) {
if s.dh == nil {
return
}
cerr := s.dh.Close()
s.dh = nil
if err == nil {
s.err = cerr
} else {
s.err = err
}
s.osDirname, s.childName = "", ""
s.scratchBuffer, s.workBuffer = nil, nil
s.statErr, s.de, s.sde = nil, nil, nil
s.fd = 0
}
// Err returns the error associated with scanning a directory.
func (s *Scanner) Err() error {
s.done(s.err)
if s.err == io.EOF {
return nil
}
return s.err
}
// Name returns the name of the current directory entry while scanning a
// directory.
func (s *Scanner) Name() string { return s.childName }
// Scan potentially reads and then decodes the next directory entry from the
// file system.
//
// When it returns false, this releases resources used by the Scanner then
// returns any error associated with closing the file system directory resource.
func (s *Scanner) Scan() bool {
if s.err != nil {
return false
}
for {
// When the work buffer has nothing remaining to decode, we need to load
// more data from disk.
if len(s.workBuffer) == 0 {
n, err := syscall.ReadDirent(s.fd, s.scratchBuffer)
if err != nil {
s.done(err)
return false
}
if n <= 0 { // end of directory
s.done(io.EOF)
return false
}
s.workBuffer = s.scratchBuffer[:n] // trim work buffer to number of bytes read
}
// Loop until we have a usable file system entry, or we run out of data
// in the work buffer.
for len(s.workBuffer) > 0 {
s.sde = (*syscall.Dirent)(unsafe.Pointer(&s.workBuffer[0])) // point entry to first syscall.Dirent in buffer
s.workBuffer = s.workBuffer[s.sde.Reclen:] // advance buffer for next iteration through loop
if inoFromDirent(s.sde) == 0 {
continue // inode set to 0 indicates an entry that was marked as deleted
}
nameSlice := nameFromDirent(s.sde)
namlen := len(nameSlice)
if namlen == 0 || (nameSlice[0] == '.' && (namlen == 1 || (namlen == 2 && nameSlice[1] == '.'))) {
continue
}
s.de = nil
s.childName = string(nameSlice)
return true
}
// No more data in the work buffer, so loop around in the outside loop
// to fetch more data.
}
}

View File

@ -0,0 +1,92 @@
// +build windows
package godirwalk
import (
"fmt"
"io"
"os"
)
// Scanner is an iterator to enumerate the contents of a directory.
type Scanner struct {
osDirname string
dh *os.File // dh is handle to open directory
de *Dirent
err error // err is the error associated with scanning directory
}
// NewScanner returns a new directory Scanner.
func NewScanner(osDirname string) (*Scanner, error) {
dh, err := os.Open(osDirname)
if err != nil {
return nil, err
}
scanner := &Scanner{
osDirname: osDirname,
dh: dh,
}
return scanner, nil
}
// Dirent returns the current directory entry while scanning a directory.
func (s *Scanner) Dirent() (*Dirent, error) { return s.de, nil }
// done is called when directory scanner unable to continue, with either the
// triggering error, or nil when there are simply no more entries to read from
// the directory.
func (s *Scanner) done(err error) {
if s.dh == nil {
return
}
cerr := s.dh.Close()
s.dh = nil
if err == nil {
s.err = cerr
} else {
s.err = err
}
s.osDirname = ""
s.de = nil
}
// Err returns the error associated with scanning a directory.
func (s *Scanner) Err() error {
s.done(s.err)
if s.err == io.EOF {
return nil
}
return s.err
}
// Name returns the name of the current directory entry while scanning a
// directory.
func (s *Scanner) Name() string { return s.de.name }
// Scan potentially reads and then decodes the next directory entry from the
// file system.
func (s *Scanner) Scan() bool {
if s.err != nil {
return false
}
fileinfos, err := s.dh.Readdir(1)
if err != nil {
s.err = err
return false
}
if l := len(fileinfos); l != 1 {
s.err = fmt.Errorf("expected a single entry rather than %d", l)
return false
}
fi := fileinfos[0]
s.de = &Dirent{
name: fi.Name(),
modeType: fi.Mode() & os.ModeType,
}
return true
}

View File

@ -0,0 +1,44 @@
package godirwalk
import "sort"
type scanner interface {
Dirent() (*Dirent, error)
Err() error
Name() string
Scan() bool
}
// sortedScanner enumerates through a directory's contents after reading the
// entire directory and sorting the entries by name. Used by walk to simplify
// its implementation.
type sortedScanner struct {
dd []*Dirent
de *Dirent
}
func newSortedScanner(osPathname string) (*sortedScanner, error) {
deChildren, err := ReadDirents(osPathname, nil)
if err != nil {
return nil, err
}
sort.Sort(deChildren)
return &sortedScanner{dd: deChildren}, nil
}
func (d *sortedScanner) Err() error {
d.dd, d.de = nil, nil
return nil
}
func (d *sortedScanner) Dirent() (*Dirent, error) { return d.de, nil }
func (d *sortedScanner) Name() string { return d.de.name }
func (d *sortedScanner) Scan() bool {
if len(d.dd) > 0 {
d.de, d.dd = d.dd[0], d.dd[1:]
return true
}
return false
}

View File

@ -0,0 +1,22 @@
package godirwalk
import "os"
func isDirectoryOrSymlinkToDirectory(de *Dirent, osPathname string) (bool, error) {
if de.IsDir() {
return true, nil
}
return isSymlinkToDirectory(de, osPathname)
}
func isSymlinkToDirectory(de *Dirent, osPathname string) (bool, error) {
if !de.IsSymlink() {
return false, nil
}
// Need to resolve the symbolic link's referent in order to respond.
info, err := os.Stat(osPathname)
if err != nil {
return false, err
}
return info.IsDir(), nil
}

View File

@ -0,0 +1,316 @@
package godirwalk
import (
"errors"
"fmt"
"os"
"path/filepath"
)
// DefaultScratchBuffer is a deprecated config parameter, whose usage was
// obsoleted by the introduction of the Scanner struct, and migrating
// ReadDirents, ReadDirnames, and Walk to use Scanner for enumerating directory
// contents.
const DefaultScratchBufferSize = 0
// Options provide parameters for how the Walk function operates.
type Options struct {
// ErrorCallback specifies a function to be invoked in the case of an error
// that could potentially be ignored while walking a file system
// hierarchy. When set to nil or left as its zero-value, any error condition
// causes Walk to immediately return the error describing what took
// place. When non-nil, this user supplied function is invoked with the OS
// pathname of the file system object that caused the error along with the
// error that took place. The return value of the supplied ErrorCallback
// function determines whether the error will cause Walk to halt immediately
// as it would were no ErrorCallback value provided, or skip this file
// system node yet continue on with the remaining nodes in the file system
// hierarchy.
//
// ErrorCallback is invoked both for errors that are returned by the
// runtime, and for errors returned by other user supplied callback
// functions.
ErrorCallback func(string, error) ErrorAction
// FollowSymbolicLinks specifies whether Walk will follow symbolic links
// that refer to directories. When set to false or left as its zero-value,
// Walk will still invoke the callback function with symbolic link nodes,
// but if the symbolic link refers to a directory, it will not recurse on
// that directory. When set to true, Walk will recurse on symbolic links
// that refer to a directory.
FollowSymbolicLinks bool
// Unsorted controls whether or not Walk will sort the immediate descendants
// of a directory by their relative names prior to visiting each of those
// entries.
//
// When set to false or left at its zero-value, Walk will get the list of
// immediate descendants of a particular directory, sort that list by
// lexical order of their names, and then visit each node in the list in
// sorted order. This will cause Walk to always traverse the same directory
// tree in the same order, however may be inefficient for directories with
// many immediate descendants.
//
// When set to true, Walk skips sorting the list of immediate descendants
// for a directory, and simply visits each node in the order the operating
// system enumerated them. This will be more fast, but with the side effect
// that the traversal order may be different from one invocation to the
// next.
Unsorted bool
// Callback is a required function that Walk will invoke for every file
// system node it encounters.
Callback WalkFunc
// PostChildrenCallback is an option function that Walk will invoke for
// every file system directory it encounters after its children have been
// processed.
PostChildrenCallback WalkFunc
// ScratchBuffer is a deprecated config parameter, whose usage was obsoleted
// by the introduction of the Scanner struct, and migrating ReadDirents,
// ReadDirnames, and Walk to use Scanner for enumerating directory contents.
ScratchBuffer []byte
}
// ErrorAction defines a set of actions the Walk function could take based on
// the occurrence of an error while walking the file system. See the
// documentation for the ErrorCallback field of the Options structure for more
// information.
type ErrorAction int
const (
// Halt is the ErrorAction return value when the upstream code wants to halt
// the walk process when a runtime error takes place. It matches the default
// action the Walk function would take were no ErrorCallback provided.
Halt ErrorAction = iota
// SkipNode is the ErrorAction return value when the upstream code wants to
// ignore the runtime error for the current file system node, skip
// processing of the node that caused the error, and continue walking the
// file system hierarchy with the remaining nodes.
SkipNode
)
// WalkFunc is the type of the function called for each file system node visited
// by Walk. The pathname argument will contain the argument to Walk as a prefix;
// that is, if Walk is called with "dir", which is a directory containing the
// file "a", the provided WalkFunc will be invoked with the argument "dir/a",
// using the correct os.PathSeparator for the Go Operating System architecture,
// GOOS. The directory entry argument is a pointer to a Dirent for the node,
// providing access to both the basename and the mode type of the file system
// node.
//
// If an error is returned by the Callback or PostChildrenCallback functions,
// and no ErrorCallback function is provided, processing stops. If an
// ErrorCallback function is provided, then it is invoked with the OS pathname
// of the node that caused the error along along with the error. The return
// value of the ErrorCallback function determines whether to halt processing, or
// skip this node and continue processing remaining file system nodes.
//
// The exception is when the function returns the special value
// filepath.SkipDir. If the function returns filepath.SkipDir when invoked on a
// directory, Walk skips the directory's contents entirely. If the function
// returns filepath.SkipDir when invoked on a non-directory file system node,
// Walk skips the remaining files in the containing directory. Note that any
// supplied ErrorCallback function is not invoked with filepath.SkipDir when the
// Callback or PostChildrenCallback functions return that special value.
type WalkFunc func(osPathname string, directoryEntry *Dirent) error
// Walk walks the file tree rooted at the specified directory, calling the
// specified callback function for each file system node in the tree, including
// root, symbolic links, and other node types. The nodes are walked in lexical
// order, which makes the output deterministic but means that for very large
// directories this function can be inefficient.
//
// This function is often much faster than filepath.Walk because it does not
// invoke os.Stat for every node it encounters, but rather obtains the file
// system node type when it reads the parent directory.
//
// If a runtime error occurs, either from the operating system or from the
// upstream Callback or PostChildrenCallback functions, processing typically
// halts. However, when an ErrorCallback function is provided in the provided
// Options structure, that function is invoked with the error along with the OS
// pathname of the file system node that caused the error. The ErrorCallback
// function's return value determines the action that Walk will then take.
//
// func main() {
// dirname := "."
// if len(os.Args) > 1 {
// dirname = os.Args[1]
// }
// err := godirwalk.Walk(dirname, &godirwalk.Options{
// Callback: func(osPathname string, de *godirwalk.Dirent) error {
// fmt.Printf("%s %s\n", de.ModeType(), osPathname)
// return nil
// },
// ErrorCallback: func(osPathname string, err error) godirwalk.ErrorAction {
// // Your program may want to log the error somehow.
// fmt.Fprintf(os.Stderr, "ERROR: %s\n", err)
//
// // For the purposes of this example, a simple SkipNode will suffice,
// // although in reality perhaps additional logic might be called for.
// return godirwalk.SkipNode
// },
// })
// if err != nil {
// fmt.Fprintf(os.Stderr, "%s\n", err)
// os.Exit(1)
// }
// }
func Walk(pathname string, options *Options) error {
if options.Callback == nil {
return errors.New("cannot walk without a specified Callback function")
}
pathname = filepath.Clean(pathname)
var fi os.FileInfo
var err error
if options.FollowSymbolicLinks {
fi, err = os.Stat(pathname)
if err != nil {
return err
}
} else {
fi, err = os.Lstat(pathname)
if err != nil {
return err
}
}
mode := fi.Mode()
if mode&os.ModeDir == 0 {
return fmt.Errorf("cannot Walk non-directory: %s", pathname)
}
// If ErrorCallback is nil, set to a default value that halts the walk
// process on all operating system errors. This is done to allow error
// handling to be more succinct in the walk code.
if options.ErrorCallback == nil {
options.ErrorCallback = defaultErrorCallback
}
dirent := &Dirent{
name: filepath.Base(pathname),
modeType: mode & os.ModeType,
}
err = walk(pathname, dirent, options)
if err == filepath.SkipDir {
return nil // silence SkipDir for top level
}
return err
}
// defaultErrorCallback always returns Halt because if the upstream code did not
// provide an ErrorCallback function, walking the file system hierarchy ought to
// halt upon any operating system error.
func defaultErrorCallback(_ string, _ error) ErrorAction { return Halt }
// walk recursively traverses the file system node specified by pathname and the
// Dirent.
func walk(osPathname string, dirent *Dirent, options *Options) error {
err := options.Callback(osPathname, dirent)
if err != nil {
if err == filepath.SkipDir {
return err
}
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
}
if dirent.IsSymlink() {
if !options.FollowSymbolicLinks {
return nil
}
isDir, err := isSymlinkToDirectory(dirent, osPathname)
if err != nil {
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
}
if !isDir {
return nil
}
} else if !dirent.IsDir() {
return nil
}
// If get here, then specified pathname refers to a directory or a
// symbolic link to a directory.
var ds scanner
if options.Unsorted {
// When upstream does not request a sorted iteration, it's more memory
// efficient to read a single child at a time from the file system.
ds, err = NewScanner(osPathname)
} else {
// When upstream wants a sorted iteration, we must read the entire
// directory and sort through the child names, and then iterate on each
// child.
ds, err = newSortedScanner(osPathname)
}
if err != nil {
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
}
for ds.Scan() {
deChild, err := ds.Dirent()
osChildname := filepath.Join(osPathname, deChild.name)
if err != nil {
if action := options.ErrorCallback(osChildname, err); action == SkipNode {
return nil
}
return err
}
err = walk(osChildname, deChild, options)
debug("osChildname: %q; error: %v\n", osChildname, err)
if err == nil {
continue
}
if err != filepath.SkipDir {
return err
}
// When received SkipDir on a directory or a symbolic link to a
// directory, stop processing that directory but continue processing
// siblings. When received on a non-directory, stop processing
// remaining siblings.
isDir, err := isDirectoryOrSymlinkToDirectory(deChild, osChildname)
if err != nil {
if action := options.ErrorCallback(osChildname, err); action == SkipNode {
continue // ignore and continue with next sibling
}
return err // caller does not approve of this error
}
if !isDir {
break // stop processing remaining siblings, but allow post children callback
}
// continue processing remaining siblings
}
if err = ds.Err(); err != nil {
return err
}
if options.PostChildrenCallback == nil {
return nil
}
err = options.PostChildrenCallback(osPathname, dirent)
if err == nil || err == filepath.SkipDir {
return err
}
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
}

View File

@ -0,0 +1,29 @@
*.log
.DS_Store
doc
tmp
pkg
*.gem
*.pid
coverage
coverage.data
build/*
*.pbxuser
*.mode1v3
.svn
profile
.console_history
.sass-cache/*
.rake_tasks~
*.log.lck
solr/
.jhw-cache/
jhw.*
*.sublime*
node_modules/
dist/
generated/
.vendor/
bin/*
gin-bin
.idea/

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 Mark Bates
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.

View File

@ -0,0 +1,61 @@
TAGS ?= ""
GO_BIN ?= "go"
install:
$(GO_BIN) install -tags ${TAGS} -v .
make tidy
tidy:
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
else
echo skipping go mod tidy
endif
deps:
$(GO_BIN) get -tags ${TAGS} -t ./...
make tidy
build:
$(GO_BIN) build -v .
make tidy
test:
$(GO_BIN) test -cover -tags ${TAGS} ./...
make tidy
ci-deps:
$(GO_BIN) get -tags ${TAGS} -t ./...
ci-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
lint:
go get github.com/golangci/golangci-lint/cmd/golangci-lint
golangci-lint run --enable-all
make tidy
update:
ifeq ($(GO111MODULE),on)
rm go.*
$(GO_BIN) mod init
$(GO_BIN) mod tidy
else
$(GO_BIN) get -u -tags ${TAGS}
endif
make test
make install
make tidy
release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy
release:
$(GO_BIN) get github.com/gobuffalo/release
make tidy
release -y -f version.go --skip-packr
make tidy

View File

@ -0,0 +1,6 @@
# github.com/markbates/errx Stands on the Shoulders of Giants
github.com/markbates/errx does not try to reinvent the wheel! Instead, it uses the already great wheels developed by the Go community and puts them all together in the best way possible. Without these giants, this project would not be possible. Please make sure to check them out and thank them for all of their hard work.
Thank you to the following **GIANTS**:

View File

@ -0,0 +1,71 @@
variables:
GOBIN: "$(GOPATH)/bin" # Go binaries path
GOPATH: "$(system.defaultWorkingDirectory)/gopath" # Go workspace path
modulePath: "$(GOPATH)/src/github.com/$(build.repository.name)" # Path to the module"s code
jobs:
- job: Windows
pool:
vmImage: "vs2017-win2016"
strategy:
matrix:
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11.5"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11.5"
GO111MODULE: "off"
go 1.12 (on):
go_version: "1.12"
GO111MODULE: "on"
go 1.12 (off):
go_version: "1.12"
GO111MODULE: "off"
steps:
- template: azure-tests.yml
- job: macOS
pool:
vmImage: "macOS-10.13"
strategy:
matrix:
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11.5"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11.5"
GO111MODULE: "off"
go 1.12 (on):
go_version: "1.12"
GO111MODULE: "on"
go 1.12 (off):
go_version: "1.12"
GO111MODULE: "off"
steps:
- template: azure-tests.yml
- job: Linux
pool:
vmImage: "ubuntu-16.04"
strategy:
matrix:
go 1.10:
go_version: "1.10"
go 1.11 (on):
go_version: "1.11.5"
GO111MODULE: "on"
go 1.11 (off):
go_version: "1.11.5"
GO111MODULE: "off"
go 1.12 (on):
go_version: "1.12"
GO111MODULE: "on"
go 1.12 (off):
go_version: "1.12"
GO111MODULE: "off"
steps:
- template: azure-tests.yml

View File

@ -0,0 +1,19 @@
steps:
- task: GoTool@0
inputs:
version: $(go_version)
- task: Bash@3
inputs:
targetType: inline
script: |
mkdir -p "$(GOBIN)"
mkdir -p "$(GOPATH)/pkg"
mkdir -p "$(modulePath)"
shopt -s extglob
mv !(gopath) "$(modulePath)"
displayName: "Setup Go Workspace"
- script: |
go get -t -v ./...
go test -race ./...
workingDirectory: "$(modulePath)"
displayName: "Tests"

View File

@ -0,0 +1,23 @@
package errx
// go2 errors
type Wrapper interface {
Unwrap() error
}
// pkg/errors
type Causer interface {
Cause() error
}
func Unwrap(err error) error {
switch e := err.(type) {
case Wrapper:
return e.Unwrap()
case Causer:
return e.Cause()
}
return err
}
var Cause = Unwrap

View File

@ -0,0 +1,4 @@
package errx
// Version of errx
const Version = "v1.0.0"

View File

@ -0,0 +1,29 @@
*.log
.DS_Store
doc
tmp
pkg
*.gem
*.pid
coverage
coverage.data
build/*
*.pbxuser
*.mode1v3
.svn
profile
.console_history
.sass-cache/*
.rake_tasks~
*.log.lck
solr/
.jhw-cache/
jhw.*
*.sublime*
node_modules/
dist/
generated/
.vendor/
bin/*
gin-bin
.idea/

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018 Mark Bates
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.

Some files were not shown because too many files have changed in this diff Show More