Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick0308 committed Oct 4, 2023
1 parent f393ddc commit d65aa42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ linters-settings:

linters:
enable-all: true
ignore-underscore-vars: true
disable:
- deadcode # deprecated
- exhaustivestruct # deprecated
Expand Down
18 changes: 7 additions & 11 deletions max_age.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ func CreateConfig() *Config {
return &Config{}
}

type ResponseWriterWrapper struct {
type responseWriterWrapper struct {
http.ResponseWriter
cookieName string
maxAge int
}

func (rww ResponseWriterWrapper) Header() http.Header {
func (rww responseWriterWrapper) Header() http.Header {
return rww.ResponseWriter.Header()
}

func (rww ResponseWriterWrapper) WriteHeader(code int) {
func (rww responseWriterWrapper) WriteHeader(code int) {
if rww.cookieName != "" {
res := http.Response{Header: rww.ResponseWriter.Header()}
cookies := res.Cookies()
Expand All @@ -40,23 +40,19 @@ func (rww ResponseWriterWrapper) WriteHeader(code int) {
rww.ResponseWriter.WriteHeader(code)
}

func (rww ResponseWriterWrapper) Write(b []byte) (int, error) {
func (rww responseWriterWrapper) Write(b []byte) (int, error) {
return rww.ResponseWriter.Write(b)
}

type HeaderWrapper http.Header

func (h HeaderWrapper) Add(key, value string) {
h.Add(key, value)
}

// SessionMaxAge is a middleware for traefik middlware plugin to set cookie max age
type SessionMaxAge struct {
next http.Handler
cookieName string
maxAge int
name string
}

// New return a wrapped http.Handler
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) {
return &SessionMaxAge{
next: next,
Expand All @@ -67,5 +63,5 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
}

func (a *SessionMaxAge) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
a.next.ServeHTTP(ResponseWriterWrapper{ResponseWriter: rw, cookieName: a.cookieName, maxAge: a.maxAge}, req)
a.next.ServeHTTP(responseWriterWrapper{ResponseWriter: rw, cookieName: a.cookieName, maxAge: a.maxAge}, req)
}

0 comments on commit d65aa42

Please sign in to comment.