Skip to content

Commit c80ee64

Browse files
Version 2 - Generics Support (#2)
* update to Go v1.18 * replace interface{} with any
1 parent 9017546 commit c80ee64

16 files changed

+29
-29
lines changed

.devcontainer/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/go/.devcontainer/base.Dockerfile
22

3-
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.16, 1.17, 1-bullseye, 1.16-bullseye, 1.17-bullseye, 1-buster, 1.16-buster, 1.17-buster
4-
ARG VARIANT="1.17-bullseye"
3+
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.17, 1.18, 1-bullseye, 1.17-bullseye, 1.18-bullseye, 1-buster, 1.17-buster, 1.18-buster
4+
ARG VARIANT="1.18-bullseye"
55
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}
66

77
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10

.devcontainer/devcontainer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"build": {
66
"dockerfile": "Dockerfile",
77
"args": {
8-
// Update the VARIANT arg to pick a version of Go: 1, 1.16, 1.17
8+
// Update the VARIANT arg to pick a version of Go: 1, 1.17, 1.18
99
// Append -bullseye or -buster to pin to an OS version.
1010
// Use -bullseye variants on local arm64/Apple Silicon.
11-
"VARIANT": "1.17-bullseye",
11+
"VARIANT": "1.18-bullseye",
1212
}
1313
},
1414
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ on:
99
jobs:
1010

1111
build:
12-
name: Build
12+
name: Build & Test
1313
runs-on: ubuntu-latest
1414
steps:
1515

1616
- name: Set up Go 1.x
1717
uses: actions/setup-go@v2
1818
with:
19-
go-version: ^1.17
19+
go-version: ^1.18
2020
id: go
2121

2222
- name: Check out code into the Go module directory

