fork of indigo with slightly nicer lexgen

switch to using net/http consts for request types

Changed files
+11 -15
lex
util
xrpc
+4 -5
lex/util/client.go
··· 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 }
··· 2 3 import ( 4 "context" 5 + "net/http" 6 ) 7 8 const ( 9 + Query = http.MethodGet 10 + Procedure = http.MethodPost 11 ) 12 13 // API client interface used in lexgen. 14 type LexClient interface { 15 + LexDo(ctx context.Context, kind string, inpenc string, method string, params map[string]any, bodyobj any, out any) error 16 }
+7 -10
xrpc/xrpc.go
··· 13 "strings" 14 "time" 15 16 - lexutil "github.com/bluesky-social/indigo/lex/util" 17 "github.com/bluesky-social/indigo/util" 18 "github.com/carlmjohnson/versioninfo" 19 ) ··· 35 return c.Client 36 } 37 38 - type XRPCRequestType = lexutil.XRPCRequestType 39 - 40 var ( 41 - Query = lexutil.Query 42 - Procedure = lexutil.Procedure 43 ) 44 45 type AuthInfo struct { ··· 134 return params.Encode() 135 } 136 137 - func (c *Client) Do(ctx context.Context, kind lexutil.XRPCRequestType, inpenc string, method string, params map[string]interface{}, bodyobj interface{}, out interface{}) error { 138 var body io.Reader 139 if bodyobj != nil { 140 if rr, ok := bodyobj.(io.Reader); ok { ··· 151 152 var m string 153 switch kind { 154 - case lexutil.Query: 155 m = "GET" 156 - case lexutil.Procedure: 157 m = "POST" 158 default: 159 - return fmt.Errorf("unsupported request kind: %d", kind) 160 } 161 162 var paramStr string ··· 229 return nil 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 }
··· 13 "strings" 14 "time" 15 16 "github.com/bluesky-social/indigo/util" 17 "github.com/carlmjohnson/versioninfo" 18 ) ··· 34 return c.Client 35 } 36 37 var ( 38 + Query = http.MethodGet 39 + Procedure = http.MethodPost 40 ) 41 42 type AuthInfo struct { ··· 131 return params.Encode() 132 } 133 134 + func (c *Client) Do(ctx context.Context, kind string, inpenc string, method string, params map[string]interface{}, bodyobj interface{}, out interface{}) error { 135 var body io.Reader 136 if bodyobj != nil { 137 if rr, ok := bodyobj.(io.Reader); ok { ··· 148 149 var m string 150 switch kind { 151 + case Query: 152 m = "GET" 153 + case Procedure: 154 m = "POST" 155 default: 156 + return fmt.Errorf("unsupported request kind: %s", kind) 157 } 158 159 var paramStr string ··· 226 return nil 227 } 228 229 + func (c *Client) LexDo(ctx context.Context, kind string, inpenc string, method string, params map[string]any, bodyobj any, out any) error { 230 return c.Do(ctx, kind, inpenc, method, params, bodyobj, out) 231 }