Skip to content

Commit

Permalink
internal/httputil -> pkg/httputil
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuryshev committed Apr 25, 2019
1 parent df4a4b0 commit 7c592fb
Show file tree
Hide file tree
Showing 19 changed files with 1,356 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6
github.com/go-chi/chi v4.0.2+incompatible
github.com/google/uuid v1.1.1
github.com/gorilla/handlers v1.4.0
github.com/gorilla/securecookie v1.1.1
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZsA=
github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
Expand Down
18 changes: 18 additions & 0 deletions internal/httputil/json.go → pkg/httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package httputil
import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"

"github.com/gorilla/handlers"
)

// WriteJSON writes a json object on a http.ResponseWriter with the given code,
Expand Down Expand Up @@ -43,3 +47,17 @@ func BoolFromQuery(r *http.Request, key string, defaultVal bool) (bool, error) {
return false, fmt.Errorf("invalid '%s' query value of '%s'", key, q)
}
}

// WriteLog writes request and response parameters using format that
// works well with logging.Logger.
func WriteLog(writer io.Writer, params handlers.LogFormatterParams) {
host, _, err := net.SplitHostPort(params.Request.RemoteAddr)
if err != nil {
host = params.Request.RemoteAddr
}

fmt.Fprintf(
writer, "%s - \"%s %s %s\" %d\n",
host, params.Request.Method, params.URL.String(), params.Request.Proto, params.StatusCode,
)
}
2 changes: 1 addition & 1 deletion pkg/manager/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"github.com/go-chi/chi/middleware"
"github.com/google/uuid"

"github.com/skycoin/skywire/internal/httputil"
"github.com/skycoin/skywire/internal/noise"
"github.com/skycoin/skywire/pkg/cipher"
"github.com/skycoin/skywire/pkg/httputil"
"github.com/skycoin/skywire/pkg/node"
"github.com/skycoin/skywire/pkg/routing"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/user_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/google/uuid"
"github.com/gorilla/securecookie"

"github.com/skycoin/skywire/internal/httputil"
"github.com/skycoin/skywire/pkg/httputil"
)

const (
Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/gorilla/handlers/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/gorilla/handlers/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions vendor/github.com/gorilla/handlers/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions vendor/github.com/gorilla/handlers/canonical.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

148 changes: 148 additions & 0 deletions vendor/github.com/gorilla/handlers/compress.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7c592fb

Please sign in to comment.