Skip to content

Commit 467f62a

Browse files
committed
Add initial project files including funding, CI, and example middleware
- Create FUNDING.yml for funding model support - Add dependabot.yml for automated dependency updates - Implement test coverage workflow in test-coverage.yml - Establish .gitignore for build artifacts and IDE settings - Create README.md with project overview and usage instructions - Add example middleware implementation in example.go - Implement tests for example middleware in example_test.go - Set up basic example application in examples/basic - Update go.mod and go.sum for dependencies - Add coverage script for running tests with coverage
0 parents  commit 467f62a

File tree

13 files changed

+409
-0
lines changed

13 files changed

+409
-0
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
patreon: meshin

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "gomod"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
12+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
go: ["1.22.x", "1.23.x", "stable"]
15+
permissions:
16+
contents: read
17+
id-token: write
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: ${{ matrix.go }}
26+
check-latest: true
27+
cache: true
28+
29+
- name: Download dependencies
30+
run: go mod download
31+
32+
- name: Run tests (no coverage)
33+
if: matrix.go != 'stable'
34+
run: |
35+
go test $(go list ./... | grep -v "/examples/") -v -race
36+
37+
- name: Run tests with coverage
38+
if: matrix.go == 'stable'
39+
run: |
40+
go test $(go list ./... | grep -v "/examples/") -v -race -covermode=atomic -coverprofile=coverage.out
41+
42+
- name: Upload coverage artifact
43+
if: matrix.go == 'stable'
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: coverage
47+
path: coverage.out
48+
49+
- name: Upload coverage to Codecov
50+
if: matrix.go == 'stable'
51+
uses: codecov/codecov-action@v5
52+
with:
53+
token: ${{ secrets.CODECOV_TOKEN }}
54+
files: coverage.out
55+
flags: unittests
56+
verbose: true
57+
disable_search: true
58+
fail_ci_if_error: false

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Go build artifacts
2+
*.a
3+
*.o
4+
5+
# Compiled binaries and shared objects
6+
*.exe
7+
*.exe~
8+
*.dll
9+
*.so
10+
*.dylib
11+
12+
# Test binaries and coverage/profiles
13+
*.test
14+
*.out
15+
*.cover
16+
*.cov
17+
coverage.out
18+
cover.out
19+
profile.out
20+
*.prof
21+
*.pprof
22+
cpu.profile
23+
mem.profile
24+
trace.out
25+
26+
# Build/output directories
27+
build/
28+
dist/
29+
out/
30+
tmp/
31+
coverage/
32+
33+
# Logs
34+
*.log
35+
36+
# IDE/editor settings
37+
.vscode/
38+
.idea/
39+
*.iml
40+
41+
# Editor swap/backup files
42+
*.swp
43+
*.swo
44+
*~
45+
46+
# macOS
47+
.DS_Store
48+
.AppleDouble
49+
.LSOverride
50+
Icon?
51+
.Spotlight-V100
52+
.Trashes
53+
._*
54+
55+
# Env files (keep examples)
56+
.env
57+
.env.*
58+
!.env.example
59+
60+
# Dependencies (uncomment if you do NOT commit vendor)
61+
vendor/
62+
tmp/

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Example middleware template for the GoFlash web framework
2+
3+
<h1 align="center">
4+
<a href="https://pkg.go.dev/github.com/goflash/example-template/v2@v2.0.0">
5+
<img src="https://pkg.go.dev/badge/github.com/goflash/example-template.svg" alt="Go Reference">
6+
</a>
7+
<a href="https://goreportcard.com/report/github.com/goflash/example-template">
8+
<img src="https://img.shields.io/badge/%F0%9F%93%9D%20Go%20Report-A%2B-75C46B?style=flat-square" alt="Go Report Card">
9+
</a>
10+
<a href="https://codecov.io/gh/goflash/example-template">
11+
<img src="https://codecov.io/gh/goflash/example-template/graph/badge.svg?token=VRHM48HJ5L" alt="Coverage">
12+
</a>
13+
<a href="https://github.com/goflash/example-template/actions?query=workflow%3ATest">
14+
<img src="https://img.shields.io/github/actions/workflow/status/goflash/example-template/test-coverage.yml?branch=main&label=%F0%9F%A7%AA%20Tests&style=flat-square&color=75C46B" alt="Tests">
15+
</a>
16+
<img src="https://img.shields.io/badge/go-1.23%2B-00ADD8?logo=golang" alt="Go Version">
17+
<a href="https://docs.goflash.dev">
18+
<img src="https://img.shields.io/badge/%F0%9F%92%A1%20GoFlash-docs-00ACD7.svg?style=flat-square" alt="GoFlash Docs">
19+
</a>
20+
<img src="https://img.shields.io/badge/status-stable-green" alt="Status">
21+
<img src="https://img.shields.io/badge/license-MIT-blue" alt="License">
22+
<br>
23+
<div style="text-align:center">
24+
<a href="https://discord.gg/QHhGHtjjQG">
25+
<img src="https://dcbadge.limes.pink/api/server/https://discord.gg/QHhGHtjjQG" alt="Discord">
26+
</a>
27+
</div>
28+
</h1>
29+
30+
## Features
31+
32+
- Minimal example middleware (`ExampleMiddleware`) showing the pattern
33+
- Runnable example app under `examples/basic`
34+
- Go module with Go 1.23 toolchain
35+
- Ready to copy/fork for new middleware in the GoFlash ecosystem
36+
37+
## Installation
38+
39+
```sh
40+
go get github.com/goflash/example-template
41+
```
42+
43+
Go version: requires Go 1.23+. The module sets `go 1.23` and can be used with newer Go versions.
44+
45+
## Quick start
46+
47+
This is the minimal usage from `examples/basic`:
48+
49+
```go
50+
package main
51+
52+
import (
53+
"log"
54+
"net/http"
55+
56+
"github.com/goflash/example-template"
57+
"github.com/goflash/flash/v2"
58+
)
59+
60+
func main() {
61+
app := flash.New()
62+
63+
// Use the example middleware
64+
app.Use(example.ExampleMiddleware)
65+
66+
// Define a simple route
67+
app.GET("/", func(c flash.Ctx) error {
68+
return c.String(http.StatusOK, "ok")
69+
})
70+
71+
log.Fatal(http.ListenAndServe(":8080", app))
72+
}
73+
```
74+
75+
## Configuration
76+
77+
This template doesn’t prescribe configuration. Customize the middleware to your needs by editing `ExampleMiddleware` (or replacing it with your own). A typical middleware should:
78+
79+
- Accept and return a `flash.Handler`
80+
- Optionally read/write values on the request context
81+
- Call `next(c)` to pass control to the next handler
82+
83+
## Examples
84+
85+
- `examples/basic`: minimal setup showing how to plug the middleware into a GoFlash app and serve a simple route.
86+
87+
Run the example locally:
88+
89+
```sh
90+
cd examples/basic
91+
go run .
92+
```
93+
94+
Then in another shell:
95+
96+
```sh
97+
curl -s localhost:8080/
98+
```
99+
100+
## Testing
101+
102+
Run tests with coverage:
103+
104+
```sh
105+
./scripts/coverage.sh
106+
```
107+
108+
## Versioning and compatibility
109+
110+
- Module path: `github.com/goflash/example-template`
111+
- Requires Go 1.23+
112+
113+
## Contributing
114+
115+
Issues and PRs are welcome. Please run tests before submitting.
116+
117+
## License
118+
119+
MIT

