Skip to content

Commit 9390fff

Browse files
committed
feat: add extra feature
1 parent d723227 commit 9390fff

Some content is hidden

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

43 files changed

+3509
-0
lines changed

.github/dependabot.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
commit-message:
8+
prefix: "chore"
9+
include: "scope"
10+
11+
- package-ecosystem: "gomod"
12+
directory: "/"
13+
schedule:
14+
interval: "daily"
15+
commit-message:
16+
prefix: "chore"
17+
include: "scope"

.github/workflows/ci.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "**.md"
7+
pull_request:
8+
paths-ignore:
9+
- "**.md"
10+
11+
env:
12+
GO111MODULE: on
13+
GOPROXY: "https://proxy.golang.org"
14+
15+
jobs:
16+
build:
17+
name: Test on ${{ matrix.os }} @Go${{ matrix.go-version }}
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
matrix:
21+
go-version: ["1.24.x"]
22+
os: [ubuntu-latest, windows-latest, macos-latest]
23+
24+
steps:
25+
- name: Set up Go ${{ matrix.go-version }}
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: ${{ matrix.go-version }}
29+
cache: false
30+
31+
- name: Check out code into the Go module directory
32+
uses: actions/checkout@v4
33+
34+
- name: Print Go environment
35+
id: vars
36+
run: |
37+
printf "Using go at: $(which go)\n"
38+
printf "Go version: $(go version)\n"
39+
printf "\n\nGo environment:\n\n"
40+
go env
41+
printf "\n\nSystem environment:\n\n"
42+
env
43+
# Calculate the short SHA1 hash of the git commit
44+
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
45+
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
46+
47+
- name: Cache go modules
48+
uses: actions/cache@v4
49+
with:
50+
path: |
51+
${{ steps.vars.outputs.GO_CACHE }}
52+
~/go/pkg/mod
53+
key: ${{ runner.os }}-${{ matrix.go-version }}-go-ci-${{ hashFiles('**/go.sum') }}
54+
restore-keys: |
55+
${{ runner.os }}-${{ matrix.go-version }}-go-ci-
56+
57+
- name: Unit test
58+
run: |
59+
go test -v -race -coverprofile=coverage -covermode=atomic ./...
60+
61+
- name: Upload coverage to Codecov
62+
if: matrix.os == 'ubuntu-latest'
63+
uses: codecov/codecov-action@v5
64+
with:
65+
files: ./coverage
66+
flags: unittests
67+
token: ${{ secrets.CODECOV_TOKEN }}
68+
verbose: true

.github/workflows/codeql.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CodeQL
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "**.md"
7+
pull_request:
8+
paths-ignore:
9+
- "**.md"
10+
schedule:
11+
- cron: "0 5 * * 6"
12+
13+
jobs:
14+
analyze:
15+
name: Analyze
16+
runs-on: ubuntu-latest
17+
permissions:
18+
actions: read
19+
contents: read
20+
security-events: write
21+
22+
steps:
23+
# optionally use a specific version of Go rather than the default one
24+
- name: Set up Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: "1.24.x"
28+
- name: Check out code into the Go module directory
29+
uses: actions/checkout@v4
30+
with:
31+
# We must fetch at least the immediate parents so that if this is
32+
# a pull request then we can checkout the head.
33+
fetch-depth: 2
34+
35+
# Initializes the CodeQL tools for scanning.
36+
- name: Initialize CodeQL
37+
uses: github/codeql-action/init@v3
38+
39+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
40+
# If this step fails, then you should remove it and run the build manually (see below)
41+
- name: Autobuild
42+
uses: github/codeql-action/autobuild@v3
43+
44+
# ℹ️ Command-line programs to run using the OS shell.
45+
# 📚 https://git.io/JvXDl
46+
47+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
48+
# and modify them (or add more) to build your code if your project
49+
# uses a compiled language
50+
51+
#- run: |
52+
# make bootstrap
53+
# make release
54+
55+
- name: Perform CodeQL Analysis
56+
uses: github/codeql-action/analyze@v3

