Skip to content

Commit a3f5fc8

Browse files
authored
Mini refactor (#96)
* remove amber package * rename fixtures to testdata * update test folder ref * remove pre 1.6 helpers * move lock code into it's own file * adding golangci, fixing issues * doc cleanup * added UseMutexLock option * update readme * ci fix * clean up context
1 parent fb5b5ba commit a3f5fc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+283
-432
lines changed

.github/workflows/test.yaml

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- "**"
99
name: Test
1010
jobs:
11-
test:
11+
tests:
1212
strategy:
1313
matrix:
1414
go-version: [1.14.x, 1.15.x, 1.16.x]
@@ -22,4 +22,10 @@ jobs:
2222
- name: Checkout code
2323
uses: actions/checkout@v2
2424
- name: Test
25-
run: go test -v -race -tags=integration
25+
run: make ci
26+
golangci:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v2
30+
- name: golangci-lint
31+
uses: golangci/golangci-lint-action@v2

.gitignore

-27
This file was deleted.

.golangci.yaml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
issues:
2+
exclude:
3+
- G203
4+
5+
linters:
6+
disable-all: true
7+
enable:
8+
- bodyclose
9+
- deadcode
10+
- depguard
11+
- dogsled
12+
- dupl
13+
- errcheck
14+
- exhaustive
15+
- goconst
16+
- gocritic
17+
- gocyclo
18+
- goimports
19+
- goprintffuncname
20+
- gosec
21+
- gosimple
22+
- govet
23+
- ineffassign
24+
- nakedret
25+
- nolintlint
26+
- rowserrcheck
27+
- staticcheck
28+
- structcheck
29+
- stylecheck
30+
- typecheck
31+
- unconvert
32+
- unparam
33+
- unused
34+
- varcheck
35+
- whitespace
36+
- noctx
37+
- misspell
38+
# - golint
39+
# - gochecknoinits
40+
# - funlen
41+
# - gofmt
42+
# - scopelint
43+
# - interfacer
44+
# - gomnd
45+
# - lll
46+
# - asciicheck
47+
# - gochecknoglobals
48+
# - gocognit
49+
# - godot
50+
# - godox
51+
# - goerr113
52+
# - maligned
53+
# - nestif
54+
# - prealloc
55+
# - testpackage
56+
# - wsl

Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: help test
2+
.DEFAULT_GOAL := help
3+
4+
help: ## Displays this help message.
5+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
6+
7+
test: ## Runs the linter, tests, and vetting.
8+
golangci-lint run ./...
9+
go test -cover -race -count=1 ./...
10+
go vet ./...
11+
12+
ci: ## Runs on the tests and vetting for CI.
13+
go test -cover -race -count=1 ./...
14+
go vet ./...

README.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# Render [![GoDoc](http://godoc.org/github.com/unrolled/render?status.svg)](http://godoc.org/github.com/unrolled/render) [![Test](https://github.com/unrolled/render/workflows/Test/badge.svg?branch=v1)](https://github.com/unrolled/render/actions)
22

33

4-
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.
5-
6-
## Block Deprecation Notice
7-
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.
4+
Render is a package that provides functionality for easily rendering JSON, XML, text, binary data, and HTML templates.
85

96
## Usage
107
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 (
2320
"encoding/xml"
2421
"net/http"
2522

26-
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
23+
"github.com/unrolled/render"
2724
)
2825

2926
type ExampleXml struct {
@@ -101,6 +98,7 @@ r := render.New(render.Options{
10198
PrefixXML: []byte("<?xml version='1.0' encoding='UTF-8'?>"), // Prefixes XML responses with the given bytes.
10299
HTMLContentType: "application/xhtml+xml", // Output XHTML content type instead of default "text/html".
103100
IsDevelopment: true, // Render will now recompile the templates on every HTML response.
101+
UseMutexLock: true, // Overrides the default no lock implementation and uses the standard `sync.RWMutex` lock.
104102
UnEscapeHTML: true, // Replace ensure '&<>' are output correctly (JSON only).
105103
StreamingJSON: true, // Streams the JSON response via json.Encoder.
106104
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{
139137
TextContentType: "text/plain",
140138
XMLContentType: "application/xhtml+xml",
141139
IsDevelopment: false,
140+
UseMutexLock: false,
142141
UnEscapeHTML: false,
143142
StreamingJSON: false,
144143
RequirePartials: false,
145144
DisableHTTPErrorRendering: false,
145+
RenderPartialsWithoutPrefix: false,
146+
BufferPool: GenericBufferPool,
146147
})
147148
~~~
148149

@@ -263,7 +264,7 @@ import (
263264
"encoding/xml"
264265
"net/http"
265266

266-
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
267+
"github.com/unrolled/render"
267268
)
268269

269270
type ExampleXml struct {
@@ -317,7 +318,7 @@ import (
317318
"encoding/xml"
318319
"net/http"
319320

320-
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
321+
"github.com/unrolled/render"
321322
)
322323

323324
type ExampleXml struct {
@@ -396,7 +397,7 @@ import (
396397
"net/http"
397398

398399
"github.com/labstack/echo"
399-
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
400+
"github.com/unrolled/render"
400401
)
401402

402403
type RenderWrapper struct { // We need to wrap the renderer because we need a different signature for echo.
@@ -418,7 +419,7 @@ func main() {
418419
return c.Render(http.StatusOK, "TemplateName", "TemplateData")
419420
})
420421

421-
e.Logger.Fatal(e.Start(":1323"))
422+
e.Logger.Fatal(e.Start("127.0.0.1:8080"))
422423
}
423424
~~~
424425

@@ -431,7 +432,7 @@ import (
431432
"net/http"
432433

433434
"github.com/gin-gonic/gin"
434-
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
435+
"github.com/unrolled/render"
435436
)
436437

437438
func main() {
@@ -445,7 +446,7 @@ func main() {
445446
r.JSON(c.Writer, http.StatusOK, map[string]string{"welcome": "This is rendered JSON!"})
446447
})
447448

448-
router.Run(":3000")
449+
router.Run("127.0.0.1:8080")
449450
}
450451
~~~
451452

@@ -459,7 +460,7 @@ import (
459460

460461
"github.com/zenazn/goji"
461462
"github.com/zenazn/goji/web"
462-
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
463+
"github.com/unrolled/render"
463464
)
464465

465466
func main() {
@@ -483,7 +484,7 @@ import (
483484
"net/http"
484485

485486
"github.com/urfave/negroni"
486-
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
487+
"github.com/unrolled/render"
487488
)
488489

489490
func main() {
@@ -498,7 +499,7 @@ func main() {
498499

499500
n := negroni.Classic()
500501
n.UseHandler(mux)
501-
n.Run(":3000")
502+
n.Run("127.0.0.1:8080")
502503
}
503504
~~~
504505

@@ -511,7 +512,7 @@ import (
511512
"net/http"
512513

513514
"github.com/pilu/traffic"
514-
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
515+
"github.com/unrolled/render"
515516
)
516517

517518
func main() {
@@ -524,6 +525,6 @@ func main() {
524525
r.JSON(w, http.StatusOK, map[string]string{"welcome": "This is rendered JSON!"})
525526
})
526527

527-
router.Run()
528+
router.Run() // Defaults to "127.0.0.1:3000".
528529
}
529530
~~~

buffer.go

-38
This file was deleted.

doc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"encoding/xml"
77
"net/http"
88
9-
"github.com/unrolled/render" // or "gopkg.in/unrolled/render.v1"
9+
"github.com/unrolled/render"
1010
)
1111
1212
type ExampleXml struct {
@@ -49,7 +49,7 @@
4949
r.HTML(w, http.StatusOK, "example", nil)
5050
})
5151
52-
http.ListenAndServe("0.0.0.0:3000", mux)
52+
http.ListenAndServe("127.0.0.1:3000", mux)
5353
}
5454
*/
5555
package render

0 commit comments

Comments
 (0)