app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func New(configure ...func(*Config)) (app *App) {
2323
app = &App{
2424
router: NewRouter(),
2525
pool: sync.Pool{
26-
New: func() interface{} {
26+
New: func() any {
2727
return &Context{App: app}
2828
},
2929
},

assert.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
)
77

8-
func isNil(i interface{}) bool {
8+
func isNil(i any) bool {
99
if i == nil {
1010
return true
1111
}
@@ -25,27 +25,27 @@ func isNil(i interface{}) bool {
2525
return false
2626
}
2727

28-
func assertNil(t *testing.T, actual interface{}) {
28+
func assertNil(t *testing.T, actual any) {
2929
if !isNil(actual) {
3030
t.Errorf("Test %s: Expected value to be nil, Received `%v` (type %v)", t.Name(), actual, reflect.TypeOf(actual))
3131
}
3232
}
3333

34-
func assertNotNil(t *testing.T, actual interface{}) {
34+
func assertNotNil(t *testing.T, actual any) {
3535
if isNil(actual) {
3636
t.Errorf("Test %s: Expected value to not be nil, Received `%v` (type %v)", t.Name(), actual, reflect.TypeOf(actual))
3737
}
3838
}
3939

40-
func assertEqual(t *testing.T, expected, actual interface{}) {
40+
func assertEqual(t *testing.T, expected, actual any) {
4141
if (isNil(expected) && isNil(actual)) || reflect.DeepEqual(expected, actual) {
4242
return
4343
}
4444

4545
t.Errorf("Test %s: Expected `%v` (type %v), Received `%v` (type %v)", t.Name(), expected, reflect.TypeOf(expected), actual, reflect.TypeOf(actual))
4646
}
4747

48-
func assertPanic(t *testing.T, expected interface{}, f func()) {
48+
func assertPanic(t *testing.T, expected any, f func()) {
4949
defer func() {
5050
if r := recover(); r == nil || r != expected {
5151
t.Errorf("Test %s: Expected Panic `%v` (type %v), Received Panic `%v` (type %v)", t.Name(), expected, reflect.TypeOf(expected), r, reflect.TypeOf(r))

assert_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
func TestAssertNil(t *testing.T) {
99
assertNil(t, nil)
1010

11-
i := (*interface{})(nil)
11+
i := (*any)(nil)
1212
assertNil(t, i)
1313

1414
var s []int
@@ -41,7 +41,7 @@ func TestAssertNotNil(t *testing.T) {
4141
func TestAssertEqualNil(t *testing.T) {
4242
assertEqual(t, nil, nil)
4343

44-
i := (*interface{})(nil)
44+
i := (*any)(nil)
4545
assertEqual(t, i, i)
4646

4747
var s []int

context.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (c *Context) Error(code int) (err error) {
198198
// Errorf dispatches a error response with custom message.
199199
// Use the method parameter `code` to set status code of the response.
200200
// Use the method parameter `message` to set the message of the response.
201-
func (c *Context) Errorf(code int, message interface{}) (err error) {
201+
func (c *Context) Errorf(code int, message any) (err error) {
202202
msg := fmt.Sprintf("%v", message)
203203
err = &RequestError{Code: code, Message: msg}
204204
return
@@ -225,7 +225,7 @@ func (c *Context) NotFound() error {
225225
// Text dispatches a text response.
226226
// Use the method parameter `code` to set the header status code.
227227
// Use the method parameter `value` to supply the object to be serialized to text.
228-
func (c *Context) Text(code int, value interface{}) (err error) {
228+
func (c *Context) Text(code int, value any) (err error) {
229229
c.SetHeader(HeaderContentType, MIMETextPlain)
230230
c.WriteHeader(code)
231231
_, err = fmt.Fprint(c.Response, value)
@@ -235,15 +235,15 @@ func (c *Context) Text(code int, value interface{}) (err error) {
235235
// Json dispatches a JSON response.
236236
// Use the method parameter `code` to set the header status code.
237237
// Use the method parameter `value` to supply the object to be serialized to JSON.
238-
func (c *Context) Json(code int, value interface{}) (err error) {
238+
func (c *Context) Json(code int, value any) (err error) {
239239
c.SetHeader(HeaderContentType, MIMEApplicationJSON)
240240
c.WriteHeader(code)
241241
err = json.NewEncoder(c.Response).Encode(value)
242242
return
243243
}
244244

245245
// DecodeJSONBody decodes an object with a given interface from a JSON request body.
246-
func (c *Context) DecodeJSONBody(dst interface{}) error {
246+
func (c *Context) DecodeJSONBody(dst any) error {
247247

248248
// check that the the Content-Type header has the value application/json.
249249
if mt, _, err := c.ParseMediaType(); err != nil || !strings.HasPrefix(mt, MIMEApplicationJSON) {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/felix-kaestner/lungo
22

3-
go 1.16
3+
go 1.18

lungo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ const (
181181
)
182182

183183
type (
184-
// Map is a shorthand of type `map[string]interface{}`.
185-
Map map[string]interface{}
184+
// Map is a shorthand of type `map[string]any`.
185+
Map map[string]any
186186
)
187187

188188
// Common HTTP methods.

middleware/cors/cors_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/felix-kaestner/lungo"
1010
)
1111

12-
func assertEqual(t *testing.T, expected, actual interface{}) {
12+
func assertEqual(t *testing.T, expected, actual any) {
1313
if reflect.DeepEqual(expected, actual) {
1414
return
1515
}

middleware/logging/color.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ const (
2525

2626
// Sprintf colorizes the provided string by wrapping
2727
// it inside an ANSI color escape sequence
28-
func (c ColorCode) Sprintf(a interface{}) string {
28+
func (c ColorCode) Sprintf(a any) string {
2929
return fmt.Sprintf("\033[1;%dm%s\033[0m", c, a)
3030
}

middleware/logging/logging_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
const LogRegex = `^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} GET / ((\d*[.])?\d+)µs$`
1717

18-
func assertEqual(t *testing.T, expected, actual interface{}) {
18+
func assertEqual(t *testing.T, expected, actual any) {
1919
if reflect.DeepEqual(expected, actual) {
2020
return
2121
}

middleware/recover/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type Config struct {
66
// the stack trace of the panic.
77
//
88
// Optional. Default: nil
9-
HandleStackTrace func(e interface{})
9+
HandleStackTrace func(e any)
1010
}
1111

1212
// DefaultConfig contains the default value for the

middleware/recover/recover_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/felix-kaestner/lungo"
1010
)
1111

12-
func assertEqual(t *testing.T, expected, actual interface{}) {
12+
func assertEqual(t *testing.T, expected, actual any) {
1313
if reflect.DeepEqual(expected, actual) {
1414
return
1515
}
@@ -30,7 +30,7 @@ func TestRecover(t *testing.T) {
3030
},
3131
{
3232
middleware: New(func(c *Config) {
33-
c.HandleStackTrace = func(e interface{}) {
33+
c.HandleStackTrace = func(e any) {
3434
assertEqual(t, "Error", e)
3535
}
3636
}),

middleware/secure/secure_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/felix-kaestner/lungo"
1010
)
1111

12-
func assertEqual(t *testing.T, expected, actual interface{}) {
12+
func assertEqual(t *testing.T, expected, actual any) {
1313
if reflect.DeepEqual(expected, actual) {
1414
return
1515
}

middleware/template/template_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/felix-kaestner/lungo"
1010
)
1111

12-
func assertEqual(t *testing.T, expected, actual interface{}) {
12+
func assertEqual(t *testing.T, expected, actual any) {
1313
if reflect.DeepEqual(expected, actual) {
1414
return
1515
}

0 commit comments

Comments
 (0)