Skip to content

Commit 4de6c54

Browse files
committed
add readme
1 parent 7bc663b commit 4de6c54

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

pkg/loop/cmd/genwiring/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Tiny code generator that turns your domain model into:
2+
3+
- .proto service + messages
4+
- single Go file (rpc.go) with:
5+
- typed gRPC Client
6+
- typed gRPC Server (thin shim over your implementation)
7+
- pb ↔ domain converters for every user message
8+
- oneof (interface) adapters
9+
- safe handling of bytes, repeated fields, and fixed-size arrays
10+
- an optional rpc_test.go with a single bufconn server and subtests (happy-path roundtrip)
11+
Usage example:
12+
Suppose your interface is in pkg/path and its called MyInterface:
13+
1. Generate proto files + go wrappers
14+
//go:generate bash -c "set -euo pipefail; mkdir -p ./gen/pb ./gen/wrap && go run ./genwiring --pkg pkg/path --interface MyInterface --config config.yaml --service MyService --proto-pkg loop.test --proto-go-package my/proto/package --proto-out ./path/to/my.proto --go-out ./path/to/my/go/wrappers --go-pkg my/go/pkg"
15+
2. Use protoc to generate go proto types
16+
//go:generate bash -c "set -euo pipefail; protoc -I ./gen/pb --go_out=paths=source_relative:./gen/pb --go-grpc_out=paths=source_relative:./gen/pb ./gen/pb/service.proto"
17+
The output will be:
18+
- A strongly typed Client that does domain <-> pb conversions rpc.go, rpc_test.go
19+
- A server wrapper that converts pb and calls your impl.
20+
A full usage example with config in pkg/loop/internal/generator/testdata

pkg/loop/internal/generator/generator.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package generator
22

33
import (
4+
"cmp"
45
"fmt"
56
"go/types"
67
"os"
78
"path"
9+
"slices"
810
"sort"
911
"strings"
1012

@@ -173,7 +175,10 @@ func ParseInterface(pkgPath, iface string, cfg *Config) (*Service, error) {
173175
for _, um := range reg {
174176
svc.UserMessages = append(svc.UserMessages, *um)
175177
}
176-
sort.Slice(svc.UserMessages, func(i, j int) bool { return svc.UserMessages[i].Name < svc.UserMessages[j].Name })
178+
179+
slices.SortFunc(svc.UserMessages, func(i, j UserMessage) int {
180+
return cmp.Compare(i.Name, j.Name)
181+
})
177182

178183
for _, io := range oneofReg {
179184
svc.InterfaceOneofs = append(svc.InterfaceOneofs, *io)

pkg/loop/internal/generator/testdata/testface.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ type TestFace interface {
2020
SendNested(ctx context.Context, ns NestedStruct) (NestedStruct, error)
2121
}
2222

23-
type SolanaService interface {
24-
// SendTx(ctx context.Context, tx *solanago.Transaction) (solanago.Signature, error)
25-
// SimulateTx(ctx context.Context, tx *solanago.Transaction, opts *rpc.SimulateTransactionOpts) (*rpc.SimulateTransactionResult, error)
26-
}
27-
2823
type MyStruct struct {
2924
B []byte
3025
Prim primitives.ConfidenceLevel

0 commit comments

Comments
 (0)