Skip to content

Commit

Permalink
ci: migrate from Travis to GitHub Actions (#35)
Browse files Browse the repository at this point in the history
* ci: migrate from Travis to GitHub Actions

* Fix lint errors

* README

Co-authored-by: Sourcegraph Bot <campaigns@sourcegraph.com>
  • Loading branch information
unknwon and Sourcegraph Bot authored Mar 28, 2020
1 parent 7476721 commit 735334c
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 38 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Go
on:
push:
branches: [master]
pull_request:
env:
GOPROXY: "https://proxy.golang.org"

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run golangci-lint
uses: actions-contrib/golangci-lint@v1

test:
name: Test
strategy:
matrix:
go-version: [1.13.x, 1.14.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Run unit tests
run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v1.0.6
with:
file: ./coverage
flags: unittests
- name: Cache downloaded modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# 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)
# binding

[![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)
[![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)
[![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)
[![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)

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

Expand Down
24 changes: 12 additions & 12 deletions binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func bind(ctx *macaron.Context, obj interface{}, ifacePtr ...interface{}) {
if ctx.Req.Method == "POST" || ctx.Req.Method == "PUT" || ctx.Req.Method == "PATCH" || ctx.Req.Method == "DELETE" {
switch {
case strings.Contains(contentType, "form-urlencoded"):
ctx.Invoke(Form(obj, ifacePtr...))
_, _ = ctx.Invoke(Form(obj, ifacePtr...))
case strings.Contains(contentType, "multipart/form-data"):
ctx.Invoke(MultipartForm(obj, ifacePtr...))
_, _ = ctx.Invoke(MultipartForm(obj, ifacePtr...))
case strings.Contains(contentType, "json"):
ctx.Invoke(Json(obj, ifacePtr...))
_, _ = ctx.Invoke(Json(obj, ifacePtr...))
default:
var errors Errors
if contentType == "" {
Expand All @@ -54,7 +54,7 @@ func bind(ctx *macaron.Context, obj interface{}, ifacePtr ...interface{}) {
ctx.Map(obj) // Map a fake struct so handler won't panic.
}
} else {
ctx.Invoke(Form(obj, ifacePtr...))
_, _ = ctx.Invoke(Form(obj, ifacePtr...))
}
}

Expand Down Expand Up @@ -83,7 +83,7 @@ func errorHandler(errs Errors, rw http.ResponseWriter) {
rw.WriteHeader(STATUS_UNPROCESSABLE_ENTITY)
}
errOutput, _ := json.Marshal(errs)
rw.Write(errOutput)
_, _ = rw.Write(errOutput)
return
}
}
Expand All @@ -103,11 +103,11 @@ func Bind(obj interface{}, ifacePtr ...interface{}) macaron.Handler {
return func(ctx *macaron.Context) {
bind(ctx, obj, ifacePtr...)
if handler, ok := obj.(ErrorHandler); ok {
ctx.Invoke(handler.Error)
_, _ = ctx.Invoke(handler.Error)
} else if CustomErrorHandler != nil {
ctx.Invoke(CustomErrorHandler)
_, _ = ctx.Invoke(CustomErrorHandler)
} else {
ctx.Invoke(errorHandler)
_, _ = ctx.Invoke(errorHandler)
}
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func MultipartForm(formStruct interface{}, ifacePtr ...interface{}) macaron.Hand
}

if ctx.Req.Form == nil {
ctx.Req.ParseForm()
_ = ctx.Req.ParseForm()
}
for k, v := range form.Value {
ctx.Req.Form[k] = append(ctx.Req.Form[k], v...)
Expand Down Expand Up @@ -284,8 +284,8 @@ func Validate(obj interface{}) macaron.Handler {
}

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

Expand Down Expand Up @@ -744,7 +744,7 @@ func ensureNotPointer(obj interface{}) {
// with errors from deserialization, then maps both the
// resulting struct and the errors to the context.
func validateAndMap(obj reflect.Value, ctx *macaron.Context, errors Errors, ifacePtr ...interface{}) {
ctx.Invoke(Validate(obj.Interface()))
_, _ = ctx.Invoke(Validate(obj.Interface()))
errors = append(errors, getErrors(ctx)...)
ctx.Map(errors)
ctx.Map(obj.Elem().Interface())
Expand Down
2 changes: 1 addition & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type (
Coauthor *Person `json:"coauthor"`
HeaderImage *multipart.FileHeader
Pictures []*multipart.FileHeader `form:"picture"`
unexported string `form:"unexported"`
unexported string `form:"unexported"` //nolint
}

EmbedPerson struct {
Expand Down
2 changes: 1 addition & 1 deletion errorhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func performErrorTest(t *testing.T, testCase errorTestCase) {

type (
errorTestCase struct {
description string
description string //nolint
errors Errors
expected errorTestResult
}
Expand Down
5 changes: 2 additions & 3 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ func buildRequestWithFile(testCase fileTestCase) *http.Request {
if err != nil {
panic("Could not create FormFile (single file): " + err.Error())
}
formFileSingle.Write([]byte(testCase.singleFile.data))
_, _ = formFileSingle.Write([]byte(testCase.singleFile.data))
}

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

err := w.Close()
Expand Down Expand Up @@ -179,7 +179,6 @@ func unpackFileHeaderData(fh *multipart.FileHeader) string {
type (
fileTestCase struct {
description string
input BlogPost
singleFile *fileInfo
multipleFiles []*fileInfo
}
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ gopkg.in/ini.v1 v1.46.0 h1:VeDZbLYGaupuvIrsYCEOe/L/2Pcs5n7hdO1ZTjporag=
gopkg.in/ini.v1 v1.46.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/macaron.v1 v1.3.4 h1:HvIscOwxhFhx3swWM/979wh2QMYyuXrNmrF9l+j3HZs=
gopkg.in/macaron.v1 v1.3.4/go.mod h1:/RoHTdC8ALpyJ3+QR36mKjwnT1F1dyYtsGM9Ate6ZFI=
gopkg.in/macaron.v1 v1.3.5 h1:FUA16VFBojxzfU75KqWrV/6BPv9O2R1GnybSGRie9QQ=
gopkg.in/macaron.v1 v1.3.5/go.mod h1:uMZCFccv9yr5TipIalVOyAyZQuOH3OkmXvgcWwhJuP4=
14 changes: 7 additions & 7 deletions multipart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ func makeMultipartPayload(testCase multipartFormTestCase) (*bytes.Buffer, *multi
body.Write([]byte(`--` + writer.Boundary() + `\nContent-Disposition: form-data; name="foo"\n\n--` + writer.Boundary() + `--`))
return body, writer
} else {
writer.WriteField("title", testCase.inputAndExpected.Title)
writer.WriteField("content", testCase.inputAndExpected.Content)
writer.WriteField("id", strconv.Itoa(testCase.inputAndExpected.Id))
writer.WriteField("ignored", testCase.inputAndExpected.Ignored)
_ = writer.WriteField("title", testCase.inputAndExpected.Title)
_ = writer.WriteField("content", testCase.inputAndExpected.Content)
_ = writer.WriteField("id", strconv.Itoa(testCase.inputAndExpected.Id))
_ = writer.WriteField("ignored", testCase.inputAndExpected.Ignored)
for _, value := range testCase.inputAndExpected.Ratings {
writer.WriteField("rating", strconv.Itoa(value))
_ = writer.WriteField("rating", strconv.Itoa(value))
}
writer.WriteField("name", testCase.inputAndExpected.Author.Name)
writer.WriteField("email", testCase.inputAndExpected.Author.Email)
_ = writer.WriteField("name", testCase.inputAndExpected.Author.Name)
_ = writer.WriteField("email", testCase.inputAndExpected.Author.Email)
return body, writer
}
}
Expand Down

0 comments on commit 735334c

Please sign in to comment.