Skip to content

Commit 74b3a47

Browse files
authored
Merge branch 'main' into configure-encoder
2 parents bc4ef3f + 5fca2dc commit 74b3a47

16 files changed

+227
-133
lines changed

.circleci/config.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; https://editorconfig.org/
2+
3+
root = true
4+
5+
[*]
6+
insert_final_newline = true
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
indent_style = space
10+
indent_size = 2
11+
12+
[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
13+
indent_style = tab
14+
indent_size = 4
15+
16+
[*.md]
17+
indent_size = 4
18+
trim_trailing_whitespace = false
19+
20+
eclint_indent_style = unset

.github/release-drafter.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/stale.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/issues.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add issues or pull-requests created to the project.
2+
name: Add issue or pull request to Project
3+
4+
on:
5+
issues:
6+
types:
7+
- opened
8+
pull_request_target:
9+
types:
10+
- opened
11+
- reopened
12+
13+
jobs:
14+
add-to-project:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Add issue to project
18+
uses: actions/[email protected]
19+
with:
20+
project-url: https://github.com/orgs/gorilla/projects/4
21+
github-token: ${{ secrets.ADD_TO_PROJECT_TOKEN }}

.github/workflows/test.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
verify-and-test:
15+
strategy:
16+
matrix:
17+
go: ['1.19','1.20']
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
fail-fast: true
20+
runs-on: ${{ matrix.os }}
21+
steps:
22+
- name: Checkout Code
23+
uses: actions/checkout@v3
24+
25+
- name: Setup Go ${{ matrix.go }}
26+
uses: actions/setup-go@v4
27+
with:
28+
go-version: ${{ matrix.go }}
29+
cache: false
30+
31+
- name: Run GolangCI-Lint
32+
uses: golangci/golangci-lint-action@v3
33+
with:
34+
version: v1.53
35+
args: --timeout=5m
36+
37+
- name: Run GoSec
38+
if: matrix.os == 'ubuntu-latest'
39+
uses: securego/gosec@master
40+
with:
41+
args: ./...
42+
43+
- name: Run GoVulnCheck
44+
uses: golang/govulncheck-action@v1
45+
with:
46+
go-version-input: ${{ matrix.go }}
47+
go-package: ./...
48+
49+
- name: Run Tests
50+
run: go test -race -cover -coverprofile=coverage -covermode=atomic -v ./...
51+
52+
- name: Upload coverage to Codecov
53+
uses: codecov/codecov-action@v3
54+
with:
55+
files: ./coverage

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage.coverprofile

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
1+
Copyright (c) 2023 The Gorilla Authors. All rights reserved.
22

33
Redistribution and use in source and binary forms, with or without
44
modification, are permitted provided that the following conditions are

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
GO_LINT=$(shell which golangci-lint 2> /dev/null || echo '')
2+
GO_LINT_URI=github.com/golangci/golangci-lint/cmd/golangci-lint@latest
3+
4+
GO_SEC=$(shell which gosec 2> /dev/null || echo '')
5+
GO_SEC_URI=github.com/securego/gosec/v2/cmd/gosec@latest
6+
7+
GO_VULNCHECK=$(shell which govulncheck 2> /dev/null || echo '')
8+
GO_VULNCHECK_URI=golang.org/x/vuln/cmd/govulncheck@latest
9+
10+
.PHONY: golangci-lint
11+
golangci-lint:
12+
$(if $(GO_LINT), ,go install $(GO_LINT_URI))
13+
@echo "##### Running golangci-lint"
14+
golangci-lint run -v
15+
16+
.PHONY: gosec
17+
gosec:
18+
$(if $(GO_SEC), ,go install $(GO_SEC_URI))
19+
@echo "##### Running gosec"
20+
gosec ./...
21+
22+
.PHONY: govulncheck
23+
govulncheck:
24+
$(if $(GO_VULNCHECK), ,go install $(GO_VULNCHECK_URI))
25+
@echo "##### Running govulncheck"
26+
govulncheck ./...
27+
28+
.PHONY: verify
29+
verify: golangci-lint gosec govulncheck
30+
31+
.PHONY: test
32+
test:
33+
@echo "##### Running tests"
34+
go test -race -cover -coverprofile=coverage.coverprofile -covermode=atomic -v ./...

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
schema
2-
======
3-
[![GoDoc](https://godoc.org/github.com/gorilla/schema?status.svg)](https://godoc.org/github.com/gorilla/schema)
4-
[![CircleCI](https://circleci.com/gh/gorilla/mux.svg?style=svg)](https://circleci.com/gh/gorilla/schema)
5-
[![Sourcegraph](https://sourcegraph.com/github.com/gorilla/schema/-/badge.svg)](https://sourcegraph.com/github.com/gorilla/schema?badge)
1+
# gorilla/schema
62

3+
![testing](https://github.com/gorilla/schema/actions/workflows/test.yml/badge.svg)
4+
[![codecov](https://codecov.io/github/gorilla/schema/branch/main/graph/badge.svg)](https://codecov.io/github/gorilla/schema)
5+
[![godoc](https://godoc.org/github.com/gorilla/schema?status.svg)](https://godoc.org/github.com/gorilla/schema)
6+
[![sourcegraph](https://sourcegraph.com/github.com/gorilla/schema/-/badge.svg)](https://sourcegraph.com/github.com/gorilla/schema?badge)
7+
8+
9+
![Gorilla Logo](https://github.com/gorilla/.github/assets/53367916/d92caabf-98e0-473e-bfbf-ab554ba435e5)
710

811
Package gorilla/schema converts structs to and from form values.
912

cache.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"sync"
1313
)
1414

15-
var invalidPath = errors.New("schema: invalid path")
15+
var errInvalidPath = errors.New("schema: invalid path")
1616

1717
// newCache returns a new cache.
1818
func newCache() *cache {
@@ -53,13 +53,13 @@ func (c *cache) parsePath(p string, t reflect.Type) ([]pathPart, error) {
5353
keys := strings.Split(p, ".")
5454
for i := 0; i < len(keys); i++ {
5555
if t.Kind() != reflect.Struct {
56-
return nil, invalidPath
56+
return nil, errInvalidPath
5757
}
5858
if struc = c.get(t); struc == nil {
59-
return nil, invalidPath
59+
return nil, errInvalidPath
6060
}
6161
if field = struc.get(keys[i]); field == nil {
62-
return nil, invalidPath
62+
return nil, errInvalidPath
6363
}
6464
// Valid field. Append index.
6565
path = append(path, field.name)
@@ -72,10 +72,10 @@ func (c *cache) parsePath(p string, t reflect.Type) ([]pathPart, error) {
7272
// So checking i+2 is not necessary anymore.
7373
i++
7474
if i+1 > len(keys) {
75-
return nil, invalidPath
75+
return nil, errInvalidPath
7676
}
7777
if index64, err = strconv.ParseInt(keys[i], 10, 0); err != nil {
78-
return nil, invalidPath
78+
return nil, errInvalidPath
7979
}
8080
parts = append(parts, pathPart{
8181
path: path,

decoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (d *Decoder) decode(v reflect.Value, path string, parts []pathPart, values
197197
if v.Type().Kind() == reflect.Struct {
198198
for i := 0; i < v.NumField(); i++ {
199199
field := v.Field(i)
200-
if field.Type().Kind() == reflect.Ptr && field.IsNil() && v.Type().Field(i).Anonymous == true {
200+
if field.Type().Kind() == reflect.Ptr && field.IsNil() && v.Type().Field(i).Anonymous {
201201
field.Set(reflect.New(field.Type().Elem()))
202202
}
203203
}

0 commit comments

Comments
 (0)