update to go-kit 0.4.0

This commit is contained in:
Victor Vrantchan
2017-03-17 19:10:32 +00:00
parent 75cc15e787
commit e6fa0b464f
11 changed files with 30 additions and 55 deletions

View File

@@ -1,6 +1,7 @@
package command
import (
"context"
"errors"
"fmt"
"net/http"
@@ -10,7 +11,6 @@ import (
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/metrics"
"github.com/micromdm/mdm"
"golang.org/x/net/context"
)
var errEmptyRequest = errors.New("request must contain UDID of the device")

View File

@@ -1,13 +1,13 @@
package command
import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
httptransport "github.com/go-kit/kit/transport/http"
"golang.org/x/net/context"
)
type HTTPHandlers struct {
@@ -17,7 +17,6 @@ type HTTPHandlers struct {
func MakeHTTPHandlers(ctx context.Context, endpoints Endpoints, opts ...httptransport.ServerOption) HTTPHandlers {
h := HTTPHandlers{
NewCommandHandler: httptransport.NewServer(
ctx,
endpoints.NewCommandEndpoint,
decodeRequest,
encodeResponse,
@@ -39,24 +38,9 @@ type statuser interface {
// The EncodeError should be passed to the Go-Kit httptransport as the
// ServerErrorEncoder to encode error responses with JSON.
func EncodeError(ctx context.Context, err error, w http.ResponseWriter) {
// unwrap Go-Kit Error
var domain string
if e, ok := err.(httptransport.Error); ok {
err = e.Err
domain = e.Domain
}
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
switch domain {
case httptransport.DomainDecode:
w.WriteHeader(http.StatusBadRequest)
case httptransport.DomainDo:
w.WriteHeader(http.StatusServiceUnavailable)
default:
w.WriteHeader(codeFromErr(err))
}
enc.Encode(map[string]interface{}{
"error": err.Error(),
})