Skip to content

Commit

Permalink
header: move from internal to pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed May 27, 2023
1 parent 87f8ad7 commit 2545817
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 71 deletions.
2 changes: 1 addition & 1 deletion pkg/authn/authn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package authn
import (
"net/http"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// Authenticator middleware
Expand Down
2 changes: 1 addition & 1 deletion pkg/authn/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"net/url"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/authn/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"net/url"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
"github.com/moonrhythm/parapet/pkg/internal/pool"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/compress/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"sync"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// Compress is the compress middleware
Expand Down
2 changes: 1 addition & 1 deletion pkg/cors/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// New creates new default cors middleware for public api
Expand Down
56 changes: 0 additions & 56 deletions pkg/internal/header/header.go → pkg/header/const.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package header

import (
"net/http"
)

// Headers in canonical format
const (
AcceptEncoding = "Accept-Encoding"
Expand Down Expand Up @@ -34,55 +30,3 @@ const (
XRealIP = "X-Real-Ip"
XRequestID = "X-Request-Id"
)

func AddIfNotExists(h http.Header, key, value string) {
for _, v := range h[key] {
if v == value {
return
}
}
h[key] = append(h[key], value)
}

func Get(h http.Header, key string) string {
if h == nil {
return ""
}
v := h[key]
if len(v) == 0 {
return ""
}
return v[0]
}

func Exists(h http.Header, key string) bool {
if h == nil {
return false
}
v := h[key]
if len(v) == 0 {
return false
}
return v[0] != ""
}

func Del(h http.Header, key string) {
if h == nil {
return
}
delete(h, key)
}

func Set(h http.Header, key, value string) {
if h == nil {
return
}
h[key] = []string{value}
}

func Add(h http.Header, key, value string) {
if h == nil {
return
}
h[key] = append(h[key], value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

func TestHeaders(t *testing.T) {
Expand Down
57 changes: 57 additions & 0 deletions pkg/header/header.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package header

import (
"net/http"
)

func AddIfNotExists(h http.Header, key, value string) {
for _, v := range h[key] {
if v == value {
return
}
}
h[key] = append(h[key], value)
}

func Get(h http.Header, key string) string {
if h == nil {
return ""
}
v := h[key]
if len(v) == 0 {
return ""
}
return v[0]
}

func Exists(h http.Header, key string) bool {
if h == nil {
return false
}
v := h[key]
if len(v) == 0 {
return false
}
return v[0] != ""
}

func Del(h http.Header, key string) {
if h == nil {
return
}
delete(h, key)
}

func Set(h http.Header, key, value string) {
if h == nil {
return
}
h[key] = []string{value}
}

func Add(h http.Header, key, value string) {
if h == nil {
return
}
h[key] = append(h[key], value)
}
2 changes: 1 addition & 1 deletion pkg/hsts/hsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"time"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// HSTS middleware
Expand Down
2 changes: 1 addition & 1 deletion pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"os"
"time"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// Logger middleware
Expand Down
2 changes: 1 addition & 1 deletion pkg/ratelimit/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// New creates new rate limiter
Expand Down
2 changes: 1 addition & 1 deletion pkg/redirect/https.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package redirect
import (
"net/http"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// HTTPS creates new https redirector
Expand Down
2 changes: 1 addition & 1 deletion pkg/redirect/nonwww.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"strings"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// NonWWW creates new non www redirector
Expand Down
2 changes: 1 addition & 1 deletion pkg/redirect/www.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"strings"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// WWW creates new www redirector
Expand Down
2 changes: 1 addition & 1 deletion pkg/requestid/requestid.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gofrs/uuid"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
"github.com/moonrhythm/parapet/pkg/logger"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/stackdriver/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.opencensus.io/trace/propagation"
"google.golang.org/api/option"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

// NewTrace creates new stack driver trace middleware
Expand Down
2 changes: 1 addition & 1 deletion pkg/upstream/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"golang.org/x/net/http2"

"github.com/moonrhythm/parapet/pkg/internal/header"
"github.com/moonrhythm/parapet/pkg/header"
)

const (
Expand Down

0 comments on commit 2545817

Please sign in to comment.