Skip to content

Commit

Permalink
buf: Remote modules (#1)
Browse files Browse the repository at this point in the history
* Use remote packages

* v2: Use remote modules from Buf
  • Loading branch information
kyleconroy authored Jun 21, 2023
1 parent a965e8c commit 19029cf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9,647 deletions.
15 changes: 7 additions & 8 deletions codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"fmt"
"io"
"os"
)

type Request = CodeGenRequest

type Response = CodeGenResponse
pb "buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
"google.golang.org/protobuf/proto"
)

type Handler func(context.Context, *Request) (*Response, error)
type Handler func(context.Context, *pb.CodeGenRequest) (*pb.CodeGenResponse, error)

func Run(h Handler) {
if err := run(h); err != nil {
Expand All @@ -22,19 +21,19 @@ func Run(h Handler) {
}

func run(h Handler) error {
var req Request
var req pb.CodeGenRequest
reqBlob, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
if err := req.UnmarshalVT(reqBlob); err != nil {
if err := proto.Unmarshal(reqBlob, &req); err != nil {
return err
}
resp, err := h(context.Background(), &req)
if err != nil {
return err
}
respBlob, err := resp.MarshalVT()
respBlob, err := proto.Marshal(resp)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 19029cf

Please sign in to comment.