Skip to content

Commit

Permalink
Merge pull request #307 from ayuryshev/feature/move-metrics-and-httpu…
Browse files Browse the repository at this point in the history
…til-into-pkg-306

Feature/move metrics and httputil into ./pkg/
  • Loading branch information
ayuryshev authored Apr 25, 2019
2 parents 9e01265 + 7c592fb commit e0a77f0
Show file tree
Hide file tree
Showing 24 changed files with 1,359 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/setup-node/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"

"github.com/skycoin/skywire/internal/metrics"
"github.com/skycoin/skywire/pkg/metrics"
"github.com/skycoin/skywire/pkg/setup"
)

Expand Down
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/setup/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"log"
"time"

"github.com/skycoin/skywire/internal/metrics"
"github.com/skycoin/skywire/pkg/metrics"

"github.com/skycoin/skycoin/src/util/logging"

Expand Down
2 changes: 1 addition & 1 deletion pkg/setup/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/skycoin/skywire/internal/metrics"
"github.com/skycoin/skywire/pkg/metrics"

"github.com/skycoin/skycoin/src/util/logging"
"github.com/stretchr/testify/assert"
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.

Loading

0 comments on commit e0a77f0

Please sign in to comment.