.github/workflows/lint.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "**.md"
7+
8+
jobs:
9+
golang-ci:
10+
name: GolangCi-Lint
11+
runs-on: ubuntu-latest
12+
steps:
13+
# optionally use a specific version of Go rather than the default one
14+
- name: Set up Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: "1.24.x"
18+
- name: Check out code into the Go module directory
19+
uses: actions/checkout@v4
20+
- name: Run golangci-lint
21+
uses: golangci/golangci-lint-action@v6
22+
with: # BUG: typecheck error when enable all
23+
args: --disable-all -E goimports,misspell,whitespace
24+
version: latest

.github/workflows/pr_review_dog.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Reviewdog
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- "**.md"
7+
8+
jobs:
9+
golangci-lint:
10+
name: runner / golangci-lint
11+
runs-on: ubuntu-latest
12+
steps:
13+
# optionally use a specific version of Go rather than the default one
14+
- name: Set up Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: "1.24.x"
18+
19+
- name: Check out code into the Go module directory
20+
uses: actions/checkout@v4
21+
22+
- name: golangci-lint
23+
uses: reviewdog/action-golangci-lint@v2
24+
with: # BUG: typecheck error when enable all
25+
args: --disable-all -E goimports,misspell,whitespace
26+
version: latest

.github/workflows/release.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
# run only against tags
6+
tags:
7+
- "*"
8+
9+
permissions:
10+
contents: write
11+
# packages: write
12+
# issues: write
13+
14+
jobs:
15+
goreleaser:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Check out code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- run: git fetch --force --tags
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: ">=1.24.0"
27+
cache: true
28+
# More assembly might be required: Docker logins, GPG, etc. It all depends
29+
# on your needs.
30+
- name: Release binary
31+
uses: goreleaser/goreleaser-action@v6
32+
with:
33+
# either 'goreleaser' (default) or 'goreleaser-pro':
34+
distribution: goreleaser
35+
version: latest
36+
args: release --clean
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro'
40+
# distribution:
41+
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# proc-extra
2+
3+
`proc-extra` Universal toolkit extra.
4+
5+
[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go&logoColor=white)](https://pkg.go.dev/github.com/things-go/proc-extra?tab=doc)
6+
[![codecov](https://codecov.io/gh/things-go/proc-extra/branch/main/graph/badge.svg)](https://codecov.io/gh/things-go/proc-extra)
7+
[![Tests](https://github.com/things-go/proc-extra/actions/workflows/ci.yml/badge.svg)](https://github.com/things-go/proc-extra/actions/workflows/ci.yml)
8+
[![Go Report Card](https://goreportcard.com/badge/github.com/things-go/proc-extra)](https://goreportcard.com/report/github.com/things-go/proc-extra)
9+
[![License](https://img.shields.io/github/license/things-go/proc-extra)](https://github.com/things-go/proc-extra/raw/main/LICENSE)
10+
[![Tag](https://img.shields.io/github/v/tag/things-go/proc-extra)](https://github.com/things-go/proc-extra/tags)

captcha/captcha.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package captcha
2+
3+
import (
4+
"github.com/mojocn/base64Captcha"
5+
"github.com/things-go/limiter/verified"
6+
)
7+
8+
var _ verified.CaptchaDriver = (*Captcha)(nil)
9+
10+
type Captcha struct {
11+
d base64Captcha.Driver
12+
}
13+
14+
func New(d base64Captcha.Driver) *Captcha {
15+
return &Captcha{
16+
d,
17+
}
18+
}
19+
20+
func (c *Captcha) Name() string { return "base64Captcha" }
21+
22+
func (c *Captcha) GenerateQuestionAnswer() (*verified.QuestionAnswer, error) {
23+
id, q, a := c.d.GenerateIdQuestionAnswer()
24+
it, err := c.d.DrawCaptcha(q)
25+
if err != nil {
26+
return nil, err
27+
}
28+
return &verified.QuestionAnswer{
29+
Id: id,
30+
Question: it.EncodeB64string(),
31+
Answer: a,
32+
}, nil
33+
}

0 commit comments

Comments
 (0)