Skip to content

Commit 735334c

Browse files
unknwonSourcegraph Bot
andauthored
ci: migrate from Travis to GitHub Actions (#35)
* ci: migrate from Travis to GitHub Actions * Fix lint errors * README Co-authored-by: Sourcegraph Bot <campaigns@sourcegraph.com>
1 parent 7476721 commit 735334c

9 files changed

Lines changed: 76 additions & 38 deletions

File tree

.github/workflows/go.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Go
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
env:
7+
GOPROXY: "https://proxy.golang.org"
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Run golangci-lint
16+
uses: actions-contrib/golangci-lint@v1
17+
18+
test:
19+
name: Test
20+
strategy:
21+
matrix:
22+
go-version: [1.13.x, 1.14.x]
23+
platform: [ubuntu-latest, macos-latest, windows-latest]
24+
runs-on: ${{ matrix.platform }}
25+
steps:
26+
- name: Install Go
27+
uses: actions/setup-go@v1
28+
with:
29+
go-version: ${{ matrix.go-version }}
30+
- name: Checkout code
31+
uses: actions/checkout@v2
32+
- name: Run unit tests
33+
run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
34+
- name: Upload coverage report to Codecov
35+
uses: codecov/codecov-action@v1.0.6
36+
with:
37+
file: ./coverage
38+
flags: unittests
39+
- name: Cache downloaded modules
40+
uses: actions/cache@v1
41+
with:
42+
path: ~/go/pkg/mod
43+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
44+
restore-keys: |
45+
${{ runner.os }}-go-

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# binding [![Build Status](https://travis-ci.org/go-macaron/binding.svg?branch=master)](https://travis-ci.org/go-macaron/binding) [![Sourcegraph](https://sourcegraph.com/github.com/go-macaron/binding/-/badge.svg)](https://sourcegraph.com/github.com/go-macaron/binding?badge)
1+
# binding
2+
3+
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/go-macaron/binding/Go?logo=github&style=for-the-badge)](https://github.com/go-macaron/binding/actions?query=workflow%3AGo)
4+
[![codecov](https://img.shields.io/codecov/c/github/go-macaron/binding/master?logo=codecov&style=for-the-badge)](https://codecov.io/gh/go-macaron/binding)
5+
[![GoDoc](https://img.shields.io/badge/GoDoc-Reference-blue?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/go-macaron/binding?tab=doc)
6+
[![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?style=for-the-badge&logo=sourcegraph)](https://sourcegraph.com/github.com/go-macaron/binding)
27

38
Middleware binding provides request data binding and validation for [Macaron](https://github.com/go-macaron/macaron).
49

binding.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ func bind(ctx *macaron.Context, obj interface{}, ifacePtr ...interface{}) {
3838
if ctx.Req.Method == "POST" || ctx.Req.Method == "PUT" || ctx.Req.Method == "PATCH" || ctx.Req.Method == "DELETE" {
3939
switch {
4040
case strings.Contains(contentType, "form-urlencoded"):
41-
ctx.Invoke(Form(obj, ifacePtr...))
41+
_, _ = ctx.Invoke(Form(obj, ifacePtr...))
4242
case strings.Contains(contentType, "multipart/form-data"):
43-
ctx.Invoke(MultipartForm(obj, ifacePtr...))
43+
_, _ = ctx.Invoke(MultipartForm(obj, ifacePtr...))
4444
case strings.Contains(contentType, "json"):
45-
ctx.Invoke(Json(obj, ifacePtr...))
45+
_, _ = ctx.Invoke(Json(obj, ifacePtr...))
4646
default:
4747
var errors Errors
4848
if contentType == "" {
@@ -54,7 +54,7 @@ func bind(ctx *macaron.Context, obj interface{}, ifacePtr ...interface{}) {
5454
ctx.Map(obj) // Map a fake struct so handler won't panic.
5555
}
5656
} else {
57-
ctx.Invoke(Form(obj, ifacePtr...))
57+
_, _ = ctx.Invoke(Form(obj, ifacePtr...))
5858
}
5959
}
6060

@@ -83,7 +83,7 @@ func errorHandler(errs Errors, rw http.ResponseWriter) {
8383
rw.WriteHeader(STATUS_UNPROCESSABLE_ENTITY)
8484
}
8585
errOutput, _ := json.Marshal(errs)
86-
rw.Write(errOutput)
86+
_, _ = rw.Write(errOutput)
8787
return
8888
}
8989
}
@@ -103,11 +103,11 @@ func Bind(obj interface{}, ifacePtr ...interface{}) macaron.Handler {
103103
return func(ctx *macaron.Context) {
104104
bind(ctx, obj, ifacePtr...)
105105
if handler, ok := obj.(ErrorHandler); ok {
106-
ctx.Invoke(handler.Error)
106+
_, _ = ctx.Invoke(handler.Error)
107107
} else if CustomErrorHandler != nil {
108-
ctx.Invoke(CustomErrorHandler)
108+
_, _ = ctx.Invoke(CustomErrorHandler)
109109
} else {
110-
ctx.Invoke(errorHandler)
110+
_, _ = ctx.Invoke(errorHandler)
111111
}
112112
}
113113
}
@@ -176,7 +176,7 @@ func MultipartForm(formStruct interface{}, ifacePtr ...interface{}) macaron.Hand
176176
}
177177

178178
if ctx.Req.Form == nil {
179-
ctx.Req.ParseForm()
179+
_ = ctx.Req.ParseForm()
180180
}
181181
for k, v := range form.Value {
182182
ctx.Req.Form[k] = append(ctx.Req.Form[k], v...)
@@ -284,8 +284,8 @@ func Validate(obj interface{}) macaron.Handler {
284284
}
285285

286286
var (
287-
AlphaDashPattern = regexp.MustCompile("[^\\d\\w-_]")
288-
AlphaDashDotPattern = regexp.MustCompile("[^\\d\\w-_\\.]")
287+
AlphaDashPattern = regexp.MustCompile(`[^\d\w-_]`)
288+
AlphaDashDotPattern = regexp.MustCompile(`[^\d\w-_\.]`)
289289
EmailPattern = regexp.MustCompile("[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[a-zA-Z0-9](?:[\\w-]*[\\w])?")
290290
)
291291

@@ -744,7 +744,7 @@ func ensureNotPointer(obj interface{}) {
744744
// with errors from deserialization, then maps both the
745745
// resulting struct and the errors to the context.
746746
func validateAndMap(obj reflect.Value, ctx *macaron.Context, errors Errors, ifacePtr ...interface{}) {
747-
ctx.Invoke(Validate(obj.Interface()))
747+
_, _ = ctx.Invoke(Validate(obj.Interface()))
748748
errors = append(errors, getErrors(ctx)...)
749749
ctx.Map(errors)
750750
ctx.Map(obj.Elem().Interface())

common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type (
4949
Coauthor *Person `json:"coauthor"`
5050
HeaderImage *multipart.FileHeader
5151
Pictures []*multipart.FileHeader `form:"picture"`
52-
unexported string `form:"unexported"`
52+
unexported string `form:"unexported"` //nolint
5353
}
5454

5555
EmbedPerson struct {

errorhandler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func performErrorTest(t *testing.T, testCase errorTestCase) {
149149

150150
type (
151151
errorTestCase struct {
152-
description string
152+
description string //nolint
153153
errors Errors
154154
expected errorTestResult
155155
}

file_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ func buildRequestWithFile(testCase fileTestCase) *http.Request {
130130
if err != nil {
131131
panic("Could not create FormFile (single file): " + err.Error())
132132
}
133-
formFileSingle.Write([]byte(testCase.singleFile.data))
133+
_, _ = formFileSingle.Write([]byte(testCase.singleFile.data))
134134
}
135135

136136
for _, file := range testCase.multipleFiles {
137137
formFileMultiple, err := w.CreateFormFile("picture", file.fileName)
138138
if err != nil {
139139
panic("Could not create FormFile (multiple files): " + err.Error())
140140
}
141-
formFileMultiple.Write([]byte(file.data))
141+
_, _ = formFileMultiple.Write([]byte(file.data))
142142
}
143143

144144
err := w.Close()
@@ -179,7 +179,6 @@ func unpackFileHeaderData(fh *multipart.FileHeader) string {
179179
type (
180180
fileTestCase struct {
181181
description string
182-
input BlogPost
183182
singleFile *fileInfo
184183
multipleFiles []*fileInfo
185184
}

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ gopkg.in/ini.v1 v1.46.0 h1:VeDZbLYGaupuvIrsYCEOe/L/2Pcs5n7hdO1ZTjporag=
3737
gopkg.in/ini.v1 v1.46.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
3838
gopkg.in/macaron.v1 v1.3.4 h1:HvIscOwxhFhx3swWM/979wh2QMYyuXrNmrF9l+j3HZs=
3939
gopkg.in/macaron.v1 v1.3.4/go.mod h1:/RoHTdC8ALpyJ3+QR36mKjwnT1F1dyYtsGM9Ate6ZFI=
40+
gopkg.in/macaron.v1 v1.3.5 h1:FUA16VFBojxzfU75KqWrV/6BPv9O2R1GnybSGRie9QQ=
41+
gopkg.in/macaron.v1 v1.3.5/go.mod h1:uMZCFccv9yr5TipIalVOyAyZQuOH3OkmXvgcWwhJuP4=

multipart_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ func makeMultipartPayload(testCase multipartFormTestCase) (*bytes.Buffer, *multi
131131
body.Write([]byte(`--` + writer.Boundary() + `\nContent-Disposition: form-data; name="foo"\n\n--` + writer.Boundary() + `--`))
132132
return body, writer
133133
} else {
134-
writer.WriteField("title", testCase.inputAndExpected.Title)
135-
writer.WriteField("content", testCase.inputAndExpected.Content)
136-
writer.WriteField("id", strconv.Itoa(testCase.inputAndExpected.Id))
137-
writer.WriteField("ignored", testCase.inputAndExpected.Ignored)
134+
_ = writer.WriteField("title", testCase.inputAndExpected.Title)
135+
_ = writer.WriteField("content", testCase.inputAndExpected.Content)
136+
_ = writer.WriteField("id", strconv.Itoa(testCase.inputAndExpected.Id))
137+
_ = writer.WriteField("ignored", testCase.inputAndExpected.Ignored)
138138
for _, value := range testCase.inputAndExpected.Ratings {
139-
writer.WriteField("rating", strconv.Itoa(value))
139+
_ = writer.WriteField("rating", strconv.Itoa(value))
140140
}
141-
writer.WriteField("name", testCase.inputAndExpected.Author.Name)
142-
writer.WriteField("email", testCase.inputAndExpected.Author.Email)
141+
_ = writer.WriteField("name", testCase.inputAndExpected.Author.Name)
142+
_ = writer.WriteField("email", testCase.inputAndExpected.Author.Email)
143143
return body, writer
144144
}
145145
}

0 commit comments

Comments
 (0)