Skip to content

kitgen implementation - #589

Merged
peterbourgon merged 123 commits into
go-kit:masterfrom
nyarly:kitgen
Dec 3, 2017
Merged

kitgen implementation#589
peterbourgon merged 123 commits into
go-kit:masterfrom
nyarly:kitgen

Conversation

@nyarly

@nyarly nyarly commented Jul 31, 2017

Copy link
Copy Markdown
Contributor

So far what I've got is simple generation based on a basic interface definition.

Not complete: different layout engines.

Specific design decision here was to construct the generated AST and then
format it out, as opposed to using a text/template. There's some things that
are made much easier this way (i.e. the output is more likely to be correct
code), but the generation code is a bit more opaque. In working with this
process I've found a few things that make the process clearer, and I'm looking
to implement those before this is merged. Specifically, I think many of the
repeated structures could be snagged from an example codefile and then
processed into target structures, rather than built out of whole cloth or
partial inline parses.

@nyarly

nyarly commented Aug 2, 2017

Copy link
Copy Markdown
Contributor Author

I'll be proceeding with this, but I wanted to get a little oversight to see if it's in a useful vein, @peterbourgon

@peterbourgon

Copy link
Copy Markdown
Member

Ah! I missed the notification! This is great. Let me dig in later today and I'll give some more specific comments...

@peterbourgon

peterbourgon commented Aug 3, 2017

Copy link
Copy Markdown
Member

Yeah, this is badass. Pretty much exactly what I had in mind, modulo the parameterization that you've already acknowledged. I also noticed it panics when I don't name the parameters in my service definition, i.e.

type Service interface {
    Foo(context.Context, int, int) (int, error)     // panic
    Bar(ctx context.Context, i, j int) (int, error) // OK
}

If you have enough to move forward, great! If not, please let me know how I can help: clarifying, requirements-gathering, etc.

@peterbourgon

peterbourgon commented Aug 3, 2017

Copy link
Copy Markdown
Member

Hehe, fun!

$ cat test.go
package main

import "context"

type Service interface {
	Foo(_ context.Context, _ int) (int, error)
}
$ kitgen test.go
 ...
func (s stubService) Foo(ctx context.Context, _ int) (int, error) {
        return "", errors.New("not implemented")
}

type FooRequest struct {
        _ int
}
type FooResponse struct {
        I   int
        Err error
}

func makeFooEndpoint(s stubService) endpoint.Endpoint {
        return func(ctx context.Context, request interface{}) (interface{}, error) {
                req := request.(FooRequest)
                i, err := s.Foo(ctx, req._)
                return FooResponse{I: i, Err: err}, nil
        }
}
 ...

@nyarly

nyarly commented Aug 3, 2017

Copy link
Copy Markdown
Contributor Author

I'm good. Just wanted to make sure I wasn't running down a rathole. :)

The edge cases are great. Thanks!

@nyarly

nyarly commented Dec 1, 2017

Copy link
Copy Markdown
Contributor Author

Okay - there's the rebase 🤞

@peterbourgon
peterbourgon merged commit 53f10af into go-kit:master Dec 3, 2017
@peterbourgon

Copy link
Copy Markdown
Member

Woohoo!

@zkanda

zkanda commented Dec 4, 2017

Copy link
Copy Markdown

I've been trying it out and it works great, thank you @nyarly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.