Skip to content

kitgen implementation #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 123 commits into from
Dec 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
6777c8b
cmd/kitgen: parse
peterbourgon Jul 3, 2016
bea53cb
First stymie
nyarly Jul 15, 2017
d87c2ef
Merge branch 'kitgen' of github.com:nyarly/kit into kitgen
nyarly Jul 15, 2017
c302638
Sketch developing
nyarly Jul 16, 2017
2eadf3a
Broken sketch.
nyarly Jul 17, 2017
feb1308
Further progress - still doesn't build
nyarly Jul 18, 2017
cfbb55d
Need to collect ast.Exprs, not strings
nyarly Jul 18, 2017
191e38b
Running downhill.
nyarly Jul 19, 2017
961b593
sd: add Stop method to Instancer interface
peterbourgon Jul 21, 2017
b2b79e8
Fruitful avenue. Committing for travel.
nyarly Jul 24, 2017
7e30257
Needs uniquify for varnames
nyarly Jul 26, 2017
1dbe8fa
Track gauge values and support default tags for dogstatsd
Jul 30, 2017
e40ee5b
Service generation tests work
nyarly Jul 31, 2017
b04b2e2
add failing test for cloudwatch metrics, that are not reset
feliksik Jul 31, 2017
2a3c64e
Refactor cloudwatch: Reset().Walk() on every Send(), like influx impl…
feliksik Jul 31, 2017
1f238bf
Tolerate that there may not be any lables, if the teststat.FillCounte…
feliksik Jul 31, 2017
002c376
Use Cloudwatch options in the struct itself, which is cleaner
feliksik Aug 1, 2017
ab2a990
sd: fix TestDefaultEndpointer flake, hopefully
peterbourgon Aug 3, 2017
aa9583c
util/conn: more detail for flaky test
peterbourgon Aug 3, 2017
8e03b4c
Merge pull request #596 from go-kit/fix-test-flake
peterbourgon Aug 3, 2017
335e7c7
removed deprecated functions
travissalascox Aug 4, 2017
c66fcdb
Merge pull request #591 from feliksik/bug/cloudwatch-reset-counter
peterbourgon Aug 7, 2017
7c0038d
Merge pull request #598 from travissalascox/master
peterbourgon Aug 7, 2017
866d91f
Functions extracted from inline codefile
nyarly Aug 7, 2017
f583a20
Cleaner/easier way for user to specify Cloudwatch metric percentiles.
feliksik Aug 8, 2017
c961428
fix test to read quantile metrics with p prefix
feliksik Aug 9, 2017
0be9fba
test cloudwatch.WithPercentiles()
feliksik Aug 10, 2017
6d351cc
Handles anonymous fields for all parts of interface
nyarly Aug 13, 2017
cd6c724
Handles underscore param names, produces compile-able code
nyarly Aug 14, 2017
4d9f525
do not prefix metrics with 'p', just like it was previously.
feliksik Aug 14, 2017
bcc4b77
Merge pull request #588 from jfhamlin/fix/dogstatsd
peterbourgon Aug 14, 2017
ca3a8b3
Fix for dogstatsd metrics with default tags and no labelValues
Aug 15, 2017
c2c2e83
Converted flat to a layout - proceeding to implement default
nyarly Aug 15, 2017
9368400
Convenience function for formatting to a tree
nyarly Aug 15, 2017
d3c6931
Fix spelling of deregisters
elliotwms Aug 16, 2017
bd8e098
Merge pull request #603 from elliotwms/patch-1
peterbourgon Aug 16, 2017
94d041d
Merge pull request #599 from feliksik/feliksik/easy-percentiles
peterbourgon Aug 16, 2017
f01651a
Merge pull request #602 from jfhamlin/fix/dogstatsd
peterbourgon Aug 17, 2017
b48aaea
Add basic auth middleware
Aug 19, 2017
a5fca17
Default layout
nyarly Aug 20, 2017
2f72aff
Need to handle mutating trees more effectively to do default layout.
nyarly Aug 22, 2017
8c6ad4e
Basic Auth: optimize memory allocation.
Aug 28, 2017
e317ca4
Fix typo
gosharplite Aug 28, 2017
37a2080
cache required creds' slices
Aug 29, 2017
f7593d1
Merge pull request #606 from gosharplite/master
peterbourgon Aug 29, 2017
6b4ca49
Clean up comment
Aug 29, 2017
8a45441
Replacing idents successfully
nyarly Aug 31, 2017
355d3e3
improve error handling and style
Sep 2, 2017
d357b9e
Constructs import paths usefully
nyarly Sep 5, 2017
74f0d79
Some debugging - transit
nyarly Sep 11, 2017
4e222a3
Set time unit on metrics.Timer
esenac Sep 15, 2017
0b39753
Changes as per code review
esenac Sep 15, 2017
0e30e42
fix missing comma in example histogram code
Sep 16, 2017
7862b3f
Merge pull request #605 from DimaSalakhov/basicAuth
peterbourgon Sep 17, 2017
f99388b
Merge pull request #611 from daniel-garcia/fixMissingComma
peterbourgon Sep 17, 2017
b5c889e
Merge pull request #610 from esenac/timer-unit
peterbourgon Sep 17, 2017
b1eb1a0
update_deps.bash: handle detached HEAD better
peterbourgon Sep 17, 2017
f3cb2c0
.travis.yml: go1.9 + tip exclusively
peterbourgon Sep 17, 2017
5d18314
circle.yml: go1.9 exclusively
peterbourgon Sep 17, 2017
e9af46a
Merge pull request #583 from go-kit/instancer-stop
peterbourgon Sep 17, 2017
0d313fb
Merge pull request #613 from go-kit/version-changes
peterbourgon Sep 17, 2017
413893d
Selectify works - need to rearrange some idents now
nyarly Sep 17, 2017
c18c922
Updating golden masters so that they build
nyarly Sep 17, 2017
2bd8e4d
Nearly 100% functionality
nyarly Sep 18, 2017
706be2a
Updated masters - all seems to work
nyarly Sep 24, 2017
e49f103
Now testing that everything builds
nyarly Sep 24, 2017
55ba856
Removing AST experiments
nyarly Sep 24, 2017
b225e46
Chopping up long sourcecontext.gog
nyarly Sep 25, 2017
7ce03db
Tiny little notes
nyarly Sep 26, 2017
4c2a022
auth/jwt: add claim factory to example
bcho Sep 26, 2017
492a87e
auth/jwt: minor gofmt fixes
bcho Sep 26, 2017
9ed3743
Merge pull request #617 from bcho/fix-doc/auth-jwt
ChrisHines Sep 26, 2017
c05f7e6
fix typo in addcli
karthikmuralidharan Oct 3, 2017
4dc7be5
Merge pull request #619 from karthikmuralidharan/patch-1
peterbourgon Oct 3, 2017
b1240ac
Cleaning up some type assertion digging
nyarly Oct 8, 2017
3752c99
Remove dependency on juju
nelz9999 Oct 9, 2017
43c4183
Downstream usages of ratelimit package
nelz9999 Oct 10, 2017
e2b2984
Merge pull request #622 from nelz9999/nelz-x-juju
peterbourgon Oct 21, 2017
0f76b6c
Recreating profilesvc issue
nyarly Oct 29, 2017
d3d877a
Adding .ignore for rg
nyarly Oct 29, 2017
d280089
flat layout works with defined types
nyarly Oct 30, 2017
b44e2a5
Default layout mostly works - one remaining selectify issue
nyarly Oct 31, 2017
d7d6d07
Debugging replaces - determined we need to do cloning
nyarly Nov 2, 2017
e98edf9
Halfway through an edit - taking it home
nyarly Nov 4, 2017
40a7aee
Works with new profilesvc testcases
nyarly Nov 5, 2017
e3b2152
Try to fix Thrift failure (again) (#630)
peterbourgon Nov 12, 2017
1c434a3
cmd/kitgen: parse
peterbourgon Jul 3, 2016
74638bd
First stymie
nyarly Jul 15, 2017
4374643
Sketch developing
nyarly Jul 16, 2017
9b2f777
Broken sketch.
nyarly Jul 17, 2017
a6627d0
Further progress - still doesn't build
nyarly Jul 18, 2017
080d80e
Need to collect ast.Exprs, not strings
nyarly Jul 18, 2017
dab9ae7
Running downhill.
nyarly Jul 19, 2017
6246ebb
Fruitful avenue. Committing for travel.
nyarly Jul 24, 2017
4441bc6
Needs uniquify for varnames
nyarly Jul 26, 2017
d4d943a
Service generation tests work
nyarly Jul 31, 2017
00fee2e
Functions extracted from inline codefile
nyarly Aug 7, 2017
c8b3d29
Handles anonymous fields for all parts of interface
nyarly Aug 13, 2017
06d8837
Handles underscore param names, produces compile-able code
nyarly Aug 14, 2017
f76159f
Converted flat to a layout - proceeding to implement default
nyarly Aug 15, 2017
fe75631
Convenience function for formatting to a tree
nyarly Aug 15, 2017
475bc74
Default layout
nyarly Aug 20, 2017
b167bc4
Need to handle mutating trees more effectively to do default layout.
nyarly Aug 22, 2017
1bae153
Replacing idents successfully
nyarly Aug 31, 2017
ba93957
Constructs import paths usefully
nyarly Sep 5, 2017
518b57a
Some debugging - transit
nyarly Sep 11, 2017
ad302ba
Selectify works - need to rearrange some idents now
nyarly Sep 17, 2017
d3bcaa8
Updating golden masters so that they build
nyarly Sep 17, 2017
4c028a1
Nearly 100% functionality
nyarly Sep 18, 2017
73c5884
Updated masters - all seems to work
nyarly Sep 24, 2017
34048c2
Now testing that everything builds
nyarly Sep 24, 2017
07595a6
Removing AST experiments
nyarly Sep 24, 2017
b9210a2
Chopping up long sourcecontext.gog
nyarly Sep 25, 2017
566f9bf
Tiny little notes
nyarly Sep 26, 2017
351ad9f
Cleaning up some type assertion digging
nyarly Oct 8, 2017
0156ebe
Recreating profilesvc issue
nyarly Oct 29, 2017
72c389e
Adding .ignore for rg
nyarly Oct 29, 2017
31848c5
flat layout works with defined types
nyarly Oct 30, 2017
73c8ebc
Default layout mostly works - one remaining selectify issue
nyarly Oct 31, 2017
964b4e7
Debugging replaces - determined we need to do cloning
nyarly Nov 2, 2017
b203a76
Halfway through an edit - taking it home
nyarly Nov 4, 2017
0096b57
Works with new profilesvc testcases
nyarly Nov 5, 2017
627d553
Merge branch 'kitgen' of github.com:nyarly/kit into kitgen
nyarly Dec 1, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Functions extracted from inline codefile
  • Loading branch information
nyarly committed Dec 1, 2017
commit 00fee2e2b1aeab681540bae657da35fa04faafbc
2 changes: 1 addition & 1 deletion cmd/kitgen/ast_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ package main
import "golang.org/x/tools/godoc/vfs/mapfs"

var ASTTemplates = mapfs.New(map[string]string{
`full.go`: "package foo\n\ntype STUBSTRUCT struct{}\n\nfunc (f STUBSTRUCT) Bar(PARAM aType) (string, error) {\n return \"\", errors.New(\"not implemented\")\n}\n\ntype BarRequest struct {\n I int\n S string\n}\n\ntype BarResponse struct {\n S string\n Err error\n}\n\nfunc makeBarEndpoint(s STUBSTRUCT) endpoint.Endpoint {\n return func(ctx context.Context, request interface{}) (interface{}, error) {\n req := request.(barrequest)\n s, err := s.bar(ctx, req.i, req.s)\n return barresponse{s: s, err: err}, nil\n }\n}\n\ntype Endpoints struct {\n Bar endpoint.Endpoint\n}\n\n// Each transport binding should be opt-in with a flag to kitgen.\n// Here's a basic sketch of what HTTP may look like.\n// n.b. comments should encourage users to edit the generated code.\n\nfunc NewHTTPHandler(endpoints Endpoints) http.Handler {\n m := http.NewServeMux()\n m.Handle(\"/bar\", httptransport.NewServer(\n endpoints.Bar,\n DecodeBarRequest,\n EncodeBarResponse,\n ))\n return m\n}\n\nfunc DecodeBarRequest(_ context.Context, r *http.Request) (interface{}, error) {\n var req BarRequest\n err := json.NewDecoder(r.Body).Decode(&req)\n return req, err\n}\n\nfunc EncodeBarResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {\n w.Header().Set(\"Content-Type\", \"application/json; charset=utf-8\")\n return json.NewEncoder(w).Encode(response)\n}\n",
`full.go`: "package foo\n\ntype stubFooService struct {\n}\n\ntype ExampleRequest struct {\n I int\n S string\n}\ntype ExampleResponse struct {\n S string\n Err error\n}\n\ntype Endpoints struct {\n ExampleEndpoint endpoint.Endpoint\n}\n\nfunc (f stubFooService) ExampleEndpoint(ctx context.Context, i int, s string) (string, error) {\n return \"\", errors.New(\"not implemented\")\n}\n\nfunc makeExampleEndpoint(f stubFooService) endpoint.Endpoint {\n return func(ctx context.Context, request interface{}) (interface{}, error) {\n req := request.(ExampleRequest)\n s, err := f.ExampleEndpoint(ctx, req.I, req.S)\n return ExampleResponse{S: s, Err: err}, nil\n }\n}\n\nfunc inlineHandlerBuilder() {\n m.Handle(\"/bar\", httptransport.NewServer(endpoints.ExampleEndpoint, DecodeExampleRequest, EncodeExampleResponse))\n}\n\nfunc NewHTTPHandler(endpoints Endpoints) http.Handler {\n m := http.NewServeMux()\n inlineHandlerBuilder()\n return m\n}\n\nfunc DecodeExampleRequest(_ context.Context, r *http.Request) (interface{}, error) {\n var req ExampleRequest\n err := json.NewDecoder(r.Body).Decode(&req)\n return req, err\n}\n\nfunc EncodeExampleResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {\n w.Header().Set(\"Content-Type\", \"application/json; charset=utf-8\")\n return json.NewEncoder(w).Encode(response)\n}\n",
})
152 changes: 59 additions & 93 deletions cmd/kitgen/sourcecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ type (
}
)

