Skip to content

Commit

Permalink
lint: fixing linter errs
Browse files Browse the repository at this point in the history
  • Loading branch information
unrolled committed Sep 27, 2024
1 parent dbf54fc commit 33e7665
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
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

0 comments on commit 33e7665

Please sign in to comment.