-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+start graphql servicer. +separate route registry.
- Loading branch information
Showing
14 changed files
with
839 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package application | ||
|
||
import ( | ||
"middleware/logging" | ||
"service/login" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
httptransport "github.com/go-kit/kit/transport/http" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// | ||
func routeLoginService(ctx context.Context, r *mux.Router) { | ||
|
||
logged := logging.New("login", Settings.Program.Name).Middleware() | ||
|
||
loginService := login.New() | ||
|
||
// POST / | ||
|
||
r.Methods("POST").Path("/").Handler(httptransport.NewServer( | ||
ctx, | ||
logged(loginService.Endpoint()), | ||
loginService.Decoder, | ||
servered(jsoned(loginService.Encoder)), | ||
)).Name("POST") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package application | ||
|
||
import ( | ||
"middleware/logging" | ||
"service/query" | ||
"transport/http/caching" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
httptransport "github.com/go-kit/kit/transport/http" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// | ||
func routeQueryService(ctx context.Context, r *mux.Router) { | ||
|
||
logged := logging.New("query", Settings.Program.Name).Middleware() | ||
|
||
queryService := query.New() | ||
|
||
// GET /:id | ||
|
||
r.Methods("GET").Path("/{id}").Handler(caching.New(-1, httptransport.NewServer( | ||
ctx, | ||
logged(queryService.Endpoint()), | ||
queryService.Decoder, | ||
servered(jsoned(queryService.Encoder)), | ||
))).Name("GET Id") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package application | ||
|
||
import ( | ||
"middleware/logging" | ||
"service/starwars" | ||
"transport/http/caching" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
httptransport "github.com/go-kit/kit/transport/http" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// | ||
func routeStarWarsService(ctx context.Context, r *mux.Router) { | ||
|
||
logged := logging.New("starwars", Settings.Program.Name).Middleware() | ||
|
||
starWarsService := starwars.New() | ||
|
||
// GET /:query | ||
|
||
r.Methods("GET").Path("/{query}").Handler(caching.New(-1, httptransport.NewServer( | ||
ctx, | ||
logged(starWarsService.Endpoint()), | ||
starWarsService.Decoder, | ||
servered(jsoned(starWarsService.Encoder)), | ||
))).Name("GET Id") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package application | ||
|
||
import ( | ||
"middleware/logging" | ||
"service/testing" | ||
"transport/http/caching" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
httptransport "github.com/go-kit/kit/transport/http" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// | ||
func routeTestService(ctx context.Context, r *mux.Router) { | ||
|
||
logged := logging.New("test", Settings.Program.Name).Middleware() | ||
|
||
testService := testing.New() | ||
|
||
// POST / | ||
|
||
r.Methods("POST").Path("/").Handler(httptransport.NewServer( | ||
ctx, | ||
logged(testService.Post()), | ||
testService.DecodePost, | ||
servered(jsoned(testService.EncodePost)), | ||
)).Name("POST") | ||
|
||
// GET /:id | ||
|
||
r.Methods("POST", "GET").Path("/{id}").Handler(caching.New(-1, httptransport.NewServer( | ||
ctx, | ||
logged(testService.Get()), | ||
testService.DecodeGet, | ||
servered(jsoned(testService.EncodeGet)), | ||
))).Name("GET/POST Id") | ||
|
||
// PUT /:id | ||
|
||
r.Methods("PUT").Path("/{id}").Handler(caching.New(-1, httptransport.NewServer( | ||
ctx, | ||
logged(testService.Put()), | ||
testService.DecodePut, | ||
servered(jsoned(testService.EncodePut)), | ||
))).Name("PUT Id") | ||
|
||
// PATCH /:id | ||
|
||
r.Methods("PATCH").Path("/{id}").Handler(httptransport.NewServer( | ||
ctx, | ||
logged(testService.Patch()), | ||
testService.DecodePatch, | ||
servered(jsoned(testService.EncodePatch)), | ||
)).Name("PATCH Id") | ||
|
||
// DELETE /:id | ||
|
||
r.Methods("DELETE").Path("/{id}").Handler(caching.New(-1, httptransport.NewServer( | ||
ctx, | ||
logged(testService.Delete()), | ||
testService.DecodeDelete, | ||
servered(jsoned(testService.EncodeDelete)), | ||
))).Name("DELETE Id") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package query | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/go-kit/kit/endpoint" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// Errors | ||
|
||
// ErrNoQuery. | ||
var ErrNoQuery = errors.New("empty query") | ||
|
||
// Model | ||
|
||
// Query operations. | ||
type Service interface { | ||
Query(string) (string, error) | ||
} | ||
|
||
// Private Query model. | ||
type queryService struct{} | ||
|
||
// Query requests. | ||
type queryRequest struct { | ||
S string `json:"s"` | ||
} | ||
|
||
// Query response. | ||
type queryResponse struct { | ||
V string `json:"v"` | ||
Err string `json:"err,omitempty"` // errors don't define JSON marshaling | ||
} | ||
|
||
// | ||
func (queryService) Query(s string) (string, error) { | ||
if s == "" { | ||
return "", ErrNoQuery | ||
} | ||
return strings.ToUpper(s), nil | ||
} | ||
|
||
// Initialization | ||
|
||
// | ||
type queryEndpoint endpoint.Endpoint | ||
|
||
// | ||
func New() queryEndpoint { | ||
svc := queryService{} | ||
|
||
return func(ctx context.Context, request interface{}) (interface{}, error) { | ||
req := request.(queryRequest) | ||
v, err := svc.Query(req.S) | ||
if err != nil { | ||
return queryResponse{v, err.Error()}, nil | ||
} | ||
return queryResponse{v, ""}, nil | ||
} | ||
} | ||
|
||
// Convenience to get a go-kit type back of query's private endpoint type. | ||
func (e queryEndpoint) Endpoint() endpoint.Endpoint { | ||
return endpoint.Endpoint(e) | ||
} | ||
|
||
// Request/response encoding and decoding. | ||
|
||
// | ||
func (e queryEndpoint) Decoder(_ context.Context, r *http.Request) (interface{}, error) { | ||
var request queryRequest | ||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil { | ||
return nil, err | ||
} | ||
return request, nil | ||
} | ||
|
||
// | ||
func (e queryEndpoint) Encoder(_ context.Context, w http.ResponseWriter, response interface{}) error { | ||
return json.NewEncoder(w).Encode(response) | ||
} |
Oops, something went wrong.