example.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package example
2+
3+
import (
4+
"github.com/goflash/flash/v2"
5+
"github.com/goflash/flash/v2/ctx"
6+
)
7+
8+
// ExampleMiddleware is an example of a middleware function.
9+
func ExampleMiddleware(next flash.Handler) flash.Handler {
10+
return func(c flash.Ctx) error {
11+
l := ctx.LoggerFromContext(c.Context())
12+
l.Info("ExampleMiddleware: before next")
13+
return next(c)
14+
}
15+
}

example_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package example
2+
3+
import (
4+
"io"
5+
"net/http"
6+
"net/http/httptest"
7+
"testing"
8+
9+
"github.com/goflash/flash/v2"
10+
)
11+
12+
func TestExampleMiddleware(t *testing.T) {
13+
app := flash.New()
14+
15+
called := 0
16+
17+
// Register middleware under test
18+
app.Use(ExampleMiddleware)
19+
20+
// Register a simple handler to verify next() is called
21+
app.GET("/", func(c flash.Ctx) error {
22+
called++
23+
return c.String(http.StatusOK, "ok")
24+
})
25+
26+
// Perform request
27+
req := httptest.NewRequest(http.MethodGet, "/", nil)
28+
rec := httptest.NewRecorder()
29+
app.ServeHTTP(rec, req)
30+
31+
// Assertions
32+
if rec.Code != http.StatusOK {
33+
t.Fatalf("unexpected status: %d", rec.Code)
34+
}
35+
body, _ := io.ReadAll(rec.Body)
36+
if string(body) != "ok" {
37+
t.Fatalf("unexpected body: %q", string(body))
38+
}
39+
if called != 1 {
40+
t.Fatalf("handler should be called once, got %d", called)
41+
}
42+
}

examples/basic/go.mod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module example-basic
2+
3+
go 1.23.0
4+
5+
toolchain go1.23.2
6+
7+
// Using local middleware codebase in local examples
8+
replace github.com/goflash/example-template => ../..
9+
10+
require (
11+
github.com/goflash/example-template v0.0.0-00010101000000-000000000000
12+
github.com/goflash/flash/v2 v2.0.0-beta.6
13+
)
14+
15+
require (
16+
github.com/julienschmidt/httprouter v1.3.0 // indirect
17+
github.com/mitchellh/mapstructure v1.5.0 // indirect
18+
)

examples/basic/go.sum

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/goflash/flash/v2 v2.0.0-beta.6 h1:9loGJuTff7nVOYINMgTqc4B/hGWRvqY6s7AYDtRafn4=
4+
github.com/goflash/flash/v2 v2.0.0-beta.6/go.mod h1:pyi7JpzMj8Qoa9YniuCiJMbsaLO5sw1jgz/9JI9/+kM=
5+
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
6+
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
7+
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
8+
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
9+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
12+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
13+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
14+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

examples/basic/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/http"
6+
7+
"github.com/goflash/example-template"
8+
"github.com/goflash/flash/v2"
9+
)
10+
11+
func main() {
12+
app := flash.New()
13+
14+
// Use the example middleware
15+
app.Use(example.ExampleMiddleware)
16+
17+
// Define a simple route
18+
app.GET("/", func(c flash.Ctx) error {
19+
return c.String(http.StatusOK, "ok")
20+
})
21+
22+
log.Fatal(http.ListenAndServe(":8080", app))
23+
}

0 commit comments

Comments
 (0)