updated dip

This commit is contained in:
Paul 2020-01-27 21:16:08 +01:00
parent a507ba6b68
commit 755dcd5a65
57 changed files with 2669 additions and 93 deletions

7
.gitignore vendored
View File

@ -15,5 +15,12 @@
# VIM swap files # VIM swap files
*.swp *.swp
# packr related exclusions
/packrd/*
/main-packr.go
# Sample configurations
*.ini *.ini
# executable file
/dip /dip

19
Makefile Normal file
View File

@ -0,0 +1,19 @@
# dip Makefile
GOCMD=go
GOBUILDCMD=${GOCMD} build
GOOPTIONS=-mod=vendor
PACKRCMD=${GOPATH}/bin/packr2
SRCFILES=cmd/dip/*.go
all: build
build:
${GOPATH}/bin/packr2
${GOBUILDCMD} ${GOOPTIONS} ${SRCFILES}
clean:
rm -f dip
${PACKRCMD} clean

View File

@ -4,16 +4,17 @@ dip is a small webservice designed to return public ip address
## Howto ## Howto
### Build ### Pre requisites
Generate embedded static files and templates Install packr to create embedded files in binary executable file
```bash ```bash
go get github.com/gobuffalo/packr/v2 go get -u github.com/gobuffalo/packr/v2/packr2
$GOPATH/bin/packr2
``` ```
### Build
```bash ```bash
go build -mod vendor make
``` ```
### Play ### Play
@ -31,7 +32,7 @@ curl -H "Accept: text/html" http://localhost:8080/
## License ## License
```text ```text
Copyright (c) 2019 PaulBSD Copyright (c) 2020 PaulBSD
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -1,16 +1,16 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os"
//packrd "git.paulbsd.com/paulbsd/dip/packrd" _ "git.paulbsd.com/paulbsd/dip/packrd"
"git.paulbsd.com/paulbsd/dip/src/ip" "git.paulbsd.com/paulbsd/dip/src/page"
"git.paulbsd.com/paulbsd/dip/src/static" "git.paulbsd.com/paulbsd/dip/src/static"
"git.paulbsd.com/paulbsd/dip/src/templates" "git.paulbsd.com/paulbsd/dip/src/templates"
"git.paulbsd.com/paulbsd/dip/utils"
"github.com/gobuffalo/packr/v2" "github.com/gobuffalo/packr/v2"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
//"github.com/markbates/pkger"
) )
func main() { func main() {
@ -18,11 +18,10 @@ func main() {
e.HideBanner = true e.HideBanner = true
var host, port string var host, port string
var p page.Page
p.Title = "Public IP Address Service"
flag.Usage = Usage utils.Flags(&host, &port)
flag.StringVar(&host, "host", "[::]", "Listen host")
flag.StringVar(&port, "port", "8080", "Listen port")
flag.Parse()
templatesbox := packr.New("templates", "./templates") templatesbox := packr.New("templates", "./templates")
staticbox := packr.New("static", "./static") staticbox := packr.New("static", "./static")
@ -30,16 +29,10 @@ func main() {
builtTemplates, _ := templates.BuildTemplates(templatesbox) builtTemplates, _ := templates.BuildTemplates(templatesbox)
e.Renderer = builtTemplates e.Renderer = builtTemplates
e.GET("/", ip.Dip) e.GET("/", p.Index)
e.GET("/static/*", func(c echo.Context) error { e.GET("/static/*", func(c echo.Context) error {
return static.Static(staticbox, c) return static.Static(staticbox, c)
}) })
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%s", host, port))) e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%s", host, port)))
} }
// Usage displays possible arguments
func Usage() {
flag.PrintDefaults()
os.Exit(1)
}

2
go.mod
View File

@ -7,9 +7,9 @@ require (
github.com/labstack/echo/v4 v4.1.11 github.com/labstack/echo/v4 v4.1.11
github.com/likexian/whois-go v1.3.1 github.com/likexian/whois-go v1.3.1
github.com/likexian/whois-parser-go v1.10.2 github.com/likexian/whois-parser-go v1.10.2
github.com/markbates/pkger v0.14.0
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 // indirect golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 // indirect
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe // indirect golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe // indirect
golang.org/x/text v0.3.2 // indirect golang.org/x/text v0.3.2 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
) )

5
go.sum
View File

@ -14,6 +14,8 @@ github.com/gobuffalo/envy v1.7.0 h1:GlXgaiBkmrYMHco6t4j7SacKO4XUjvh5pwXh0f4uxXU=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/envy v1.7.1 h1:OQl5ys5MBea7OGCdvPbBJWRgnhC/fGona6QKfvFeau8= 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/envy v1.7.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI=
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
github.com/gobuffalo/logger v1.0.1 h1:ZEgyRGgAm4ZAhAO45YXMs5Fp+bzGLESFewzAVBMKuTg= 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/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 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4=
@ -43,6 +45,8 @@ github.com/likexian/whois-go v1.3.1/go.mod h1:6aBrKuJZ66dDhXG7/BiZ6uxPzmBocgapf+
github.com/likexian/whois-parser-go v1.10.2 h1:j4qDwPuv7Qnmg3CcSEAywqcTnXCFETMAMn+jhRkTaJs= github.com/likexian/whois-parser-go v1.10.2 h1:j4qDwPuv7Qnmg3CcSEAywqcTnXCFETMAMn+jhRkTaJs=
github.com/likexian/whois-parser-go v1.10.2/go.mod h1:I3zHrhbq4XRmc3nn4xtWNafclqmZXJzW7tSx9KXlCwk= github.com/likexian/whois-parser-go v1.10.2/go.mod h1:I3zHrhbq4XRmc3nn4xtWNafclqmZXJzW7tSx9KXlCwk=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/markbates/pkger v0.14.0 h1:z6KCEBkr3zJTkAMz5SJzjA9Izo+Ipb6XXvOIjQEW+PU=
github.com/markbates/pkger v0.14.0/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
@ -93,6 +97,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g= 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/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-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/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-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-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

View File

@ -1,8 +0,0 @@
// +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 _ "git.paulbsd.com/paulbsd/dip/packrd"

8
packr.go Normal file
View File

@ -0,0 +1,8 @@
package main
import "github.com/gobuffalo/packr/v2"
func run() {
packr.New("static", "./static")
packr.New("templates", "./templates")
}

View File

@ -1,25 +0,0 @@
// +build !skippackr
// Code generated by github.com/gobuffalo/packr/v2. DO NOT EDIT.
// You can use the "packr2 clean" command to clean up this,
// and any other packr generated files.
package packrd
import (
"github.com/gobuffalo/packr/v2"
"github.com/gobuffalo/packr/v2/file/resolver"
)
var _ = func() error {
const gk = "3ce634b1ba2765e987bab67da01981e4"
g := packr.New(gk, "")
hgr, err := resolver.NewHexGzip(map[string]string{
})
if err != nil {
panic(err)
}
g.DefaultResolver = hgr
return nil
}()

View File

@ -4,15 +4,13 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"net/http"
"strings"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/likexian/whois-go" "github.com/likexian/whois-go"
whoisparser "github.com/likexian/whois-parser-go" whoisparser "github.com/likexian/whois-parser-go"
) )
// GetIPInfo returns IP address informations // GetIPInfo returns IP address mail informations
func (ip *IP) GetIPInfo(c echo.Context) (err error) { func (ip *IP) GetIPInfo(c echo.Context) (err error) {
if c.QueryParam("ip") != "" { if c.QueryParam("ip") != "" {
ip.IP = c.QueryParam("ip") ip.IP = c.QueryParam("ip")
@ -30,6 +28,11 @@ func (ip *IP) GetIPInfo(c echo.Context) (err error) {
log.Println(err) log.Println(err)
} }
/*err = ip.GetWhois()
if err != nil {
log.Println(err)
}*/
return return
} }
@ -65,20 +68,7 @@ func (ip *IP) GetWhois() (err error) {
return return
} }
// Dip returns webpage // IP defines ip main struct
func Dip(c echo.Context) (err error) {
var ip IP
ip.GetIPInfo(c)
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
return c.Render(http.StatusOK, "index.html", ip)
} else {
return c.JSON(http.StatusOK, ip)
}
}
// IP defines dip main struct
type IP struct { type IP struct {
IP string `json:"ip"` IP string `json:"ip"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`

31
src/page/main.go Normal file
View File

@ -0,0 +1,31 @@
package page
import (
"net/http"
"strings"
"git.paulbsd.com/paulbsd/dip/src/ip"
"git.paulbsd.com/paulbsd/dip/src/templates"
"github.com/labstack/echo/v4"
)
// Index returns main webpage
func (p *Page) Index(c echo.Context) (err error) {
var ip ip.IP
ip.GetIPInfo(c)
p.IP = &ip
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
return c.Render(http.StatusOK, "index.html", p)
}
return c.JSON(http.StatusOK, ip)
}
// Page defines Web page
type Page struct {
Title string
Templates *templates.Template
IP *ip.IP
}

View File

@ -1,19 +1,18 @@
package templates package templates
import ( import (
"fmt"
"html/template" "html/template"
"io" "io"
"io/ioutil"
"os"
"strings" "strings"
"github.com/gobuffalo/packr/v2" "github.com/gobuffalo/packr/v2"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/markbates/pkger"
) )
// Template is a template struct
type Template struct {
templates *template.Template
}
// Render is a method that render templates // Render is a method that render templates
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) (err error) { func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) (err error) {
if strings.HasSuffix(name, ".html") { if strings.HasSuffix(name, ".html") {
@ -37,3 +36,30 @@ func BuildTemplates(box *packr.Box) (builttemplates *Template, err error) {
return builttemplate, nil return builttemplate, nil
} }
// BuildTemplatesDir converts packr packages to html/template
func BuildTemplatesDir(dir string) (builttemplates *Template, err error) {
tmpl := template.New("templates")
err = pkger.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
freader, _ := pkger.Open(path)
tmplContent, err := ioutil.ReadAll(freader)
tmpl.New(info.Name()).Parse(string(tmplContent))
fmt.Println(info.Name(), tmplContent)
return err
})
builttemplate := &Template{
templates: tmpl,
}
return builttemplate, nil
}
// Template is a template struct
type Template struct {
templates *template.Template
}