func fetchFuncDecl(name string) *ast.FuncDecl {
full, err := ASTTemplates.Open("full.go")
if err != nil {
panic(err)
}
f, err := parser.ParseFile(token.NewFileSet(), "templates/full.go", full, parser.DeclarationErrors)
if err != nil {
panic(err)
}
for _, decl := range f.Decls {
if f, ok := decl.(*ast.FuncDecl); ok && f.Name.Name == name {
return f
}
}
panic(fmt.Errorf("No function called %q in 'templates/full.go'", name))
}

func id(name string) *ast.Ident {
return ast.NewIdent(name)
}
Expand Down Expand Up @@ -80,14 +97,6 @@ func structDecl(name *ast.Ident, fields *ast.FieldList) ast.Decl {
}
}

func mustParseExpr(s string) ast.Node {
n, err := parser.ParseExpr(s)
if err != nil {
panic(err)
}
return n
}

func pasteStmts(body *ast.BlockStmt, idx int, stmts []ast.Stmt) {
list := body.List
prefix := list[:idx]
Expand Down Expand Up @@ -138,16 +147,13 @@ func NewHTTPHandler(endpoints Endpoints) http.Handler {
return m
}
*/

func (i iface) httpHandler() ast.Decl {
handlerFn := mustParseExpr(`func (endpoints Endpoints) http.Handler {
m := http.NewServeMux()
replaceWithHandleCalls()
return m
}`).(*ast.FuncLit)
handlerFn := fetchFuncDecl("NewHTTPHandler")

handleCalls := []ast.Stmt{}
for _, m := range i.methods {
handleCall := mustParseExpr(`m.Handle("", httptransport.NewServer())`).(*ast.CallExpr)
handleCall := fetchFuncDecl("inlineHandlerBuilder").Body.List[0].(*ast.ExprStmt).X.(*ast.CallExpr)

handleCall.Args[0].(*ast.BasicLit).Value = `"` + m.pathName() + `"`

Expand All @@ -159,11 +165,7 @@ func (i iface) httpHandler() ast.Decl {

pasteStmts(handlerFn.Body, 1, handleCalls)

return &ast.FuncDecl{
Name: id("NewHTTPHandler"),
Type: handlerFn.Type,
Body: handlerFn.Body,
}
return handlerFn
}

func (i iface) reciever() *ast.Field {
Expand Down Expand Up @@ -195,27 +197,22 @@ func (i iface) receiverName() *ast.Ident {
}

func (m method) definition(ifc iface) ast.Decl {
notImpl := mustParseExpr(`func() {return "", errors.New("not implemented")}`).(*ast.FuncLit)
notImpl := fetchFuncDecl("ExampleEndpoint")

parms := m.funcParams()
if m.hasContext() {
parms = &ast.FieldList{
List: append([]*ast.Field{{
Names: []*ast.Ident{ast.NewIdent("ctx")},
Type: sel(id("context"), id("Context")),
}}, parms.List...),
}
}
notImpl.Name = m.name
notImpl.Recv = &ast.FieldList{List: []*ast.Field{ifc.reciever()}}
notImpl.Type.Params = m.funcParams()
notImpl.Type.Results = m.funcResults()

return &ast.FuncDecl{
Recv: &ast.FieldList{List: []*ast.Field{ifc.reciever()}},
Name: m.name,
Type: &ast.FuncType{
Params: parms,
Results: m.funcResults(),
},
Body: notImpl.Body,
return notImpl
}

func scopeWith(names ...string) *ast.Scope {
scope := ast.NewScope(nil)
for _, name := range names {
scope.Insert(ast.NewObj(ast.Var, name))
}
return scope
}

/*
Expand All @@ -228,42 +225,23 @@ func (m method) definition(ifc iface) ast.Decl {
}
*/
func (m method) endpointMaker(ifc iface) ast.Decl {
endpointFn := mustParseExpr(`func() {return func(ctx context.Context, request interface{}) (interface{}, error) { }}`).(*ast.FuncLit)
scope := ast.NewScope(nil)
scope.Insert(ast.NewObj(ast.Var, ifc.receiverName().Name))
scope.Insert(ast.NewObj(ast.Var, "ctx"))
scope.Insert(ast.NewObj(ast.Var, "req"))
endpointFn := fetchFuncDecl("makeExampleEndpoint")
scope := scopeWith("ctx", "req", ifc.receiverName().Name)

anonFunc := endpointFn.Body.List[0].(*ast.ReturnStmt).Results[0].(*ast.FuncLit)
if !m.hasContext() { // is this the right thing?
anonFunc.Type.Params.List = anonFunc.Type.Params.List[1:]
}

castReq := mustParseExpr(`func() {req := request.(NOTTHIS)}`).(*ast.FuncLit).Body.List[0].(*ast.AssignStmt)
castReq.Rhs[0].(*ast.TypeAssertExpr).Type = m.requestStructName()

anonFunc.Body.List[0].(*ast.AssignStmt).Rhs[0].(*ast.TypeAssertExpr).Type = m.requestStructName()
callMethod := m.called(ifc, scope, "ctx", "req")
anonFunc.Body.List[1] = callMethod
anonFunc.Body.List[2].(*ast.ReturnStmt).Results[0] = m.wrapResult(callMethod.Lhs)

returnResponse := &ast.ReturnStmt{
Results: []ast.Expr{m.wrapResult(callMethod.Lhs), id("nil")},
}

anonFunc.Body = blockStmt(
castReq,
callMethod,
returnResponse,
)

return &ast.FuncDecl{
Name: m.endpointMakerName(),
Type: &ast.FuncType{
Params: &ast.FieldList{List: []*ast.Field{ifc.reciever()}},
Results: &ast.FieldList{List: []*ast.Field{
&ast.Field{Type: sel(id("endpoint"), id("Endpoint"))},
}},
},
Body: endpointFn.Body,
}
endpointFn.Name = m.endpointMakerName()
endpointFn.Type.Params = &ast.FieldList{List: []*ast.Field{ifc.reciever()}}
endpointFn.Type.Results = &ast.FieldList{List: []*ast.Field{&ast.Field{Type: sel(id("endpoint"), id("Endpoint"))}}}
return endpointFn
}

func (m method) pathName() string {
Expand Down Expand Up @@ -390,36 +368,16 @@ func (m method) resolveStructNames() {
}

func (m method) decoderFunc() ast.Decl {
fn := mustParseExpr(`
func (_ context.Context, r *http.Request) (interface{}, error) {
var req ReqStructName
err := json.NewDecoder(r.Body).Decode(&req)
return req, err
}
`).(*ast.FuncLit)

fn := fetchFuncDecl("DecodeExampleRequest")
fn.Name = m.decodeFuncName()
fn.Body.List[0].(*ast.DeclStmt).Decl.(*ast.GenDecl).Specs[0].(*ast.ValueSpec).Type = m.requestStructName()

return &ast.FuncDecl{
Name: m.decodeFuncName(),
Type: fn.Type,
Body: fn.Body,
}
return fn
}

func (m method) encoderFunc() ast.Decl {
fn := mustParseExpr(`
func (_ context.Context, w http.ResponseWriter, response interface{}) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
return json.NewEncoder(w).Encode(response)
}
`).(*ast.FuncLit)

return &ast.FuncDecl{
Name: m.encodeFuncName(),
Type: fn.Type,
Body: fn.Body,
}
fn := fetchFuncDecl("EncodeExampleResponse")
fn.Name = m.encodeFuncName()
return fn
}

func (m method) endpointMakerName() *ast.Ident {
Expand Down Expand Up @@ -459,9 +417,17 @@ func (m method) nonContextParams() []arg {
}

func (m method) funcParams() *ast.FieldList {
return fieldList(func(a arg) *ast.Field {
parms := &ast.FieldList{}
if m.hasContext() {
parms.List = []*ast.Field{{
Names: []*ast.Ident{ast.NewIdent("ctx")},
Type: sel(id("context"), id("Context")),
}}
}
parms.List = append(parms.List, fieldList(func(a arg) *ast.Field {
return a.field()
}, m.nonContextParams()...)
}, m.nonContextParams()...).List...)
return parms
}

func (m method) funcResults() *ast.FieldList {
Expand Down
46 changes: 21 additions & 25 deletions cmd/kitgen/templates/full.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
package foo

type STUBSTRUCT struct{}

func (f STUBSTRUCT) METHOD(PARAM aType) (string, error) {
return "", errors.New("not implemented")
type stubFooService struct {
}

type BarRequest struct {
type ExampleRequest struct {
I int
S string
}

type BarResponse struct {
type ExampleResponse struct {
S string
Err error
}

func MAKEENDPOINT(s STUBSTRUCT) endpoint.Endpoint {
type Endpoints struct {
ExampleEndpoint endpoint.Endpoint
}

func (f stubFooService) ExampleEndpoint(ctx context.Context, i int, s string) (string, error) {
return "", errors.New("not implemented")
}

func makeExampleEndpoint(f stubFooService) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(REQUESTSTRUCT)
s, err := s.bar(ctx, req.i, req.s)
return RESPONSESTRUCT{s: s, err: err}, nil
req := request.(ExampleRequest)
s, err := f.ExampleEndpoint(ctx, req.I, req.S)
return ExampleResponse{S: s, Err: err}, nil
}
}

type Endpoints struct {
Bar endpoint.Endpoint
func inlineHandlerBuilder() {
m.Handle("/bar", httptransport.NewServer(endpoints.ExampleEndpoint, DecodeExampleRequest, EncodeExampleResponse))
}

// Each transport binding should be opt-in with a flag to kitgen.
// Here's a basic sketch of what HTTP may look like.
// n.b. comments should encourage users to edit the generated code.

func NewHTTPHandler(endpoints Endpoints) http.Handler {
m := http.NewServeMux()
m.Handle("/bar", httptransport.NewServer(
endpoints.Bar,
DecodeBarRequest,
EncodeBarResponse,
))
inlineHandlerBuilder()
return m
}

func DecodeBarRequest(_ context.Context, r *http.Request) (interface{}, error) {
var req BarRequest
func DecodeExampleRequest(_ context.Context, r *http.Request) (interface{}, error) {
var req ExampleRequest
err := json.NewDecoder(r.Body).Decode(&req)
return req, err
}

func EncodeBarResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
func EncodeExampleResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
return json.NewEncoder(w).Encode(response)
}
3 changes: 0 additions & 3 deletions cmd/kitgen/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package main

import (
"go/ast"

"github.com/davecgh/go-spew/spew"
)

func transformAST(ctx *sourceContext) (ast.Node, error) {
Expand Down Expand Up @@ -40,7 +38,6 @@ func addStubStruct(root *ast.File, iface iface) {

func addMethod(root *ast.File, iface iface, meth method) {
def := meth.definition(iface)
spew.Dump(def)
root.Decls = append(root.Decls, def)
}

Expand Down