Skip to content

Commit

Permalink
Merge pull request #2 from Comcast/feature/scytale-2.0
Browse files Browse the repository at this point in the history
Feature/scytale 2.0
  • Loading branch information
johnabass authored Sep 19, 2017
2 parents dc6f4b7 + 692c53c commit 1aa2641
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 574 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ src/vendor
+src/scytale/output

# config
-src/scytale/scytale.json
+src/scytale/scytale.json
+keys/*.private

src/scytale/scytale
src/scytale/debug
src/scytale/output

# config
src/scytale/scytale.json
keys/*.private

# Vim
Expand Down
129 changes: 54 additions & 75 deletions src/glide.lock

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

12 changes: 1 addition & 11 deletions src/glide.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
package: .
import:
- package: github.com/Comcast/webpa-common
subpackages:
- concurrent
- handler
- health
- logging
- secure
- server
- package: github.com/gorilla/mux
- package: github.com/justinas/alice
- package: github.com/spf13/pflag
- package: github.com/spf13/viper
version: 05094818a42ba3682b43c60c29a237d8e6995341
97 changes: 0 additions & 97 deletions src/scytale/http.go

This file was deleted.

72 changes: 72 additions & 0 deletions src/scytale/primaryHandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"fmt"
"net/http"

"github.com/Comcast/webpa-common/wrp"
"github.com/Comcast/webpa-common/wrp/wrphttp"
"github.com/go-kit/kit/log"
gokithttp "github.com/go-kit/kit/transport/http"
"github.com/gorilla/mux"
"github.com/spf13/viper"
)

const (
baseURI = "/api"
version = "v2"
)

func NewPrimaryHandler(logger log.Logger, v *viper.Viper) (http.Handler, error) {
fanoutOptions := new(wrphttp.FanoutOptions)
if err := v.UnmarshalKey("fanout", fanoutOptions); err != nil {
return nil, err
}

fanoutOptions.Logger = logger
fanoutEndpoint, err := wrphttp.NewFanoutEndpoint(fanoutOptions)
if err != nil {
return nil, err
}

var (
router = mux.NewRouter()
subrouter = router.Path(fmt.Sprintf("%s/%s/device", baseURI, version)).Methods("POST", "PUT").Subrouter()
timeLayout = ""
)

subrouter.Headers(wrphttp.MessageTypeHeader, "").Handler(
gokithttp.NewServer(
fanoutEndpoint,
wrphttp.ServerDecodeRequestHeaders(logger),
wrphttp.ServerEncodeResponseHeaders(timeLayout),
gokithttp.ServerErrorEncoder(
wrphttp.ServerErrorEncoder(timeLayout),
),
),
)

subrouter.Headers("Content-Type", wrp.JSON.ContentType()).Handler(
gokithttp.NewServer(
fanoutEndpoint,
wrphttp.ServerDecodeRequestBody(logger, fanoutOptions.NewDecoderPool(wrp.JSON)),
wrphttp.ServerEncodeResponseBody(timeLayout, fanoutOptions.NewEncoderPool(wrp.JSON)),
gokithttp.ServerErrorEncoder(
wrphttp.ServerErrorEncoder(timeLayout),
),
),
)

subrouter.Headers("Content-Type", wrp.Msgpack.ContentType()).Handler(
gokithttp.NewServer(
fanoutEndpoint,
wrphttp.ServerDecodeRequestBody(logger, fanoutOptions.NewDecoderPool(wrp.Msgpack)),
wrphttp.ServerEncodeResponseBody(timeLayout, fanoutOptions.NewEncoderPool(wrp.Msgpack)),
gokithttp.ServerErrorEncoder(
wrphttp.ServerErrorEncoder(timeLayout),
),
),
)

return router, nil
}
Loading

0 comments on commit 1aa2641

Please sign in to comment.