View File

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

View File

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

10
utils/flags.go Normal file
View File

@ -0,0 +1,10 @@
package utils
import "flag"
func Flags(host *string, port *string) {
flag.Usage = Usage
flag.StringVar(host, "host", "[::]", "Listen host")
flag.StringVar(port, "port", "8080", "Listen port")
flag.Parse()
}

12
utils/usage.go Normal file
View File

@ -0,0 +1,12 @@
package utils
import (
"flag"
"os"
)
// Usage displays possible arguments
func Usage() {
flag.PrintDefaults()
os.Exit(1)
}

28
vendor/github.com/gobuffalo/here/.gitignore generated vendored Normal file
View File

@ -0,0 +1,28 @@
*.log
.DS_Store
doc
tmp
pkg
*.pid
coverage
coverage.data
build/*
*.pbxuser
*.mode1v3
.svn
profile
.console_history
.sass-cache/*
solr/
.jhw-cache/
jhw.*
*.sublime*
node_modules/
dist/
generated/
.vendor/
bin/*
gin-bin
.idea/
.vscode
cover.out

45
vendor/github.com/gobuffalo/here/.goreleaser.yml generated vendored Normal file
View File

@ -0,0 +1,45 @@
builds:
-
main: ./cmd/here/main.go
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X "github.com/gobuffalo/here.Version={{.Tag}}"
goos:
- darwin
- linux
- windows
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 6
- 7
archives:
-
replacements:
'386': i386
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: checksums.txt
snapshot:
name_template: '{{ .Tag }}-next'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
brews:
-
name: 'here'
github:
owner: 'gobuffalo'
name: 'homebrew-tap'
install: |
bin.install "here"

21
vendor/github.com/gobuffalo/here/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.

50
vendor/github.com/gobuffalo/here/Makefile generated vendored Normal file
View File

@ -0,0 +1,50 @@
TAGS ?= ""
GO_BIN ?= "go"
install: tidy
cd ./cmd/here && $(GO_BIN) install -tags ${TAGS} -v .
make tidy
tidy:
$(GO_BIN) mod tidy -v
build: tidy
$(GO_BIN) build -v .
make tidy
test: tidy
$(GO_BIN) test -count 1 -cover -tags ${TAGS} -timeout 10s ./...
make tidy
cov:
$(GO_BIN) test -coverprofile cover.out -count 1 -tags ${TAGS} ./...
go tool cover -html cover.out
make tidy
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:
rm go.*
$(GO_BIN) mod init
$(GO_BIN) mod tidy
make test
make install
make tidy
release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy
release:
make tidy
release -y -f version.go --skip-packr
make tidy

277
vendor/github.com/gobuffalo/here/README.md generated vendored Normal file
View File

@ -0,0 +1,277 @@
# Here
[![](https://github.com/gobuffalo/here/workflows/Tests/badge.svg)](https://github.com/gobuffalo/here/actions)
[![GoDoc](https://godoc.org/github.com/gobuffalo/here?status.svg)](https://godoc.org/github.com/gobuffalo/here)
Here will get you **accurate** Go information about the directory of package requested.
### Requirements
* Go 1.13+
* Go Modules
## CLI
While you can use the tool via its API, you can also use the CLI to get a JSON version of the data.
### Installation
```bash
$ go get github.com/gobuffalo/here/cmd/here
```
### Usage
#### Default
```bash
$ here
{
"Dir": "$GOPATH/src/github.com/gobuffalo/here",
"ImportPath": "github.com/gobuffalo/here",
"Name": "here",
"Doc": "",
"Target": "$GOPATH/pkg/darwin_amd64/github.com/gobuffalo/here.a",
"Root": "$GOPATH",
"Match": [
"."
],
"Stale": true,
"StaleReason": "not installed but available in build cache",
"GoFiles": [
"current.go",
"dir.go",
"here.go",
"info.go",
"info_map.go",
"module.go",
"pkg.go",
"version.go"
],
"Imports": [
"bytes",
"encoding/json",
"fmt",
"os",
"os/exec",
"path/filepath",
"regexp",
"sync"
],
"Deps": [
"bytes",
"context",
"encoding",
"encoding/base64",
"encoding/binary",
"encoding/json",
"errors",
"fmt",
"internal/bytealg",
"internal/cpu",
"internal/fmtsort",
"internal/oserror",
"internal/poll",
"internal/race",
"internal/reflectlite",
"internal/syscall/unix",
"internal/testlog",
"io",
"math",
"math/bits",
"os",
"os/exec",
"path/filepath",
"reflect",
"regexp",
"regexp/syntax",
"runtime",
"runtime/internal/atomic",
"runtime/internal/math",
"runtime/internal/sys",
"sort",
"strconv",
"strings",
"sync",
"sync/atomic",
"syscall",
"time",
"unicode",
"unicode/utf16",
"unicode/utf8",
"unsafe"
],
"TestGoFiles": [
"current_test.go",
"dir_test.go",
"here_test.go",
"info_test.go",
"module_test.go",
"pkg_test.go"
],
"TestImports": [
"github.com/stretchr/testify/require",
"os",
"path/filepath",
"testing"
],
"Module": {
"Path": "github.com/gobuffalo/here",
"Main": true,
"Dir": "$GOPATH/src/github.com/gobuffalo/here",
"GoMod": "$GOPATH/src/github.com/gobuffalo/here/go.mod",
"GoVersion": "1.13"
}
}
```
#### By Directory
```bash
$ here cmd/here
{
"Dir": "$GOPATH/src/github.com/gobuffalo/here/cmd/here",
"ImportPath": "github.com/gobuffalo/here/cmd/here",
"Name": "main",
"Doc": "",
"Target": "$GOPATH/bin/here",
"Root": "$GOPATH",
"Match": [
"."
],
"Stale": false,
"StaleReason": "",
"GoFiles": [
"main.go"
],
"Imports": [
"fmt",
"github.com/gobuffalo/here",
"log",
"os",
"os/exec"
],
"Deps": [
"bytes",
"context",
"encoding",
"encoding/base64",
"encoding/binary",
"encoding/json",
"errors",
"fmt",
"github.com/gobuffalo/here",
"internal/bytealg",
"internal/cpu",
"internal/fmtsort",
"internal/oserror",
"internal/poll",
"internal/race",
"internal/reflectlite",
"internal/syscall/unix",
"internal/testlog",
"io",
"log",
"math",
"math/bits",
"os",
"os/exec",
"path/filepath",
"reflect",
"regexp",
"regexp/syntax",
"runtime",
"runtime/internal/atomic",
"runtime/internal/math",
"runtime/internal/sys",
"sort",
"strconv",
"strings",
"sync",
"sync/atomic",
"syscall",
"time",
"unicode",
"unicode/utf16",
"unicode/utf8",
"unsafe"
],
"TestGoFiles": null,
"TestImports": null,
"Module": {
"Path": "github.com/gobuffalo/here",
"Main": true,
"Dir": "$GOPATH/src/github.com/gobuffalo/here",
"GoMod": "$GOPATH/src/github.com/gobuffalo/here/go.mod",
"GoVersion": "1.13"
}
}
```
#### By Package
```bash
$ here pkg github.com/gobuffalo/genny
{
"Dir": "$GOPATH/pkg/mod/github.com/gobuffalo/genny@v0.4.1",
"ImportPath": "github.com/gobuffalo/genny",
"Name": "genny",
"Doc": "Package genny is a _framework_ for writing modular generators, it however, doesn't actually generate anything.",
"Target": "",
"Root": "$GOPATH/pkg/mod/github.com/gobuffalo/genny@v0.4.1",
"Match": [
"github.com/gobuffalo/genny"
],
"Stale": true,
"StaleReason": "build ID mismatch",
"GoFiles": [
"confirm.go",
"dir.go",
"disk.go",
"dry_runner.go",
"events.go",
"file.go",
"force.go",
"generator.go",
"genny.go",
"group.go",
"helpers.go",
"logger.go",
"replacer.go",
"results.go",
"runner.go",
"step.go",
"transformer.go",
"version.go",
"wet_runner.go"
],
"Imports": null,
"Deps": null,
"TestGoFiles": [
"dry_runner_test.go",
"file_test.go",
"force_test.go",
"generator_test.go",
"genny_test.go",
"group_test.go",
"helpers_test.go",
"replacer_test.go",
"results_test.go",
"runner_test.go",
"step_test.go",
"transformer_test.go",
"wet_runner_test.go"
],
"TestImports": null,
"Module": {
"Path": "github.com/gobuffalo/genny",
"Main": false,
"Dir": "$GOPATH/pkg/mod/github.com/gobuffalo/genny@v0.4.1",
"GoMod": "$GOPATH/pkg/mod/cache/download/github.com/gobuffalo/genny/@v/v0.4.1.mod",
"GoVersion": "1.13"
}
}
```

24
vendor/github.com/gobuffalo/here/SHOULDERS.md generated vendored Normal file
View File

@ -0,0 +1,24 @@
# github.com/gobuffalo/here Stands on the Shoulders of Giants
github.com/gobuffalo/here 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/davecgh/go-spew](https://godoc.org/github.com/davecgh/go-spew)
* [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/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/yaml.v2](https://godoc.org/gopkg.in/yaml.v2)

31
vendor/github.com/gobuffalo/here/current.go generated vendored Normal file
View File

@ -0,0 +1,31 @@
package here
import (
"path/filepath"
)
// Current returns the Info representing the current Go module
func (h Here) Current() (Info, error) {
hp := &h
(&hp.curOnce).Do(func() {
b, err := run("go", "env", "GOMOD")
if err != nil {
hp.curErr = err
return
}
root := filepath.Dir(string(b))
i, err := h.Dir(root)
if err != nil {
hp.curErr = err
return
}
hp.current = i
})
return h.current, h.curErr
}
// Current returns the Info representing the current Go module
func Current() (Info, error) {
return New().Current()
}

83
vendor/github.com/gobuffalo/here/dir.go generated vendored Normal file
View File

@ -0,0 +1,83 @@
package here
import (
"encoding/json"
"os"
"path/filepath"
)
// Dir attempts to gather info for the requested directory.
func (h Here) Dir(p string) (Info, error) {
i, err := h.cache(p, func(p string) (Info, error) {
var i Info
fi, err := os.Stat(p)
if err != nil {
return i, err
}
if !fi.IsDir() {
p = filepath.Dir(p)
}
pwd, err := os.Getwd()
if err != nil {
return i, err
}
defer os.Chdir(pwd)
os.Chdir(p)
b, err := run("go", "list", "-json")
// go: cannot find main module; see 'go help modules'
// build .: cannot find module for path .
// no Go files in
if err != nil {
if nonGoDirRx.MatchString(err.Error()) {
return fromNonGoDir(p)
}
return i, err
}
if err := json.Unmarshal(b, &i); err != nil {
return i, err
}
return i, nil
})
if err != nil {
return i, err
}
return h.cache(i.ImportPath, func(p string) (Info, error) {
return i, nil
})
}
// Dir attempts to gather info for the requested directory.
func Dir(p string) (Info, error) {
return New().Dir(p)
}
func fromNonGoDir(dir string) (Info, error) {
i := Info{
Dir: dir,
Name: filepath.Base(dir),
}
b, err := run("go", "list", "-json", "-m")
if err != nil {
if nonGoDirRx.MatchString(err.Error()) {
return i, nil
}
return i, err
}
if err := json.Unmarshal(b, &i.Module); err != nil {
return i, err
}
return i, err
}

11
vendor/github.com/gobuffalo/here/go.mod generated vendored Normal file
View File

@ -0,0 +1,11 @@
module github.com/gobuffalo/here
go 1.13
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/stretchr/testify v1.4.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
)

19
vendor/github.com/gobuffalo/here/go.sum generated vendored Normal file
View File

@ -0,0 +1,19 @@
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/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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
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/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=

57
vendor/github.com/gobuffalo/here/here.go generated vendored Normal file
View File

@ -0,0 +1,57 @@
package here
import (
"bytes"
"fmt"
"os/exec"
"regexp"
"sync"
)
type Here struct {
infos *infoMap
curOnce sync.Once
curErr error
current Info
}
// New returns a Here type that will cache
// all results. This speeds up repeated calls,
// and can be useful for testing.
func New() Here {
return Here{
infos: &infoMap{
data: &sync.Map{},
},
}
}
func run(n string, args ...string) ([]byte, error) {
c := exec.Command(n, args...)
bb := &bytes.Buffer{}
ebb := &bytes.Buffer{}
c.Stdout = bb
c.Stderr = ebb
err := c.Run()
if err != nil {
return nil, fmt.Errorf("%s: %s", err, ebb)
}
return bb.Bytes(), nil
}
func (h Here) cache(p string, fn func(string) (Info, error)) (Info, error) {
i, ok := h.infos.Load(p)
if ok {
return i, nil
}
i, err := fn(p)
if err != nil {
return i, err
}
h.infos.Store(p, i)
return i, nil
}
var nonGoDirRx = regexp.MustCompile(`cannot find main|go help modules|go: |build .:|no Go files|can't load package|not using modules`)

39
vendor/github.com/gobuffalo/here/info.go generated vendored Normal file
View File

@ -0,0 +1,39 @@
package here
import (
"encoding/json"
)
// Info represents details about the directory/package
type Info struct {
Dir string
ImportPath string
Name string
Doc string
Target string
Root string
Match []string
Stale bool
StaleReason string
GoFiles []string
Imports []string
Deps []string
TestGoFiles []string
TestImports []string
Module Module
}
// IsZero checks if the type has been filled
// with rich chocolately data goodness
func (i Info) IsZero() bool {
return i.String() == Info{}.String()
}
func (i Info) String() string {
b, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err.Error()
}
s := string(b)
return s
}

32
vendor/github.com/gobuffalo/here/info_map.go generated vendored Normal file
View File

@ -0,0 +1,32 @@
// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT.
package here
import (
"sync"
)
// infoMap wraps sync.Map and uses the following types:
// key: string
// value: Info
type infoMap struct {
data *sync.Map
}
// Load the key from the map.
// Returns Info or bool.
// A false return indicates either the key was not found
// or the value is not of type Info
func (m *infoMap) Load(key string) (Info, bool) {
i, ok := m.data.Load(key)
if !ok {
return Info{}, false
}
s, ok := i.(Info)
return s, ok
}
// Store a Info in the map
func (m *infoMap) Store(key string, value Info) {
m.data.Store(key, value)
}

29
vendor/github.com/gobuffalo/here/module.go generated vendored Normal file
View File

@ -0,0 +1,29 @@
package here
import (
"encoding/json"
)
type Module struct {
Path string
Main bool
Dir string
GoMod string
GoVersion string
}
func (i Module) String() string {
b, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err.Error()
}
return string(b)
}
func (i Module) IsZero() bool {
const cla = "command-line-arguments"
if i.Path == cla {
i.Path = ""
}
return i.String() == Module{}.String()
}

63
vendor/github.com/gobuffalo/here/parse.go generated vendored Normal file
View File

@ -0,0 +1,63 @@
package here
import (
"fmt"
"path/filepath"
"regexp"
"strings"
)
func (i Info) Parse(p string) (Path, error) {
p = strings.TrimSpace(p)
p = filepath.Clean(p)
p = strings.TrimPrefix(p, i.Dir)
p = strings.Replace(p, "\\", "/", -1)
p = strings.TrimSpace(p)
if len(p) == 0 || p == ":" || p == "." {
return i.build("", "", "")
}
res := pathrx.FindAllStringSubmatch(p, -1)
if len(res) == 0 {
return Path{}, fmt.Errorf("could not parse %q", p)
}
matches := res[0]
if len(matches) != 4 {
return Path{}, fmt.Errorf("could not parse %q", p)
}
return i.build(p, matches[1], matches[3])
}
func (i Info) build(p, pkg, name string) (Path, error) {
pt := Path{
Pkg: pkg,
Name: name,
}
if strings.HasPrefix(pt.Pkg, "/") || len(pt.Pkg) == 0 {
pt.Name = pt.Pkg
pt.Pkg = i.Module.Path
}
if len(pt.Name) == 0 {
pt.Name = "/"
}
if pt.Pkg == pt.Name {
pt.Pkg = i.Module.Path
pt.Name = "/"
}
if !strings.HasPrefix(pt.Name, "/") {
pt.Name = "/" + pt.Name
}
pt.Name = strings.TrimPrefix(pt.Name, i.Dir)
return pt, nil
}
var pathrx = regexp.MustCompile("([^:]+)(:(/.+))?")

20
vendor/github.com/gobuffalo/here/path.go generated vendored Normal file
View File

@ -0,0 +1,20 @@
package here
import (
"fmt"
)
type Path struct {
Pkg string
Name string
}
func (p Path) String() string {
if p.Name == "" {
p.Name = "/"
}
if p.Pkg == "" {
return p.Name
}
return fmt.Sprintf("%s:%s", p.Pkg, p.Name)
}

57
vendor/github.com/gobuffalo/here/pkg.go generated vendored Normal file
View File

@ -0,0 +1,57 @@
package here
import (
"encoding/json"
"fmt"
)
// Package attempts to gather info for the requested package.
//
// From the `go help list` docs:
// The -find flag causes list to identify the named packages but not
// resolve their dependencies: the Imports and Deps lists will be empty.
//
// A workaround for this issue is to use the `Dir` field in the
// returned `Info` value and pass it to the `Dir(string) (Info, error)`
// function to return the complete data.
func (h Here) Package(p string) (Info, error) {
i, err := h.cache(p, func(p string) (Info, error) {
var i Info
if len(p) == 0 || p == "." {
return i, fmt.Errorf("missing package name")
}
b, err := run("go", "list", "-json", "-find", p)
if err != nil {
return i, err
}
if err := json.Unmarshal(b, &i); err != nil {
return i, err
}
return i, nil
})
if err != nil {
return i, err
}
h.cache(i.Dir, func(p string) (Info, error) {
return i, nil
})
return i, nil
}
// Package attempts to gather info for the requested package.
//
// From the `go help list` docs:
// The -find flag causes list to identify the named packages but not
// resolve their dependencies: the Imports and Deps lists will be empty.
//
// A workaround for this issue is to use the `Dir` field in the
// returned `Info` value and pass it to the `Dir(string) (Info, error)`
// function to return the complete data.
func Package(p string) (Info, error) {
return New().Package(p)
}

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

@ -0,0 +1,4 @@
package here
// Version of here
var Version = "development"

35
vendor/github.com/markbates/pkger/.gitignore generated vendored Normal file
View File

@ -0,0 +1,35 @@
.fstest
*.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/
pkged.go
cover.out
.pkgtest
example
app

45
vendor/github.com/markbates/pkger/.goreleaser.yml generated vendored Normal file
View File

@ -0,0 +1,45 @@
builds:
-
main: ./cmd/pkger/main.go
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X "github.com/markbates/pkger.Version={{.Tag}}"
goos:
- darwin
- linux
- windows
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 6
- 7
archives:
-
replacements:
'386': i386
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: checksums.txt
snapshot:
name_template: '{{ .Tag }}-next'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
brews:
-
name: 'pkger'
github:
owner: 'markbates'
name: 'homebrew-tap'
install: |
bin.install "pkger"

21
vendor/github.com/markbates/pkger/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.

54
vendor/github.com/markbates/pkger/Makefile generated vendored Normal file
View File

@ -0,0 +1,54 @@
TAGS ?= ""
GO_BIN ?= "go"
install: tidy
cd ./cmd/pkger && $(GO_BIN) install -tags ${TAGS} -v .
make tidy
run: install
cd ./examples/app; pkger
tidy:
$(GO_BIN) mod tidy -v
build: tidy
$(GO_BIN) build -v .
make tidy
test: tidy
$(GO_BIN) test -count 1 -cover -tags ${TAGS} -timeout 1m ./...
make tidy
cov:
$(GO_BIN) test -coverprofile cover.out -tags ${TAGS} ./...
go tool cover -html cover.out
make tidy
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:
rm go.*
$(GO_BIN) mod init
$(GO_BIN) mod tidy
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

431
vendor/github.com/markbates/pkger/README.md generated vendored Normal file
View File

@ -0,0 +1,431 @@
# Pkger
[`github.com/markbates/pkger`](https://godoc.org/github.com/markbates/pkger) is a tool for embedding static files into Go binaries. It will, hopefully, be a replacement for [`github.com/gobuffalo/packr/v2`](https://godoc.org/github.com/gobuffalo/packr/v2).
### Requirements
* Go 1.13+
* Go Modules
## How it Works (Module Aware Pathing)
Pkger is powered by the dark magic of Go Modules, so they're like, totally required.
With Go Modules pkger can resolve packages with accuracy. No more guessing and trying to
figure out build paths, GOPATHS, etc... for this tired old lad.
With the module's path correctly resolved, it can serve as the "root" directory for that
module, and all files in that module's directory are available.
Paths:
* Paths should use UNIX style paths:
`/cmd/pkger/main.go`
* If unspecified the path's package is assumed to be the current module.
* Packages can specified in at the beginning of a path with a `:` seperator.
github.com/markbates/pkger:/cmd/pkger/main.go
* There are no relative paths. All paths are absolute to the modules root.
```
"github.com/gobuffalo/buffalo:/go.mod" => $GOPATH/pkg/mod/github.com/gobuffalo/buffalo@v0.14.7/go.mod
```
## CLI
### Installation
```bash
$ go get github.com/markbates/pkger/cmd/pkger
$ pkger -h
```
### Usage
```bash
$ pkger
```
The result will be a `pkged.go` file in the **root** of the module with the embedded information and the package name of the module.
```go
// ./pkged.go
package <.>
// Pkger stuff here
```
The `-o` flag can be used specify the directory of the `pkged.go` file.
```bash
$ pkger -o cmd/reader
```
The result will be a `pkged.go` file in the **cmd/reader** folder with the embedded information and the package name of that folder.
```go
// cmd/reader/pkged.go
package <reader>
// Pkger stuff here
```
### Including Files at Package Time
There may be reasons where you don't reference a particular file, or folder, that you want embedded in your application, such as a build artifact.
To do this you may use either the [`github.com/markbates/pkger#Include`](https://godoc.org/github.com/markbates/pkger#Include) function to set a no-op parser directive to include the specified path.
Alternatively, you may use the `-include` flag with the `pkger` and `pkger list` commands.
```bash
$ pkger list -include /actions -include github.com/gobuffalo/buffalo:/app.go
app
> app:/actions
> app:/actions/actions.go
> app:/assets
> app:/assets/css
> app:/assets/css/_buffalo.scss
> app:/assets/css/application.scss
> app:/assets/images
> app:/assets/images/favicon.ico
> app:/assets/images/logo.svg
> app:/assets/js
> app:/assets/js/application.js
> app:/go.mod
> app:/locales/all.en-us.yaml
> app:/public
> app:/public/assets
> app:/public/assets/.keep
> app:/public/assets/app.css
> app:/public/images
> app:/public/images/img1.png
> app:/public/index.html
> app:/public/robots.txt
> app:/templates
> app:/templates/_flash.plush.html
> app:/templates/application.plush.html
> app:/templates/index.plush.html
> app:/web
> app:/web/web.go
> github.com/gobuffalo/buffalo:/app.go
> github.com/gobuffalo/buffalo:/logo.svg
```
## Reference Application
The reference application for the `README` examples, as well as all testing, can be found at [https://github.com/markbates/pkger/tree/master/pkging/pkgtest/testdata/ref](https://github.com/markbates/pkger/tree/master/pkging/pkgtest/testdata/ref).
```
├── actions
│   └── actions.go
├── assets
│   ├── css
│   │   ├── _buffalo.scss
│   │   └── application.scss
│   ├── images
│   │   ├── favicon.ico
│   │   └── logo.svg
│   └── js
│   └── application.js
├── go.mod
├── go.sum
├── locales
│   └── all.en-us.yaml
├── main.go
├── mod
│   └── mod.go
├── models
│   └── models.go
├── public
│   ├── assets
│   │   └── app.css
│   ├── images
│   │   └── img1.png
│   ├── index.html
│   └── robots.txt
├── templates
│   ├── _flash.plush.html
│   ├── application.plush.html
│   └── index.plush.html
└── web
└── web.go
13 directories, 20 files
```
## API Usage
Pkger's API is modeled on that of the [`os`](https://godoc.org/os) package in Go's standard library. This makes Pkger usage familiar to Go developers.
The two most important interfaces are [`github.com/markbates/pkger/pkging#Pkger`](https://godoc.org/github.com/markbates/pkger/pkging#Pkger) and [`github.com/markbates/pkger/pkging#File`](https://godoc.org/github.com/markbates/pkger/pkging#File).
```go
type Pkger interface {
Parse(p string) (Path, error)
Current() (here.Info, error)
Info(p string) (here.Info, error)
Create(name string) (File, error)
MkdirAll(p string, perm os.FileMode) error
Open(name string) (File, error)
Stat(name string) (os.FileInfo, error)
Walk(p string, wf filepath.WalkFunc) error
Remove(name string) error
RemoveAll(path string) error
}
type File interface {
Close() error
Info() here.Info
Name() string
Open(name string) (http.File, error)
Path() Path
Read(p []byte) (int, error)
Readdir(count int) ([]os.FileInfo, error)
Seek(offset int64, whence int) (int64, error)
Stat() (os.FileInfo, error)
Write(b []byte) (int, error)
}
```
These two interfaces, along with the [`os#FileInfo`](https://godoc.org/os#FileInfo), provide the bulk of the API surface area.
### Open
```go
func run() error {
f, err := pkger.Open("/public/index.html")
if err != nil {
return err
}
defer f.Close()
info, err := f.Stat()
if err != nil {
return err
}
fmt.Println("Name: ", info.Name())
fmt.Println("Size: ", info.Size())
fmt.Println("Mode: ", info.Mode())
fmt.Println("ModTime: ", info.ModTime())
if _, err := io.Copy(os.Stdout, f); err != nil {
return err
}
return nil
}
```
### Stat
```go
func run() error {
info, err := pkger.Stat("/public/index.html")
if err != nil {
return err
}
fmt.Println("Name: ", info.Name())
fmt.Println("Size: ", info.Size())
fmt.Println("Mode: ", info.Mode())
fmt.Println("ModTime: ", info.ModTime())
return nil
}
```
### Walk
```go
func run() error {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 0, ' ', tabwriter.Debug)
defer w.Flush()
return pkger.Walk("/public", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
fmt.Fprintf(w,
"%s \t %d \t %s \t %s \t\n",
info.Name(),
info.Size(),
info.Mode(),
info.ModTime().Format(time.RFC3339),
)
return nil
})
}
```
## Understanding the Parser
The [`github.com/markbates/pkger/parser#Parser`](https://godoc.org/github.com/markbates/pkger/parser#Parser) works by statically analyzing the source code of your module using the [`go/parser`](https://godoc.org/go/parser) to find a selection of declarations.
The following declarations in your source code will tell the parser to embed files or folders.
* `pkger.Dir("<path>")` - Embeds all files under the specified path.
* `pkger.Open("<path>")` - Embeds the file, or folder, of the specified path.
* `pkger.Stat("<path>")` - Embeds the file, or folder, of the specified path.
* `pkger.Walk("<path>", filepath.WalkFunc)` - Embeds all files under the specified path.
* `pkger.Include("<path>")` - `Include` is a no-op that directs the pkger tool to include the desired file or folder.
### CLI Usage
To see what declarations the parser has found, you can use the `pkger parse` command to get a `JSON` list of the declarations.
```bash
$ pkger parse
{
".": [
{
"file": {
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/foo/bar/baz",
"Path": {
"Pkg": "app",
"Name": "/foo/bar/baz"
},
"Here": {
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"ImportPath": "app",
"Module": {
"Path": "app",
"Main": true,
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
"GoVersion": "1.13"
},
"Name": "main"
}
},
"pos": {
"Filename": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/main.go",
"Offset": 629,
"Line": 47,
"Column": 27
},
"type": "pkger.MkdirAll",
"value": "/foo/bar/baz"
},
{
"file": {
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/foo/bar/baz/biz.txt",
"Path": {
"Pkg": "app",
"Name": "/foo/bar/baz/biz.txt"
},
"Here": {
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"ImportPath": "app",
"Module": {
"Path": "app",
"Main": true,
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
"GoVersion": "1.13"
},
"Name": "main"
}
},
"pos": {
"Filename": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/main.go",
"Offset": 706,
"Line": 51,
"Column": 25
},
"type": "pkger.Create",
"value": "/foo/bar/baz/biz.txt"
},
...
]
}
```
For a module aware list use the `pkger list` command.
```bash
$ pkger list
app
> app:/assets
> app:/assets/css
> app:/assets/css/_buffalo.scss
> app:/assets/css/application.scss
> app:/assets/images
> app:/assets/images/favicon.ico
> app:/assets/images/logo.svg
> app:/assets/js
> app:/assets/js/application.js
> app:/go.mod
> app:/locales/all.en-us.yaml
> app:/public
> app:/public/assets
> app:/public/assets/.keep
> app:/public/assets/app.css
> app:/public/images
> app:/public/images/img1.png
> app:/public/index.html
> app:/public/robots.txt
> app:/templates
> app:/templates/_flash.plush.html
> app:/templates/application.plush.html
> app:/templates/index.plush.html
> app:/web
> app:/web/web.go
> github.com/gobuffalo/buffalo:/logo.svg
```
The `-json` flag can be used to get a more detailed list in JSON.
```bash
$ pkger list -json
{
"ImportPath": "app",
"Files": [
{
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
"Path": {
"Pkg": "app",
"Name": "/assets"
},
"Here": {
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
"ImportPath": "",
"Module": {
"Path": "app",
"Main": true,
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
"GoVersion": "1.13"
},
"Name": "assets"
}
},
{
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets/css",
"Path": {
"Pkg": "app",
"Name": "/assets/css"
},
"Here": {
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
"ImportPath": "",
"Module": {
"Path": "app",
"Main": true,
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
"GoVersion": "1.13"
},
"Name": "assets"
}
},
...
}
```

24
vendor/github.com/markbates/pkger/SHOULDERS.md generated vendored Normal file
View File

@ -0,0 +1,24 @@
# github.com/markbates/pkger Stands on the Shoulders of Giants
github.com/markbates/pkger 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/davecgh/go-spew](https://godoc.org/github.com/davecgh/go-spew)
* [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/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/yaml.v2](https://godoc.org/gopkg.in/yaml.v2)

19
vendor/github.com/markbates/pkger/apply.go generated vendored Normal file
View File

@ -0,0 +1,19 @@
package pkger
import (
"github.com/markbates/pkger/pkging"
)
// Apply will wrap the current implementation
// of pkger.Pkger with the new pkg. This allows
// for layering of pkging.Pkger implementations.
func Apply(pkg pkging.Pkger, err error) error {
if err != nil {
panic(err)
return err
}
gil.Lock()
defer gil.Unlock()
current = pkging.Wrap(current, pkg)
return nil
}

8
vendor/github.com/markbates/pkger/go.mod generated vendored Normal file
View File

@ -0,0 +1,8 @@
module github.com/markbates/pkger
go 1.13
require (
github.com/gobuffalo/here v0.6.0
github.com/stretchr/testify v1.4.0
)

22
vendor/github.com/markbates/pkger/go.sum generated vendored Normal file
View File

@ -0,0 +1,22 @@
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/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI=
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
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/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
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/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=

View File

@ -0,0 +1,124 @@
// Code generated by github.com/gobuffalo/mapgen. DO NOT EDIT.
package maps
import (
"encoding/json"
"fmt"
"sort"
"sync"
"github.com/gobuffalo/here"
"github.com/markbates/pkger/pkging"
)
// Files wraps sync.Map and uses the following types:
// key: here.Path
// value: pkging.File
type Files struct {
data *sync.Map
once *sync.Once
}
func (m *Files) Data() *sync.Map {
if m.once == nil {
m.once = &sync.Once{}
}
m.once.Do(func() {
if m.data == nil {
m.data = &sync.Map{}
}
})
return m.data
}
func (m *Files) MarshalJSON() ([]byte, error) {
var err error
mm := map[string]interface{}{}
m.Data().Range(func(key, value interface{}) bool {
var b []byte
b, err = json.Marshal(key)
if err != nil {
return false
}
mm[string(b)] = value
return true
})
if err != nil {
return nil, err
}
return json.Marshal(mm)
}
func (m *Files) UnmarshalJSON(b []byte) error {
mm := map[string]pkging.File{}
if err := json.Unmarshal(b, &mm); err != nil {
return err
}
for k, v := range mm {
var pt here.Path
if err := json.Unmarshal([]byte(k), &pt); err != nil {
return err
}
m.Store(pt, v)
}
return nil
}
// Delete the key from the map
func (m *Files) Delete(key here.Path) {
m.Data().Delete(key)
}
// Load the key from the map.
// Returns pkging.File or bool.
// A false return indicates either the key was not found
// or the value is not of type pkging.File
func (m *Files) Load(key here.Path) (pkging.File, bool) {
i, ok := m.Data().Load(key)
if !ok {
return nil, false
}
s, ok := i.(pkging.File)
return s, ok
}
// Range over the pkging.File values in the map
func (m *Files) Range(f func(key here.Path, value pkging.File) bool) {
m.Data().Range(func(k, v interface{}) bool {
key, ok := k.(here.Path)
if !ok {
return false
}
value, ok := v.(pkging.File)
if !ok {
return false
}
return f(key, value)
})
}
// Store a pkging.File in the map
func (m *Files) Store(key here.Path, value pkging.File) {
m.Data().Store(key, value)
}
// Keys returns a list of keys in the map
func (m *Files) Keys() []here.Path {
var keys []here.Path
m.Range(func(key here.Path, value pkging.File) bool {
keys = append(keys, key)
return true
})
sort.Slice(keys, func(a, b int) bool {
return keys[a].String() <= keys[b].String()
})
return keys
}
func (m *Files) String() string {
return fmt.Sprintf("%v", m.Keys())
}

View File

@ -0,0 +1,103 @@
// Code generated by github.com/markbates/pkger/mapgen. DO NOT EDIT.
package maps
import (
"encoding/json"
"fmt"
"sort"
"sync"
"github.com/gobuffalo/here"
)
// Infos wraps sync.Map and uses the following types:
// key: string
// value: here.Info
type Infos struct {
data *sync.Map
once *sync.Once
}
func (m *Infos) Data() *sync.Map {
if m.once == nil {
m.once = &sync.Once{}
}
m.once.Do(func() {
if m.data == nil {
m.data = &sync.Map{}
}
})
return m.data
}
func (m *Infos) MarshalJSON() ([]byte, error) {
mm := map[string]interface{}{}
m.data.Range(func(key, value interface{}) bool {
mm[fmt.Sprintf("%s", key)] = value
return true
})
return json.Marshal(mm)
}
func (m *Infos) UnmarshalJSON(b []byte) error {
mm := map[string]here.Info{}
if err := json.Unmarshal(b, &mm); err != nil {
return err
}
for k, v := range mm {
m.Store(k, v)
}
return nil
}
// Delete the key from the map
func (m *Infos) Delete(key string) {
m.Data().Delete(key)
}
// Load the key from the map.
// Returns here.Info or bool.
// A false return indicates either the key was not found
// or the value is not of type here.Info
func (m *Infos) Load(key string) (here.Info, bool) {
m.Data()
i, ok := m.data.Load(key)
if !ok {
return here.Info{}, false
}
s, ok := i.(here.Info)
return s, ok
}
// Range over the here.Info values in the map
func (m *Infos) Range(f func(key string, value here.Info) bool) {
m.Data().Range(func(k, v interface{}) bool {
key, ok := k.(string)
if !ok {
return false
}
value, ok := v.(here.Info)
if !ok {
return false
}
return f(key, value)
})
}
// Store a here.Info in the map
func (m *Infos) Store(key string, value here.Info) {
m.Data().Store(key, value)
}
// Keys returns a list of keys in the map
func (m *Infos) Keys() []string {
var keys []string
m.Range(func(key string, value here.Info) bool {
keys = append(keys, key)
return true
})
sort.Strings(keys)
return keys
}

95
vendor/github.com/markbates/pkger/pkger.go generated vendored Normal file
View File

@ -0,0 +1,95 @@
package pkger
import (
"net/http"
"os"
"path/filepath"
"sync"
"github.com/gobuffalo/here"
"github.com/markbates/pkger/pkging"
"github.com/markbates/pkger/pkging/stdos"
)
var current pkging.Pkger
var gil = &sync.RWMutex{}
var disk = func() pkging.Pkger {
her, _ := here.Current()
n, _ := stdos.New(her)
return n
}()
func impl() pkging.Pkger {
gil.RLock()
defer gil.RUnlock()
if current == nil {
return disk
}
return current
}
type Dir string
func (d Dir) Open(name string) (http.File, error) {
f, err := impl().Open(string(d))
if err != nil {
return nil, err
}
return f.Open(name)
}
// Parse the string in here.Path format.
func Parse(p string) (here.Path, error) {
return impl().Parse(p)
}
// Current returns the here.Info representing the current Pkger implementation.
func Current() (here.Info, error) {
return impl().Current()
}
// Info returns the here.Info of the here.Path
func Info(p string) (here.Info, error) {
return impl().Info(p)
}
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
func Create(p string) (pkging.File, error) {
return impl().Create(p)
}
// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func MkdirAll(p string, perm os.FileMode) error {
return impl().MkdirAll(p, perm)
}
// Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
func Open(p string) (pkging.File, error) {
return impl().Open(p)
}
// Stat returns a FileInfo describing the named file.
func Stat(name string) (os.FileInfo, error) {
return impl().Stat(name)
}
// Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links. - That is from the standard library. I know. Their grammar teachers can not be happy with them right now.
func Walk(p string, wf filepath.WalkFunc) error {
return impl().Walk(p, wf)
}
// Remove removes the named file or (empty) directory.
func Remove(name string) error {
return impl().Remove(name)
}
// RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
func RemoveAll(name string) error {
return impl().RemoveAll(name)
}
// Include is a no-op that directs the pkger tool to include the desired file or folder.
func Include(name string) string {
return name
}

7
vendor/github.com/markbates/pkger/pkging/faces.go generated vendored Normal file
View File

@ -0,0 +1,7 @@
package pkging
import "os"
type Adder interface {
Add(files ...*os.File) error
}

44
vendor/github.com/markbates/pkger/pkging/file.go generated vendored Normal file
View File

@ -0,0 +1,44 @@
package pkging
import (
"net/http"
"os"
"github.com/gobuffalo/here"
)
type File interface {
// Close closes the File, rendering it unusable for I/O.
Close() error
// Info returns the here.Info of the file
Info() here.Info
// Name retuns the name of the file
Name() string
// Open implements the http.FileSystem interface. A FileSystem implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.
Open(name string) (http.File, error)
// Path returns the here.Path of the file
Path() here.Path
// Read reads up to len(b) bytes from the File. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF.
Read(p []byte) (int, error)
// Readdir reads the contents of the directory associated with file and returns a slice of up to n FileInfo values, as would be returned by Lstat, in directory order. Subsequent calls on the same file will yield further FileInfos.
//
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.
//
// If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error.
Readdir(count int) ([]os.FileInfo, error)
// Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any.
Seek(offset int64, whence int) (int64, error)
// Stat returns the FileInfo structure describing file. If there is an error, it will be of type *PathError.
Stat() (os.FileInfo, error)
// Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).
Write(b []byte) (int, error)
}

65
vendor/github.com/markbates/pkger/pkging/file_info.go generated vendored Normal file
View File

@ -0,0 +1,65 @@
package pkging
import (
"encoding/json"
"os"
"time"
)
type Details struct {
Name string `json:"name"`
Size int64 `json:"size"`
Mode os.FileMode `json:"mode"`
ModTime ModTime `json:"mod_time"`
IsDir bool `json:"is_dir"`
Sys interface{} `json:"sys"`
}
type FileInfo struct {
Details `json:"details"`
}
func (f *FileInfo) String() string {
b, _ := json.MarshalIndent(f, "", " ")
return string(b)
}
func (f *FileInfo) Name() string {
return f.Details.Name
}
func (f *FileInfo) Size() int64 {
return f.Details.Size
}
func (f *FileInfo) Mode() os.FileMode {
return f.Details.Mode
}
func (f *FileInfo) ModTime() time.Time {
return time.Time(f.Details.ModTime)
}
func (f *FileInfo) IsDir() bool {
return f.Details.IsDir
}
func (f *FileInfo) Sys() interface{} {
return f.Details.Sys
}
var _ os.FileInfo = &FileInfo{}
func NewFileInfo(info os.FileInfo) *FileInfo {
fi := &FileInfo{
Details: Details{
Name: info.Name(),
Size: info.Size(),
Mode: info.Mode(),
ModTime: ModTime(info.ModTime()),
IsDir: info.IsDir(),
Sys: info.Sys(),
},
}
return fi
}

24
vendor/github.com/markbates/pkger/pkging/mod_time.go generated vendored Normal file
View File

@ -0,0 +1,24 @@
package pkging
import (
"encoding/json"
"time"
)
const timeFmt = time.RFC3339Nano
type ModTime time.Time
func (m ModTime) MarshalJSON() ([]byte, error) {
t := time.Time(m)
return json.Marshal(t.Format(timeFmt))
}
func (m *ModTime) UnmarshalJSON(b []byte) error {
t := time.Time{}
if err := json.Unmarshal(b, &t); err != nil {
return err
}
(*m) = ModTime(t)
return nil
}

43
vendor/github.com/markbates/pkger/pkging/pkger.go generated vendored Normal file
View File

@ -0,0 +1,43 @@
package pkging
import (
"os"
"path/filepath"
"github.com/gobuffalo/here"
)
type Pkger interface {
// Parse the string in here.Path format.
Parse(p string) (here.Path, error)
// Current returns the here.Info representing the current Pkger implementation.
Current() (here.Info, error)
// Info returns the here.Info of the here.Path
Info(p string) (here.Info, error)
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
Create(name string) (File, error)
// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
MkdirAll(p string, perm os.FileMode) error
// Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
// @Parser Directive
Open(name string) (File, error)
// Stat returns a FileInfo describing the named file.
// @Parser Directive
Stat(name string) (os.FileInfo, error)
// Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links. - That is from the standard library. I know. Their grammar teachers can not be happy with them right now.
// @Parser Directive
Walk(p string, wf filepath.WalkFunc) error
// Remove removes the named file or (empty) directory.
Remove(name string) error
// RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
RemoveAll(path string) error
}

73
vendor/github.com/markbates/pkger/pkging/stdos/file.go generated vendored Normal file
View File

@ -0,0 +1,73 @@
package stdos
import (
"net/http"
"os"
"path"
"github.com/gobuffalo/here"
"github.com/markbates/pkger/pkging"
)
var _ pkging.File = &File{}
type File struct {
*os.File
info *pkging.FileInfo
her here.Info
path here.Path
pkging pkging.Pkger
}
// Close closes the File, rendering it unusable for I/O.
func (f *File) Close() error {
return f.File.Close()
}
// Info returns the here.Info of the file
func (f *File) Info() here.Info {
return f.her
}
// Name retuns the name of the file in pkger format
func (f File) Name() string {
return f.path.String()
}
// Readdir reads the contents of the directory associated with file and returns a slice of up to n FileInfo values, as would be returned by Lstat, in directory order. Subsequent calls on the same file will yield further FileInfos.
//
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.
//
// If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error.
func (f *File) Readdir(count int) ([]os.FileInfo, error) {
return f.File.Readdir(count)
}
// Open implements the http.FileSystem interface. A FileSystem implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.
func (f *File) Open(name string) (http.File, error) {
fp := path.Join(f.Path().Name, name)
f2, err := f.pkging.Open(fp)
if err != nil {
return nil, err
}
return f2, nil
}
// Path returns the here.Path of the file
func (f *File) Path() here.Path {
return f.path
}
// Stat returns the FileInfo structure describing file. If there is an error, it will be of type *PathError.
func (f *File) Stat() (os.FileInfo, error) {
if f.info != nil {
return f.info, nil
}
info, err := f.File.Stat()
if err != nil {
return nil, err
}
f.info = pkging.NewFileInfo(info)
return f.info, nil
}

View File

@ -0,0 +1 @@
package stdos

223
vendor/github.com/markbates/pkger/pkging/stdos/stdos.go generated vendored Normal file
View File

@ -0,0 +1,223 @@
package stdos
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/gobuffalo/here"
"github.com/markbates/pkger/internal/maps"
"github.com/markbates/pkger/pkging"
)
var _ pkging.Pkger = &Pkger{}
type Pkger struct {
Here here.Info
infos *maps.Infos
}
// New returns *Pkger for the provided here.Info
func New(her here.Info) (*Pkger, error) {
p := &Pkger{
infos: &maps.Infos{},
Here: her,
}
p.infos.Store(her.ImportPath, her)
return p, nil
}
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
func (fx *Pkger) Create(name string) (pkging.File, error) {
pt, err := fx.Parse(name)
if err != nil {
return nil, err
}
her, err := fx.Info(pt.Pkg)
if err != nil {
return nil, err
}
name = filepath.Join(her.Dir, pt.Name)
f, err := os.Create(name)
if err != nil {
return nil, err
}
nf := &File{
File: f,
her: her,
path: pt,
pkging: fx,
}
info, err := f.Stat()
if err != nil {
return nil, err
}
nf.info = pkging.NewFileInfo(info)
return nf, nil
}
// Current returns the here.Info representing the current Pkger implementation.
func (f *Pkger) Current() (here.Info, error) {
return f.Here, nil
}
// Info returns the here.Info of the here.Path
func (f *Pkger) Info(p string) (here.Info, error) {
info, ok := f.infos.Load(p)
if ok {
return info, nil
}
info, err := here.Package(p)
if err != nil {
return info, err
}
f.infos.Store(p, info)
return info, nil
}
// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func (f *Pkger) MkdirAll(p string, perm os.FileMode) error {
pt, err := f.Parse(p)
if err != nil {
return err
}
info, err := f.Info(pt.Pkg)
if err != nil {
return err
}
return os.MkdirAll(filepath.Join(info.Dir, p), perm)
}
// Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
func (fx *Pkger) Open(name string) (pkging.File, error) {
pt, err := fx.Parse(name)
if err != nil {
return nil, err
}
her, err := fx.Info(pt.Pkg)
if err != nil {
return nil, err
}
name = filepath.Join(her.Dir, pt.Name)
f, err := os.Open(name)
if err != nil {
return nil, err
}
nf := &File{
File: f,
her: her,
path: pt,
pkging: fx,
}
info, err := f.Stat()
if err != nil {
return nil, err
}
nf.info = pkging.NewFileInfo(info)
return nf, nil
}
// Parse the string in here.Path format.
func (f *Pkger) Parse(p string) (here.Path, error) {
return f.Here.Parse(p)
}
// Stat returns a FileInfo describing the named file.
func (fx *Pkger) Stat(name string) (os.FileInfo, error) {
pt, err := fx.Parse(name)
if err != nil {
return nil, err
}
her, err := fx.Info(pt.Pkg)
if err != nil {
return nil, err
}
info, err := os.Stat(filepath.Join(her.Dir, pt.Name))
if err != nil {
return nil, err
}
info = pkging.NewFileInfo(info)
return info, nil
}
// Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links. - That is from the standard library. I know. Their grammar teachers can not be happy with them right now.
func (f *Pkger) Walk(p string, wf filepath.WalkFunc) error {
pt, err := f.Parse(p)
if err != nil {
return err
}
info, err := f.Info(pt.Pkg)
if err != nil {
return err
}
fp := filepath.Join(info.Dir, pt.Name)
err = filepath.Walk(fp, func(path string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
pt, err := f.Parse(fmt.Sprintf("%s:%s", pt.Pkg, path))
if err != nil {
return err
}
info, err := f.Info(pt.Pkg)
if err != nil {
return err
}
path = strings.TrimPrefix(path, info.Dir)
path = strings.ReplaceAll(path, "\\", "/")
pt.Name = path
return wf(pt.String(), pkging.NewFileInfo(fi), nil)
})
return err
}
// Remove removes the named file or (empty) directory.
func (fx *Pkger) Remove(name string) error {
pt, err := fx.Parse(name)
if err != nil {
return err
}
info, err := fx.Info(pt.Pkg)
if err != nil {
return err
}
return os.Remove(filepath.Join(info.Dir, pt.Name))
}
// RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
func (fx *Pkger) RemoveAll(name string) error {
pt, err := fx.Parse(name)
if err != nil {
return err
}
info, err := fx.Info(pt.Pkg)
if err != nil {
return err
}
return os.RemoveAll(filepath.Join(info.Dir, pt.Name))
}

145
vendor/github.com/markbates/pkger/pkging/wrap.go generated vendored Normal file
View File

@ -0,0 +1,145 @@
package pkging
import (
"fmt"
"os"
"path/filepath"
"github.com/gobuffalo/here"
)
func Wrap(parent, with Pkger) Pkger {
return withPkger{
base: with,
parent: parent,
}
}
type withPkger struct {
base Pkger
parent Pkger
}
func (w withPkger) String() string {
if w.parent == nil {
return fmt.Sprintf("%T", w.base)
}
return fmt.Sprintf("%T > %T", w.base, w.parent)
}
func (w withPkger) Parse(p string) (here.Path, error) {
pt, err := w.base.Parse(p)
if err != nil {
if w.parent != nil {
return w.parent.Parse(p)
}
return pt, err
}
return pt, nil
}
func (w withPkger) Current() (here.Info, error) {
pt, err := w.base.Current()
if err != nil {
if w.parent != nil {
return w.parent.Current()
}
return pt, err
}
return pt, nil
}
func (w withPkger) Info(p string) (here.Info, error) {
pt, err := w.base.Info(p)
if err != nil {
if w.parent != nil {
return w.parent.Info(p)
}
return pt, err
}
return pt, nil
}
// Create creates the named file with mode 0666 (before umask) - It's actually 0644, truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR.
func (w withPkger) Create(p string) (File, error) {
pt, err := w.base.Create(p)
if err != nil {
if w.parent != nil {
return w.parent.Create(p)
}
return pt, err
}
return pt, nil
}
// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func (w withPkger) MkdirAll(p string, perm os.FileMode) error {
err := w.base.MkdirAll(p, perm)
if err != nil {
return err
}
if w.parent != nil {
return w.parent.MkdirAll(p, perm)
}
return nil
}
// Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
func (w withPkger) Open(p string) (File, error) {
pt, err := w.base.Open(p)
if err != nil {
if w.parent != nil {
return w.parent.Open(p)
}
return pt, err
}
return pt, nil
}
// Stat returns a FileInfo describing the named file.
func (w withPkger) Stat(p string) (os.FileInfo, error) {
pt, err := w.base.Stat(p)
if err != nil {
if w.parent != nil {
return w.parent.Stat(p)
}
return pt, err
}
return pt, nil
}
// Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links. - That is from the standard library. I know. Their grammar teachers can not be happy with them right now.
func (w withPkger) Walk(p string, wf filepath.WalkFunc) error {
err := w.base.Walk(p, wf)
if err != nil {
return err
}
if w.parent != nil {
return w.parent.Walk(p, wf)
}
return nil
}
// Remove removes the named file or (empty) directory.
func (w withPkger) Remove(p string) error {
err := w.base.Remove(p)
if err != nil {
return err
}
if w.parent != nil {
return w.parent.Remove(p)
}
return nil
}
// RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
func (w withPkger) RemoveAll(p string) error {
err := w.base.RemoveAll(p)
if err != nil {
return err
}
if w.parent != nil {
return w.parent.RemoveAll(p)
}
return nil
}

4
vendor/github.com/markbates/pkger/version.go generated vendored Normal file
View File

@ -0,0 +1,4 @@
package pkger
// Version of pkger
var Version = "development"

7
vendor/modules.txt vendored
View File

@ -1,5 +1,7 @@
# github.com/gobuffalo/envy v1.7.1 # github.com/gobuffalo/envy v1.7.1
github.com/gobuffalo/envy github.com/gobuffalo/envy
# github.com/gobuffalo/here v0.6.0
github.com/gobuffalo/here
# github.com/gobuffalo/logger v1.0.1 # github.com/gobuffalo/logger v1.0.1
github.com/gobuffalo/logger github.com/gobuffalo/logger
# github.com/gobuffalo/packd v0.3.0 # github.com/gobuffalo/packd v0.3.0
@ -32,6 +34,11 @@ github.com/likexian/gokit/xslice
github.com/likexian/whois-go github.com/likexian/whois-go
# github.com/likexian/whois-parser-go v1.10.2 # github.com/likexian/whois-parser-go v1.10.2
github.com/likexian/whois-parser-go github.com/likexian/whois-parser-go
# github.com/markbates/pkger v0.14.0
github.com/markbates/pkger
github.com/markbates/pkger/internal/maps
github.com/markbates/pkger/pkging
github.com/markbates/pkger/pkging/stdos
# github.com/mattn/go-colorable v0.1.2 # github.com/mattn/go-colorable v0.1.2
github.com/mattn/go-colorable github.com/mattn/go-colorable
# github.com/mattn/go-isatty v0.0.9 # github.com/mattn/go-isatty v0.0.9