Skip to content

Commit

Permalink
Mini refactor (#96)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
unrolled authored May 27, 2021
1 parent fb5b5ba commit a3f5fc8
Show file tree
Hide file tree
Showing 46 changed files with 283 additions and 432 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- "**"
name: Test
jobs:
test:
tests:
strategy:
matrix:
go-version: [1.14.x, 1.15.x, 1.16.x]
Expand All @@ -22,4 +22,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: go test -v -race -tags=integration
run: make ci
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
27 changes: 0 additions & 27 deletions .gitignore

This file was deleted.

56 changes: 56 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ./...
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# 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)


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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
})
~~~

Expand Down Expand Up @@ -263,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 {
Expand Down Expand Up @@ -317,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 {
Expand Down Expand Up @@ -396,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.
Expand All @@ -418,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"))
}
~~~

Expand All @@ -431,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() {
Expand All @@ -445,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")
}
~~~

Expand All @@ -459,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() {
Expand All @@ -483,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() {
Expand All @@ -498,7 +499,7 @@ func main() {

n := negroni.Classic()
n.UseHandler(mux)
n.Run(":3000")
n.Run("127.0.0.1:8080")
}
~~~

Expand All @@ -511,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() {
Expand All @@ -524,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 changes: 0 additions & 38 deletions buffer.go

This file was deleted.

4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Loading

0 comments on commit a3f5fc8

Please sign in to comment.