Skip to content

lint: fixing linter errs #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
- uses: actions/checkout@v4
with:
path: src/github.com/unrolled/secure
- uses: golangci/golangci-lint-action@v4
- uses: golangci/golangci-lint-action@v6
with:
working-directory: src/github.com/unrolled/secure
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ linters:
- maintidx
- contextcheck
- perfsprint
- exportloopref
4 changes: 2 additions & 2 deletions secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ type Options struct {
// AllowedHostsAreRegex determines, if the provided `AllowedHosts` slice contains valid regular expressions. If this flag is set to true, every request's host will be checked against these expressions. Default is false.
AllowedHostsAreRegex bool
// AllowRequestFunc is a custom function that allows you to determine if the request should proceed or not based on your own custom logic. Default is nil.
AllowRequestFunc AllowRequestFunc `json:"-" yaml:"-" toml:"-"`
AllowRequestFunc AllowRequestFunc `json:"-" toml:"-" yaml:"-"`
// HostsProxyHeaders is a set of header keys that may hold a proxied hostname value for the request.
HostsProxyHeaders []string
// SSLHostFunc is a function pointer, the return value of the function is the host name that has same functionality as `SSHost`. Default is nil.
// If SSLHostFunc is nil, the `SSLHost` option will be used.
SSLHostFunc *SSLHostFunc `json:"-" yaml:"-" toml:"-"`
SSLHostFunc *SSLHostFunc `json:"-" toml:"-" yaml:"-"`
// SSLProxyHeaders is set of header keys with associated values that would indicate a valid https request. Useful when using Nginx: `map[string]string{"X-Forwarded-Proto": "https"}`. Default is blank map.
SSLProxyHeaders map[string]string
// STSSeconds is the max-age of the Strict-Transport-Security header. Default is 0, which would NOT include the header.
Expand Down
28 changes: 4 additions & 24 deletions secure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,35 +1376,15 @@ func TestBadRequestHandler(t *testing.T) {
}

func TestMarshal(t *testing.T) {
// func cant be marshalled
var t1 = struct {
A string
F func()
}{}
_, err := json.Marshal(t1) //lint:ignore SA1026 ignore marshal error
if err == nil {
t.Error("expected error got none")
} else if !strings.Contains(err.Error(), "unsupported type: func()") {
t.Error("unexpected error:", err)
}

// struct field tags omits func
var t2 = struct {
A string
F func() `json:"-"`
}{}
_, err = json.Marshal(t2)
if err != nil {
t.Error("unexpected error:", err)
}

// Options has struct field tags to omit func fields
var o1 Options
b, err := json.Marshal(o1)

b, err := json.Marshal(o1) //nolint:musttag
if err != nil {
t.Errorf("unexpected error marshal: %v", err)
}
err = json.Unmarshal(b, &o1)

err = json.Unmarshal(b, &o1) //nolint:musttag
if err != nil {
t.Errorf("unexpected error unmarshal: %v", err)
}
Expand Down