forked from forgejo/forgejo
Vendor Update (#16121)
* update github.com/PuerkitoBio/goquery * update github.com/alecthomas/chroma * update github.com/blevesearch/bleve/v2 * update github.com/caddyserver/certmagic * update github.com/go-enry/go-enry/v2 * update github.com/go-git/go-billy/v5 * update github.com/go-git/go-git/v5 * update github.com/go-redis/redis/v8 * update github.com/go-testfixtures/testfixtures/v3 * update github.com/jaytaylor/html2text * update github.com/json-iterator/go * update github.com/klauspost/compress * update github.com/markbates/goth * update github.com/mattn/go-isatty * update github.com/mholt/archiver/v3 * update github.com/microcosm-cc/bluemonday * update github.com/minio/minio-go/v7 * update github.com/prometheus/client_golang * update github.com/unrolled/render * update github.com/xanzy/go-gitlab * update github.com/yuin/goldmark * update github.com/yuin/goldmark-highlighting Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
f088dc4ea1
commit
86e2789960
819 changed files with 38072 additions and 34969 deletions
27
vendor/github.com/unrolled/render/.gitignore
generated
vendored
27
vendor/github.com/unrolled/render/.gitignore
generated
vendored
|
@ -1,27 +0,0 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
|
||||
|
||||
*.pem
|
||||
.DS_Store
|
56
vendor/github.com/unrolled/render/.golangci.yaml
generated
vendored
Normal file
56
vendor/github.com/unrolled/render/.golangci.yaml
generated
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
issues:
|
||||
exclude:
|
||||
- G203
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- depguard
|
||||
- dogsled
|
||||
- dupl
|
||||
- errcheck
|
||||
- exhaustive
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- goimports
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- nakedret
|
||||
- nolintlint
|
||||
- rowserrcheck
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
||||
- whitespace
|
||||
- noctx
|
||||
- misspell
|
||||
# - golint
|
||||
# - gochecknoinits
|
||||
# - funlen
|
||||
# - gofmt
|
||||
# - scopelint
|
||||
# - interfacer
|
||||
# - gomnd
|
||||
# - lll
|
||||
# - asciicheck
|
||||
# - gochecknoglobals
|
||||
# - gocognit
|
||||
# - godot
|
||||
# - godox
|
||||
# - goerr113
|
||||
# - maligned
|
||||
# - nestif
|
||||
# - prealloc
|
||||
# - testpackage
|
||||
# - wsl
|
14
vendor/github.com/unrolled/render/Makefile
generated
vendored
Normal file
14
vendor/github.com/unrolled/render/Makefile
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
.PHONY: help test
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
help: ## Displays this help message.
|
||||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
|
||||
test: ## Runs the linter, tests, and vetting.
|
||||
golangci-lint run ./...
|
||||
go test -cover -race -count=1 ./...
|
||||
go vet ./...
|
||||
|
||||
ci: ## Runs on the tests and vetting for CI.
|
||||
go test -cover -race -count=1 ./...
|
||||
go vet ./...
|
55
vendor/github.com/unrolled/render/README.md
generated
vendored
55
vendor/github.com/unrolled/render/README.md
generated
vendored
|
@ -1,10 +1,7 @@
|
|||
# Render [](http://godoc.org/github.com/unrolled/render) [](https://github.com/unrolled/render/actions)
|
||||
|
||||
|
||||
Render is a package that provides functionality for easily rendering JSON, XML, text, binary data, and HTML templates. This package is based on the [Martini](https://github.com/go-martini/martini) [render](https://github.com/martini-contrib/render) work.
|
||||
|
||||
## Block Deprecation Notice
|
||||
Go 1.6 introduces a new [block](https://github.com/golang/go/blob/release-branch.go1.6/src/html/template/example_test.go#L128) action. This conflicts with Render's included `block` template function. To provide an easy migration path, a new function was created called `partial`. It is a duplicate of the old `block` function. It is advised that all users of the `block` function update their code to avoid any issues in the future. Previous to Go 1.6, Render's `block` functionality will continue to work but a message will be logged urging you to migrate to the new `partial` function.
|
||||
Render is a package that provides functionality for easily rendering JSON, XML, text, binary data, and HTML templates.
|
||||
|
||||
## Usage
|
||||
Render can be used with pretty much any web framework providing you can access the `http.ResponseWriter` from your handler. The rendering functions simply wraps Go's existing functionality for marshaling and rendering data.
|
||||
|
@ -23,7 +20,7 @@ import (
|
|||
"encoding/xml"
|
||||
"net/http"
|
||||
|
||||
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
|
||||
"github.com/unrolled/render"
|
||||
)
|
||||
|
||||
type ExampleXml struct {
|
||||
|
@ -101,6 +98,7 @@ r := render.New(render.Options{
|
|||
PrefixXML: []byte("<?xml version='1.0' encoding='UTF-8'?>"), // Prefixes XML responses with the given bytes.
|
||||
HTMLContentType: "application/xhtml+xml", // Output XHTML content type instead of default "text/html".
|
||||
IsDevelopment: true, // Render will now recompile the templates on every HTML response.
|
||||
UseMutexLock: true, // Overrides the default no lock implementation and uses the standard `sync.RWMutex` lock.
|
||||
UnEscapeHTML: true, // Replace ensure '&<>' are output correctly (JSON only).
|
||||
StreamingJSON: true, // Streams the JSON response via json.Encoder.
|
||||
RequirePartials: true, // Return an error if a template is missing a partial used in a layout.
|
||||
|
@ -139,10 +137,13 @@ r := render.New(render.Options{
|
|||
TextContentType: "text/plain",
|
||||
XMLContentType: "application/xhtml+xml",
|
||||
IsDevelopment: false,
|
||||
UseMutexLock: false,
|
||||
UnEscapeHTML: false,
|
||||
StreamingJSON: false,
|
||||
RequirePartials: false,
|
||||
DisableHTTPErrorRendering: false,
|
||||
RenderPartialsWithoutPrefix: false,
|
||||
BufferPool: GenericBufferPool,
|
||||
})
|
||||
~~~
|
||||
|
||||
|
@ -171,7 +172,27 @@ admin/edit
|
|||
home
|
||||
~~~
|
||||
|
||||
You can also load templates from memory by providing the Asset and AssetNames options,
|
||||
Templates can be loaded from an `embed.FS`.
|
||||
|
||||
~~~ go
|
||||
// ...
|
||||
|
||||
//go:embed templates/*.html templates/*.tmpl
|
||||
var embeddedTemplates embed.FS
|
||||
|
||||
// ...
|
||||
|
||||
r := render.New(render.Options{
|
||||
Directory: "templates",
|
||||
FileSystem: &render.EmbedFileSystem{
|
||||
FS: embeddedTemplates,
|
||||
},
|
||||
Extensions: []string{".html", ".tmpl"},
|
||||
})
|
||||
// ...
|
||||
~~~
|
||||
|
||||
You can also load templates from memory by providing the `Asset` and `AssetNames` options,
|
||||
e.g. when generating an asset file using [go-bindata](https://github.com/jteeuwen/go-bindata).
|
||||
|
||||
### Layouts
|
||||
|
@ -243,7 +264,7 @@ import (
|
|||
"encoding/xml"
|
||||
"net/http"
|
||||
|
||||
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
|
||||
"github.com/unrolled/render"
|
||||
)
|
||||
|
||||
type ExampleXml struct {
|
||||
|
@ -297,7 +318,7 @@ import (
|
|||
"encoding/xml"
|
||||
"net/http"
|
||||
|
||||
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
|
||||
"github.com/unrolled/render"
|
||||
)
|
||||
|
||||
type ExampleXml struct {
|
||||
|
@ -376,7 +397,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/labstack/echo"
|
||||
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
|
||||
"github.com/unrolled/render"
|
||||
)
|
||||
|
||||
type RenderWrapper struct { // We need to wrap the renderer because we need a different signature for echo.
|
||||
|
@ -398,7 +419,7 @@ func main() {
|
|||
return c.Render(http.StatusOK, "TemplateName", "TemplateData")
|
||||
})
|
||||
|
||||
e.Logger.Fatal(e.Start(":1323"))
|
||||
e.Logger.Fatal(e.Start("127.0.0.1:8080"))
|
||||
}
|
||||
~~~
|
||||
|
||||
|
@ -411,7 +432,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
|
||||
"github.com/unrolled/render"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -425,7 +446,7 @@ func main() {
|
|||
r.JSON(c.Writer, http.StatusOK, map[string]string{"welcome": "This is rendered JSON!"})
|
||||
})
|
||||
|
||||
router.Run(":3000")
|
||||
router.Run("127.0.0.1:8080")
|
||||
}
|
||||
~~~
|
||||
|
||||
|
@ -439,7 +460,7 @@ import (
|
|||
|
||||
"github.com/zenazn/goji"
|
||||
"github.com/zenazn/goji/web"
|
||||
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
|
||||
"github.com/unrolled/render"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -463,7 +484,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/urfave/negroni"
|
||||
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
|
||||
"github.com/unrolled/render"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -478,7 +499,7 @@ func main() {
|
|||
|
||||
n := negroni.Classic()
|
||||
n.UseHandler(mux)
|
||||
n.Run(":3000")
|
||||
n.Run("127.0.0.1:8080")
|
||||
}
|
||||
~~~
|
||||
|
||||
|
@ -491,7 +512,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/pilu/traffic"
|
||||
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
|
||||
"github.com/unrolled/render"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -504,6 +525,6 @@ func main() {
|
|||
r.JSON(w, http.StatusOK, map[string]string{"welcome": "This is rendered JSON!"})
|
||||
})
|
||||
|
||||
router.Run()
|
||||
router.Run() // Defaults to "127.0.0.1:3000".
|
||||
}
|
||||
~~~
|
||||
|
|
38
vendor/github.com/unrolled/render/buffer.go
generated
vendored
38
vendor/github.com/unrolled/render/buffer.go
generated
vendored
|
@ -1,38 +0,0 @@
|
|||
package render
|
||||
|
||||
import "bytes"
|
||||
|
||||
// BufferPool implements a pool of bytes.Buffers in the form of a bounded channel.
|
||||
// Pulled from the github.com/oxtoacart/bpool package (Apache licensed).
|
||||
type BufferPool struct {
|
||||
c chan *bytes.Buffer
|
||||
}
|
||||
|
||||
// NewBufferPool creates a new BufferPool bounded to the given size.
|
||||
func NewBufferPool(size int) (bp *BufferPool) {
|
||||
return &BufferPool{
|
||||
c: make(chan *bytes.Buffer, size),
|
||||
}
|
||||
}
|
||||
|
||||
// Get gets a Buffer from the BufferPool, or creates a new one if none are
|
||||
// available in the pool.
|
||||
func (bp *BufferPool) Get() (b *bytes.Buffer) {
|
||||
select {
|
||||
case b = <-bp.c:
|
||||
// reuse existing buffer
|
||||
default:
|
||||
// create new buffer
|
||||
b = bytes.NewBuffer([]byte{})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Put returns the given Buffer to the BufferPool.
|
||||
func (bp *BufferPool) Put(b *bytes.Buffer) {
|
||||
b.Reset()
|
||||
select {
|
||||
case bp.c <- b:
|
||||
default: // Discard the buffer if the pool is full.
|
||||
}
|
||||
}
|
4
vendor/github.com/unrolled/render/doc.go
generated
vendored
4
vendor/github.com/unrolled/render/doc.go
generated
vendored
|
@ -6,7 +6,7 @@
|
|||
"encoding/xml"
|
||||
"net/http"
|
||||
|
||||
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
|
||||
"github.com/unrolled/render"
|
||||
)
|
||||
|
||||
type ExampleXml struct {
|
||||
|
@ -49,7 +49,7 @@
|
|||
r.HTML(w, http.StatusOK, "example", nil)
|
||||
})
|
||||
|
||||
http.ListenAndServe("0.0.0.0:3000", mux)
|
||||
http.ListenAndServe("127.0.0.1:3000", mux)
|
||||
}
|
||||
*/
|
||||
package render
|
||||
|
|
30
vendor/github.com/unrolled/render/engine.go
generated
vendored
30
vendor/github.com/unrolled/render/engine.go
generated
vendored
|
@ -78,7 +78,7 @@ func (d Data) Render(w io.Writer, v interface{}) error {
|
|||
d.Head.Write(hw)
|
||||
}
|
||||
|
||||
w.Write(v.([]byte))
|
||||
_, _ = w.Write(v.([]byte))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ func (h HTML) Render(w io.Writer, binding interface{}) error {
|
|||
if hw, ok := w.(http.ResponseWriter); ok {
|
||||
h.Head.Write(hw)
|
||||
}
|
||||
buf.WriteTo(w)
|
||||
_, _ = buf.WriteTo(w)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -125,9 +125,9 @@ func (j JSON) Render(w io.Writer, v interface{}) error {
|
|||
|
||||
// Unescape HTML if needed.
|
||||
if j.UnEscapeHTML {
|
||||
result = bytes.Replace(result, []byte("\\u003c"), []byte("<"), -1)
|
||||
result = bytes.Replace(result, []byte("\\u003e"), []byte(">"), -1)
|
||||
result = bytes.Replace(result, []byte("\\u0026"), []byte("&"), -1)
|
||||
result = bytes.ReplaceAll(result, []byte("\\u003c"), []byte("<"))
|
||||
result = bytes.ReplaceAll(result, []byte("\\u003e"), []byte(">"))
|
||||
result = bytes.ReplaceAll(result, []byte("\\u0026"), []byte("&"))
|
||||
}
|
||||
|
||||
// JSON marshaled fine, write out the result.
|
||||
|
@ -135,9 +135,9 @@ func (j JSON) Render(w io.Writer, v interface{}) error {
|
|||
j.Head.Write(hw)
|
||||
}
|
||||
if len(j.Prefix) > 0 {
|
||||
w.Write(j.Prefix)
|
||||
_, _ = w.Write(j.Prefix)
|
||||
}
|
||||
w.Write(result)
|
||||
_, _ = w.Write(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ func (j JSON) renderStreamingJSON(w io.Writer, v interface{}) error {
|
|||
j.Head.Write(hw)
|
||||
}
|
||||
if len(j.Prefix) > 0 {
|
||||
w.Write(j.Prefix)
|
||||
_, _ = w.Write(j.Prefix)
|
||||
}
|
||||
|
||||
return json.NewEncoder(w).Encode(v)
|
||||
|
@ -170,13 +170,13 @@ func (j JSONP) Render(w io.Writer, v interface{}) error {
|
|||
if hw, ok := w.(http.ResponseWriter); ok {
|
||||
j.Head.Write(hw)
|
||||
}
|
||||
w.Write([]byte(j.Callback + "("))
|
||||
w.Write(result)
|
||||
w.Write([]byte(");"))
|
||||
_, _ = w.Write([]byte(j.Callback + "("))
|
||||
_, _ = w.Write(result)
|
||||
_, _ = w.Write([]byte(");"))
|
||||
|
||||
// If indenting, append a new line.
|
||||
if j.Indent {
|
||||
w.Write([]byte("\n"))
|
||||
_, _ = w.Write([]byte("\n"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ func (t Text) Render(w io.Writer, v interface{}) error {
|
|||
t.Head.Write(hw)
|
||||
}
|
||||
|
||||
w.Write([]byte(v.(string)))
|
||||
_, _ = w.Write([]byte(v.(string)))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -215,8 +215,8 @@ func (x XML) Render(w io.Writer, v interface{}) error {
|
|||
x.Head.Write(hw)
|
||||
}
|
||||
if len(x.Prefix) > 0 {
|
||||
w.Write(x.Prefix)
|
||||
_, _ = w.Write(x.Prefix)
|
||||
}
|
||||
w.Write(result)
|
||||
_, _ = w.Write(result)
|
||||
return nil
|
||||
}
|
||||
|
|
31
vendor/github.com/unrolled/render/fs_embed.go
generated
vendored
Normal file
31
vendor/github.com/unrolled/render/fs_embed.go
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
// +build go1.16
|
||||
|
||||
package render
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// EmbedFileSystem implements FileSystem on top of an embed.FS
|
||||
type EmbedFileSystem struct {
|
||||
embed.FS
|
||||
}
|
||||
|
||||
var _ FileSystem = &EmbedFileSystem{}
|
||||
|
||||
func (e *EmbedFileSystem) Walk(root string, walkFn filepath.WalkFunc) error {
|
||||
return fs.WalkDir(e.FS, root, func(path string, d fs.DirEntry, _ error) error {
|
||||
if d == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
info, err := d.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return walkFn(path, info, err)
|
||||
})
|
||||
}
|
7
vendor/github.com/unrolled/render/go.mod
generated
vendored
7
vendor/github.com/unrolled/render/go.mod
generated
vendored
|
@ -1,5 +1,8 @@
|
|||
module github.com/unrolled/render
|
||||
|
||||
go 1.12
|
||||
go 1.16
|
||||
|
||||
require github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385
|
||||
require (
|
||||
github.com/fsnotify/fsnotify v1.4.9
|
||||
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea // indirect
|
||||
)
|
||||
|
|
7
vendor/github.com/unrolled/render/go.sum
generated
vendored
7
vendor/github.com/unrolled/render/go.sum
generated
vendored
|
@ -1,2 +1,5 @@
|
|||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o=
|
||||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea h1:+WiDlPBBaO+h9vPNZi8uJ3k4BkKQB7Iow3aqwHVA5hI=
|
||||
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
2
vendor/github.com/unrolled/render/helpers.go
generated
vendored
2
vendor/github.com/unrolled/render/helpers.go
generated
vendored
|
@ -1,5 +1,3 @@
|
|||
// +build go1.6
|
||||
|
||||
package render
|
||||
|
||||
import (
|
||||
|
|
26
vendor/github.com/unrolled/render/helpers_pre16.go
generated
vendored
26
vendor/github.com/unrolled/render/helpers_pre16.go
generated
vendored
|
@ -1,26 +0,0 @@
|
|||
// +build !go1.6
|
||||
|
||||
package render
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
// Included helper functions for use when rendering HTML.
|
||||
var helperFuncs = template.FuncMap{
|
||||
"yield": func() (string, error) {
|
||||
return "", fmt.Errorf("yield called with no layout defined")
|
||||
},
|
||||
// `block` is deprecated! Use the `partial` below if you need this functionality still.
|
||||
// Otherwise, checkout Go's `block` implementation introduced in 1.6
|
||||
"block": func() (string, error) {
|
||||
return "", fmt.Errorf("block called with no layout defined")
|
||||
},
|
||||
"partial": func() (string, error) {
|
||||
return "", fmt.Errorf("block called with no layout defined")
|
||||
},
|
||||
"current": func() (string, error) {
|
||||
return "", nil
|
||||
},
|
||||
}
|
25
vendor/github.com/unrolled/render/lock.go
generated
vendored
Normal file
25
vendor/github.com/unrolled/render/lock.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
package render
|
||||
|
||||
import "sync"
|
||||
|
||||
// rwLock represents an interface for sync.RWMutex.
|
||||
type rwLock interface {
|
||||
Lock()
|
||||
Unlock()
|
||||
RLock()
|
||||
RUnlock()
|
||||
}
|
||||
|
||||
var (
|
||||
// Ensure our interface is correct.
|
||||
_ rwLock = &sync.RWMutex{}
|
||||
_ rwLock = emptyLock{}
|
||||
)
|
||||
|
||||
// emptyLock is a noop RWLock implementation.
|
||||
type emptyLock struct{}
|
||||
|
||||
func (emptyLock) Lock() {}
|
||||
func (emptyLock) Unlock() {}
|
||||
func (emptyLock) RLock() {}
|
||||
func (emptyLock) RUnlock() {}
|
117
vendor/github.com/unrolled/render/render.go
generated
vendored
117
vendor/github.com/unrolled/render/render.go
generated
vendored
|
@ -11,6 +11,8 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -90,6 +92,9 @@ type Options struct {
|
|||
XMLContentType string
|
||||
// If IsDevelopment is set to true, this will recompile the templates on every request. Default is false.
|
||||
IsDevelopment bool
|
||||
// If UseMutexLock is set to true, the standard `sync.RWMutex` lock will be used instead of the lock free implementation. Default is false.
|
||||
// Note that when `IsDevelopment` is true, the standard `sync.RWMutex` lock is always used. Lock free is only a production feature.
|
||||
UseMutexLock bool
|
||||
// Unescape HTML characters "&<>" to their original values. Default is false.
|
||||
UnEscapeHTML bool
|
||||
// Streams JSON responses instead of marshalling prior to sending. Default is false.
|
||||
|
@ -103,7 +108,6 @@ type Options struct {
|
|||
// Enables using partials without the current filename suffix which allows use of the same template in multiple files. e.g {{ partial "carosuel" }} inside the home template will match carosel-home or carosel.
|
||||
// ***NOTE*** - This option should be named RenderPartialsWithoutSuffix as that is what it does. "Prefix" is a typo. Maintaining the existing name for backwards compatibility.
|
||||
RenderPartialsWithoutPrefix bool
|
||||
|
||||
// BufferPool to use when rendering HTML templates. If none is supplied
|
||||
// defaults to SizedBufferPool of size 32 with 512KiB buffers.
|
||||
BufferPool GenericBufferPool
|
||||
|
@ -120,11 +124,13 @@ type HTMLOptions struct {
|
|||
// Render is a service that provides functions for easily writing JSON, XML,
|
||||
// binary data, and HTML templates out to a HTTP Response.
|
||||
type Render struct {
|
||||
lock rwLock
|
||||
|
||||
// Customize Secure with an Options struct.
|
||||
opt Options
|
||||
templates *template.Template
|
||||
templatesLk sync.RWMutex
|
||||
compiledCharset string
|
||||
hasWatcher bool
|
||||
}
|
||||
|
||||
// New constructs a new Render instance with the supplied options.
|
||||
|
@ -134,12 +140,10 @@ func New(options ...Options) *Render {
|
|||
o = options[0]
|
||||
}
|
||||
|
||||
r := Render{
|
||||
opt: o,
|
||||
}
|
||||
r := Render{opt: o}
|
||||
|
||||
r.prepareOptions()
|
||||
r.compileTemplates()
|
||||
r.CompileTemplates()
|
||||
|
||||
return &r
|
||||
}
|
||||
|
@ -149,10 +153,9 @@ func (r *Render) prepareOptions() {
|
|||
if len(r.opt.Charset) == 0 {
|
||||
r.opt.Charset = defaultCharset
|
||||
}
|
||||
if r.opt.DisableCharset == false {
|
||||
if !r.opt.DisableCharset {
|
||||
r.compiledCharset = "; charset=" + r.opt.Charset
|
||||
}
|
||||
|
||||
if len(r.opt.Directory) == 0 {
|
||||
r.opt.Directory = "templates"
|
||||
}
|
||||
|
@ -181,16 +184,21 @@ func (r *Render) prepareOptions() {
|
|||
r.opt.XMLContentType = ContentXML
|
||||
}
|
||||
if r.opt.BufferPool == nil {
|
||||
// 32 buffers of size 512KiB each
|
||||
r.opt.BufferPool = NewSizedBufferPool(32, 1<<19)
|
||||
r.opt.BufferPool = NewSizedBufferPool(32, 1<<19) // 32 buffers of size 512KiB each
|
||||
}
|
||||
if r.opt.IsDevelopment || r.opt.UseMutexLock {
|
||||
r.lock = &sync.RWMutex{}
|
||||
} else {
|
||||
r.lock = &emptyLock{}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Render) compileTemplates() {
|
||||
func (r *Render) CompileTemplates() {
|
||||
if r.opt.Asset == nil || r.opt.AssetNames == nil {
|
||||
r.compileTemplatesFromDir()
|
||||
return
|
||||
}
|
||||
|
||||
r.compileTemplatesFromAsset()
|
||||
}
|
||||
|
||||
|
@ -199,12 +207,24 @@ func (r *Render) compileTemplatesFromDir() {
|
|||
tmpTemplates := template.New(dir)
|
||||
tmpTemplates.Delims(r.opt.Delims.Left, r.opt.Delims.Right)
|
||||
|
||||
var watcher *fsnotify.Watcher
|
||||
if r.opt.IsDevelopment {
|
||||
var err error
|
||||
watcher, err = fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
log.Printf("Unable to create new watcher for template files. Templates will be recompiled on every render. Error: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Walk the supplied directory and compile any files that match our extension list.
|
||||
r.opt.FileSystem.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
_ = r.opt.FileSystem.Walk(dir, func(path string, info os.FileInfo, _ error) error {
|
||||
// Fix same-extension-dirs bug: some dir might be named to: "users.tmpl", "local.html".
|
||||
// These dirs should be excluded as they are not valid golang templates, but files under
|
||||
// them should be treat as normal.
|
||||
// If is a dir, return immediately (dir is not a valid golang template).
|
||||
if info != nil && watcher != nil {
|
||||
_ = watcher.Add(path)
|
||||
}
|
||||
if info == nil || info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
@ -215,7 +235,7 @@ func (r *Render) compileTemplatesFromDir() {
|
|||
}
|
||||
|
||||
ext := ""
|
||||
if strings.Index(rel, ".") != -1 {
|
||||
if strings.Contains(rel, ".") {
|
||||
ext = filepath.Ext(rel)
|
||||
}
|
||||
|
||||
|
@ -242,9 +262,25 @@ func (r *Render) compileTemplatesFromDir() {
|
|||
return nil
|
||||
})
|
||||
|
||||
r.templatesLk.Lock()
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
r.templates = tmpTemplates
|
||||
r.templatesLk.Unlock()
|
||||
if r.hasWatcher = watcher != nil; r.hasWatcher {
|
||||
go func() {
|
||||
select {
|
||||
case _, ok := <-watcher.Events:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
case _, ok := <-watcher.Errors:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
watcher.Close()
|
||||
r.CompileTemplates()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Render) compileTemplatesFromAsset() {
|
||||
|
@ -263,13 +299,12 @@ func (r *Render) compileTemplatesFromAsset() {
|
|||
}
|
||||
|
||||
ext := ""
|
||||
if strings.Index(rel, ".") != -1 {
|
||||
if strings.Contains(rel, ".") {
|
||||
ext = "." + strings.Join(strings.Split(rel, ".")[1:], ".")
|
||||
}
|
||||
|
||||
for _, extension := range r.opt.Extensions {
|
||||
if ext == extension {
|
||||
|
||||
buf, err := r.opt.Asset(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -289,28 +324,29 @@ func (r *Render) compileTemplatesFromAsset() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.templatesLk.Lock()
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
r.templates = tmpTemplates
|
||||
r.templatesLk.Unlock()
|
||||
}
|
||||
|
||||
// TemplateLookup is a wrapper around template.Lookup and returns
|
||||
// the template with the given name that is associated with t, or nil
|
||||
// if there is no such template.
|
||||
func (r *Render) TemplateLookup(t string) *template.Template {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
return r.templates.Lookup(t)
|
||||
}
|
||||
|
||||
func (r *Render) execute(name string, binding interface{}) (*bytes.Buffer, error) {
|
||||
func (r *Render) execute(templates *template.Template, name string, binding interface{}) (*bytes.Buffer, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
return buf, r.templates.ExecuteTemplate(buf, name, binding)
|
||||
return buf, templates.ExecuteTemplate(buf, name, binding)
|
||||
}
|
||||
|
||||
func (r *Render) layoutFuncs(name string, binding interface{}) template.FuncMap {
|
||||
func (r *Render) layoutFuncs(templates *template.Template, name string, binding interface{}) template.FuncMap {
|
||||
return template.FuncMap{
|
||||
"yield": func() (template.HTML, error) {
|
||||
buf, err := r.execute(name, binding)
|
||||
buf, err := r.execute(templates, name, binding)
|
||||
// Return safe HTML here since we are rendering our own template.
|
||||
return template.HTML(buf.String()), err
|
||||
},
|
||||
|
@ -318,13 +354,13 @@ func (r *Render) layoutFuncs(name string, binding interface{}) template.FuncMap
|
|||
return name, nil
|
||||
},
|
||||
"block": func(partialName string) (template.HTML, error) {
|
||||
log.Print("Render's `block` implementation is now depericated. Use `partial` as a drop in replacement.")
|
||||
log.Println("Render's `block` implementation is now depericated. Use `partial` as a drop in replacement.")
|
||||
fullPartialName := fmt.Sprintf("%s-%s", partialName, name)
|
||||
if r.TemplateLookup(fullPartialName) == nil && r.opt.RenderPartialsWithoutPrefix {
|
||||
if templates.Lookup(fullPartialName) == nil && r.opt.RenderPartialsWithoutPrefix {
|
||||
fullPartialName = partialName
|
||||
}
|
||||
if r.opt.RequireBlocks || r.TemplateLookup(fullPartialName) != nil {
|
||||
buf, err := r.execute(fullPartialName, binding)
|
||||
if r.opt.RequireBlocks || templates.Lookup(fullPartialName) != nil {
|
||||
buf, err := r.execute(templates, fullPartialName, binding)
|
||||
// Return safe HTML here since we are rendering our own template.
|
||||
return template.HTML(buf.String()), err
|
||||
}
|
||||
|
@ -332,11 +368,11 @@ func (r *Render) layoutFuncs(name string, binding interface{}) template.FuncMap
|
|||
},
|
||||
"partial": func(partialName string) (template.HTML, error) {
|
||||
fullPartialName := fmt.Sprintf("%s-%s", partialName, name)
|
||||
if r.TemplateLookup(fullPartialName) == nil && r.opt.RenderPartialsWithoutPrefix {
|
||||
if templates.Lookup(fullPartialName) == nil && r.opt.RenderPartialsWithoutPrefix {
|
||||
fullPartialName = partialName
|
||||
}
|
||||
if r.opt.RequirePartials || r.TemplateLookup(fullPartialName) != nil {
|
||||
buf, err := r.execute(fullPartialName, binding)
|
||||
if r.opt.RequirePartials || templates.Lookup(fullPartialName) != nil {
|
||||
buf, err := r.execute(templates, fullPartialName, binding)
|
||||
// Return safe HTML here since we are rendering our own template.
|
||||
return template.HTML(buf.String()), err
|
||||
}
|
||||
|
@ -397,19 +433,20 @@ func (r *Render) Data(w io.Writer, status int, v []byte) error {
|
|||
|
||||
// HTML builds up the response from the specified template and bindings.
|
||||
func (r *Render) HTML(w io.Writer, status int, name string, binding interface{}, htmlOpt ...HTMLOptions) error {
|
||||
|
||||
// If we are in development mode, recompile the templates on every HTML request.
|
||||
if r.opt.IsDevelopment {
|
||||
r.compileTemplates()
|
||||
r.lock.RLock() // rlock here because we're reading the hasWatcher
|
||||
if r.opt.IsDevelopment && !r.hasWatcher {
|
||||
r.lock.RUnlock() // runlock here because CompileTemplates will lock
|
||||
r.CompileTemplates()
|
||||
r.lock.RLock()
|
||||
}
|
||||
|
||||
r.templatesLk.RLock()
|
||||
defer r.templatesLk.RUnlock()
|
||||
templates := r.templates
|
||||
r.lock.RUnlock()
|
||||
|
||||
opt := r.prepareHTMLOptions(htmlOpt)
|
||||
if tpl := r.templates.Lookup(name); tpl != nil {
|
||||
if tpl := templates.Lookup(name); tpl != nil {
|
||||
if len(opt.Layout) > 0 {
|
||||
tpl.Funcs(r.layoutFuncs(name, binding))
|
||||
tpl.Funcs(r.layoutFuncs(templates, name, binding))
|
||||
name = opt.Layout
|
||||
}
|
||||
|
||||
|
@ -426,7 +463,7 @@ func (r *Render) HTML(w io.Writer, status int, name string, binding interface{},
|
|||
h := HTML{
|
||||
Head: head,
|
||||
Name: name,
|
||||
Templates: r.templates,
|
||||
Templates: templates,
|
||||
bp: r.opt.BufferPool,
|
||||
}
|
||||
|
||||
|
|
1
vendor/github.com/unrolled/render/testdata/basic/admin/index.tmpl
generated
vendored
Normal file
1
vendor/github.com/unrolled/render/testdata/basic/admin/index.tmpl
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>Admin {{.}}</h1>
|
3
vendor/github.com/unrolled/render/testdata/basic/another_layout.tmpl
generated
vendored
Normal file
3
vendor/github.com/unrolled/render/testdata/basic/another_layout.tmpl
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
another head
|
||||
{{ yield }}
|
||||
another foot
|
1
vendor/github.com/unrolled/render/testdata/basic/content.tmpl
generated
vendored
Normal file
1
vendor/github.com/unrolled/render/testdata/basic/content.tmpl
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>{{ . }}</h1>
|
3
vendor/github.com/unrolled/render/testdata/basic/current_layout.tmpl
generated
vendored
Normal file
3
vendor/github.com/unrolled/render/testdata/basic/current_layout.tmpl
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{{ current }} head
|
||||
{{ yield }}
|
||||
{{ current }} foot
|
1
vendor/github.com/unrolled/render/testdata/basic/delims.tmpl
generated
vendored
Normal file
1
vendor/github.com/unrolled/render/testdata/basic/delims.tmpl
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>Hello {[{.}]}</h1>
|
1
vendor/github.com/unrolled/render/testdata/basic/hello.tmpl
generated
vendored
Normal file
1
vendor/github.com/unrolled/render/testdata/basic/hello.tmpl
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>Hello {{.}}</h1>
|
1
vendor/github.com/unrolled/render/testdata/basic/hypertext.html
generated
vendored
Normal file
1
vendor/github.com/unrolled/render/testdata/basic/hypertext.html
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Hypertext!
|
3
vendor/github.com/unrolled/render/testdata/basic/layout.tmpl
generated
vendored
Normal file
3
vendor/github.com/unrolled/render/testdata/basic/layout.tmpl
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
head
|
||||
{{ yield }}
|
||||
foot
|
1
vendor/github.com/unrolled/render/testdata/blocks/content-partial.tmpl
generated
vendored
Normal file
1
vendor/github.com/unrolled/render/testdata/blocks/content-partial.tmpl
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{{define "after-content-partial"}}after {{ . }}{{end}}
|
2
vendor/github.com/unrolled/render/testdata/blocks/content.tmpl
generated
vendored
Normal file
2
vendor/github.com/unrolled/render/testdata/blocks/content.tmpl
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
{{define "before-content"}}before {{ . }}{{end}}
|
||||
{{define "after-content"}}after {{ . }}{{end}}
|
3
vendor/github.com/unrolled/render/testdata/blocks/layout.tmpl
generated
vendored
Normal file
3
vendor/github.com/unrolled/render/testdata/blocks/layout.tmpl
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{{ block "before" }}
|
||||
<h1>during</h1>
|
||||
{{ block "after" }}
|
1
vendor/github.com/unrolled/render/testdata/custom_funcs/index.tmpl
generated
vendored
Normal file
1
vendor/github.com/unrolled/render/testdata/custom_funcs/index.tmpl
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{{ myCustomFunc }}
|
1
vendor/github.com/unrolled/render/testdata/partials/content-partial.tmpl
generated
vendored
Normal file
1
vendor/github.com/unrolled/render/testdata/partials/content-partial.tmpl
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{{define "after-content-partial"}}after {{ . }}{{end}}
|
2
vendor/github.com/unrolled/render/testdata/partials/content.tmpl
generated
vendored
Normal file
2
vendor/github.com/unrolled/render/testdata/partials/content.tmpl
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
{{define "before-content"}}before {{ . }}{{end}}
|
||||
{{define "after-content"}}after {{ . }}{{end}}
|
3
vendor/github.com/unrolled/render/testdata/partials/layout.tmpl
generated
vendored
Normal file
3
vendor/github.com/unrolled/render/testdata/partials/layout.tmpl
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{{ partial "before" }}
|
||||
<h1>during</h1>
|
||||
{{ partial "after" }}
|
0
vendor/github.com/unrolled/render/testdata/template-dir-test/0.tmpl
generated
vendored
Normal file
0
vendor/github.com/unrolled/render/testdata/template-dir-test/0.tmpl
generated
vendored
Normal file
0
vendor/github.com/unrolled/render/testdata/template-dir-test/dedicated.tmpl/notbad.tmpl
generated
vendored
Normal file
0
vendor/github.com/unrolled/render/testdata/template-dir-test/dedicated.tmpl/notbad.tmpl
generated
vendored
Normal file
0
vendor/github.com/unrolled/render/testdata/template-dir-test/subdir/1.tmpl
generated
vendored
Normal file
0
vendor/github.com/unrolled/render/testdata/template-dir-test/subdir/1.tmpl
generated
vendored
Normal file
Loading…
Add table
Add a link
Reference in a new issue