Skip to content

Commit 716437c

Browse files
unknwonSourcegraph Bot
andauthored
ci: migrate from Travis to GitHub Actions (#7)
* ci: migrate from Travis to GitHub Actions * Fix lint errors Co-authored-by: Sourcegraph Bot <[email protected]>
1 parent dbc994d commit 716437c

File tree

5 files changed

+59
-19
lines changed

5 files changed

+59
-19
lines changed

.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/[email protected]
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 & 12 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-
# captcha [![Build Status](https://travis-ci.org/go-macaron/captcha.svg?branch=master)](https://travis-ci.org/go-macaron/captcha)
1+
# captcha
2+
3+
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/go-macaron/captcha/Go?logo=github&style=for-the-badge)](https://github.com/go-macaron/captcha/actions?query=workflow%3AGo)
4+
[![codecov](https://img.shields.io/codecov/c/github/go-macaron/captcha/master?logo=codecov&style=for-the-badge)](https://codecov.io/gh/go-macaron/captcha)
5+
[![GoDoc](https://img.shields.io/badge/GoDoc-Reference-blue?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/go-macaron/captcha?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/captcha)
27

38
Middleware captcha provides captcha service for [Macaron](https://github.com/go-macaron/macaron).
49

captcha.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"path"
2424
"strings"
2525

26-
"github.com/unknwon/com"
2726
"github.com/go-macaron/cache"
27+
"github.com/unknwon/com"
2828
"gopkg.in/macaron.v1"
2929
)
3030

@@ -91,7 +91,7 @@ func (c *Captcha) CreateCaptcha() (string, error) {
9191

9292
// verify from a request
9393
func (c *Captcha) VerifyReq(req macaron.Request) bool {
94-
req.ParseForm()
94+
_ = req.ParseForm()
9595
return c.Verify(req.Form.Get(c.FieldIdName), req.Form.Get(c.FieldCaptchaName))
9696
}
9797

@@ -111,7 +111,9 @@ func (c *Captcha) Verify(id string, challenge string) bool {
111111
return false
112112
}
113113

114-
defer c.store.Delete(key)
114+
defer func() {
115+
_ = c.store.Delete(key)
116+
}()
115117

116118
if len(chars) != len(challenge) {
117119
return false
@@ -227,15 +229,15 @@ func Captchaer(options ...Options) macaron.Handler {
227229
chars = cpt.genRandChars()
228230
if err := cpt.store.Put(key, chars, cpt.Expiration); err != nil {
229231
ctx.Status(500)
230-
ctx.Write([]byte("captcha reload error"))
232+
_, _ = ctx.Write([]byte("captcha reload error"))
231233
panic(fmt.Errorf("reload captcha: %v", err))
232234
}
233235
} else {
234236
if v, ok := cpt.store.Get(key).(string); ok {
235237
chars = v
236238
} else {
237239
ctx.Status(404)
238-
ctx.Write([]byte("captcha not found"))
240+
_, _ = ctx.Write([]byte("captcha not found"))
239241
return
240242
}
241243
}

image_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func BenchmarkImageWriteTo(b *testing.B) {
4646
counter := &byteCounter{}
4747
for i := 0; i < b.N; i++ {
4848
img := NewImage(d, stdWidth, stdHeight, color.Palette{})
49-
img.WriteTo(counter)
49+
_, _ = img.WriteTo(counter)
5050
b.SetBytes(counter.n)
5151
counter.n = 0
5252
}

0 commit comments

Comments
 (0)