-1
lex/gen.go
-1
lex/gen.go
···
135
135
pf("\t\"fmt\"\n")
136
136
pf("\t\"encoding/json\"\n")
137
137
pf("\tcbg \"github.com/whyrusleeping/cbor-gen\"\n")
138
-
pf("\t\"github.com/bluesky-social/indigo/xrpc\"\n")
139
138
pf("\t\"github.com/bluesky-social/indigo/lex/util\"\n")
140
139
for _, xpkg := range packages {
141
140
if xpkg.Prefix != pkg.Prefix {
+4
-4
lex/type_schema.go
+4
-4
lex/type_schema.go
···
54
54
pf := printerf(w)
55
55
fname := typename
56
56
57
-
params := "ctx context.Context, c *xrpc.Client"
57
+
params := "ctx context.Context, c util.LexClient"
58
58
inpvar := "nil"
59
59
inpenc := ""
60
60
···
161
161
var reqtype string
162
162
switch s.Type {
163
163
case "procedure":
164
-
reqtype = "xrpc.Procedure"
164
+
reqtype = "util.Procedure"
165
165
case "query":
166
-
reqtype = "xrpc.Query"
166
+
reqtype = "util.Query"
167
167
default:
168
168
return fmt.Errorf("can only generate RPC for Query or Procedure (got %s)", s.Type)
169
169
}
170
170
171
-
pf("\tif err := c.Do(ctx, %s, %q, \"%s\", %s, %s, %s); err != nil {\n", reqtype, inpenc, s.id, queryparams, inpvar, outvar)
171
+
pf("\tif err := c.LexDo(ctx, %s, %q, \"%s\", %s, %s, %s); err != nil {\n", reqtype, inpenc, s.id, queryparams, inpvar, outvar)
172
172
pf("\t\treturn %s\n", errRet)
173
173
pf("\t}\n\n")
174
174
pf("\treturn %s\n", outRet)
+17
lex/util/client.go
+17
lex/util/client.go
···
1
+
package util
2
+
3
+
import (
4
+
"context"
5
+
)
6
+
7
+
type XRPCRequestType int
8
+
9
+
const (
10
+
Query = XRPCRequestType(iota)
11
+
Procedure
12
+
)
13
+
14
+
// API client interface used in lexgen.
15
+
type LexClient interface {
16
+
LexDo(ctx context.Context, kind XRPCRequestType, inpenc string, method string, params map[string]any, bodyobj any, out any) error
17
+
}
+14
-9
xrpc/xrpc.go
+14
-9
xrpc/xrpc.go
···
13
13
"strings"
14
14
"time"
15
15
16
+
lexutil "github.com/bluesky-social/indigo/lex/util"
16
17
"github.com/bluesky-social/indigo/util"
17
18
"github.com/carlmjohnson/versioninfo"
18
19
)
···
34
35
return c.Client
35
36
}
36
37
37
-
type XRPCRequestType int
38
+
type XRPCRequestType = lexutil.XRPCRequestType
39
+
40
+
var (
41
+
Query = lexutil.Query
42
+
Procedure = lexutil.Procedure
43
+
)
38
44
39
45
type AuthInfo struct {
40
46
AccessJwt string `json:"accessJwt"`
···
110
116
Reset time.Time
111
117
}
112
118
113
-
const (
114
-
Query = XRPCRequestType(iota)
115
-
Procedure
116
-
)
117
-
118
119
// makeParams converts a map of string keys and any values into a URL-encoded string.
119
120
// If a value is a slice of strings, it will be joined with commas.
120
121
// Generally the values will be strings, numbers, booleans, or slices of strings
···
133
134
return params.Encode()
134
135
}
135
136
136
-
func (c *Client) Do(ctx context.Context, kind XRPCRequestType, inpenc string, method string, params map[string]interface{}, bodyobj interface{}, out interface{}) error {
137
+
func (c *Client) Do(ctx context.Context, kind lexutil.XRPCRequestType, inpenc string, method string, params map[string]interface{}, bodyobj interface{}, out interface{}) error {
137
138
var body io.Reader
138
139
if bodyobj != nil {
139
140
if rr, ok := bodyobj.(io.Reader); ok {
···
150
151
151
152
var m string
152
153
switch kind {
153
-
case Query:
154
+
case lexutil.Query:
154
155
m = "GET"
155
-
case Procedure:
156
+
case lexutil.Procedure:
156
157
m = "POST"
157
158
default:
158
159
return fmt.Errorf("unsupported request kind: %d", kind)
···
227
228
228
229
return nil
229
230
}
231
+
232
+
func (c *Client) LexDo(ctx context.Context, kind lexutil.XRPCRequestType, inpenc string, method string, params map[string]any, bodyobj any, out any) error {
233
+
return c.Do(ctx, kind, inpenc, method, params, bodyobj, out)
234
+
}