fork of indigo with slightly nicer lexgen

feedback from code review

Changed files
+27 -31
atproto
+6 -5
atproto/client/apierror.go
··· 11 11 } 12 12 13 13 func (ae *APIError) Error() string { 14 - if ae.StatusCode > 0 && ae.Name != "" && ae.Message != "" { 15 - return fmt.Sprintf("API request failed (HTTP %d): %s: %s", ae.StatusCode, ae.Name, ae.Message) 16 - } else if ae.StatusCode > 0 && ae.Name != "" { 17 - return fmt.Sprintf("API request failed (HTTP %d): %s", ae.StatusCode, ae.Name) 18 - } else if ae.StatusCode > 0 { 14 + if ae.StatusCode > 0 { 15 + if ae.Name != "" && ae.Message != "" { 16 + return fmt.Sprintf("API request failed (HTTP %d): %s: %s", ae.StatusCode, ae.Name, ae.Message) 17 + } else if ae.Name != "" { 18 + return fmt.Sprintf("API request failed (HTTP %d): %s", ae.StatusCode, ae.Name) 19 + } 19 20 return fmt.Sprintf("API request failed (HTTP %d)", ae.StatusCode) 20 21 } 21 22 return "API request failed"
+11 -8
atproto/client/lexclient.go
··· 11 11 ) 12 12 13 13 // Implements the [github.com/bluesky-social/indigo/lex/util.LexClient] interface, for use with code-generated API helpers. 14 - func (c *APIClient) LexDo(ctx context.Context, kind string, inpenc string, method string, params map[string]any, bodyobj any, out any) error { 14 + func (c *APIClient) LexDo(ctx context.Context, method string, inputEncoding string, endpoint string, params map[string]any, bodyData any, out any) error { 15 15 // some of the code here is copied from indigo:xrpc/xrpc.go 16 16 17 - nsid, err := syntax.ParseNSID(method) 17 + nsid, err := syntax.ParseNSID(endpoint) 18 18 if err != nil { 19 19 return err 20 20 } 21 21 22 22 var body io.Reader 23 - if bodyobj != nil { 24 - if rr, ok := bodyobj.(io.Reader); ok { 23 + if bodyData != nil { 24 + if rr, ok := bodyData.(io.Reader); ok { 25 25 body = rr 26 26 } else { 27 - b, err := json.Marshal(bodyobj) 27 + b, err := json.Marshal(bodyData) 28 28 if err != nil { 29 29 return err 30 30 } 31 31 32 32 body = bytes.NewReader(b) 33 + if inputEncoding == "" { 34 + inputEncoding = "application/json" 35 + } 33 36 } 34 37 } 35 38 36 - req := NewAPIRequest(kind, nsid, body) 39 + req := NewAPIRequest(method, nsid, body) 37 40 38 - if bodyobj != nil && inpenc != "" { 39 - req.Headers.Set("Content-Type", inpenc) 41 + if inputEncoding != "" { 42 + req.Headers.Set("Content-Type", inputEncoding) 40 43 } 41 44 42 45 if params != nil {
+10 -18
atproto/client/params.go
··· 15 15 case nil: 16 16 out.Set(k, "") 17 17 case bool: 18 - if v { 19 - out.Set(k, "true") 20 - } else { 21 - out.Set(k, "false") 22 - } 18 + out.Set(k, fmt.Sprint(v)) 23 19 case string: 24 20 out.Set(k, v) 25 - case int, uint, int8, int16, int32, int64, uint8, uint16, uint32, uint64: 26 - out.Set(k, fmt.Sprintf("%d", v)) 21 + case int, uint, int8, int16, int32, int64, uint8, uint16, uint32, uint64, uintptr: 22 + out.Set(k, fmt.Sprint(v)) 27 23 case encoding.TextMarshaler: 28 - out.Set(k, fmt.Sprintf("%s", v)) 24 + out.Set(k, fmt.Sprint(v)) 29 25 default: 30 26 ref := reflect.ValueOf(v) 31 27 if ref.Kind() == reflect.Slice { ··· 34 30 case nil: 35 31 out.Add(k, "") 36 32 case bool: 37 - if elem { 38 - out.Add(k, "true") 39 - } else { 40 - out.Add(k, "false") 41 - } 33 + out.Add(k, fmt.Sprint(elem)) 42 34 case string: 43 35 out.Add(k, elem) 44 - case int, uint, int8, int16, int32, int64, uint8, uint16, uint32, uint64: 45 - out.Add(k, fmt.Sprintf("%d", elem)) 36 + case int, uint, int8, int16, int32, int64, uint8, uint16, uint32, uint64, uintptr: 37 + out.Add(k, fmt.Sprint(elem)) 46 38 case encoding.TextMarshaler: 47 - out.Add(k, fmt.Sprintf("%s", elem)) 39 + out.Add(k, fmt.Sprint(elem)) 48 40 default: 49 - return nil, fmt.Errorf("can't marshal query param type: %T", v) 41 + return nil, fmt.Errorf("can't marshal query param '%s' with type: %T", k, v) 50 42 } 51 43 } 52 44 } else { 53 - return nil, fmt.Errorf("can't marshal query param type: %T", v) 45 + return nil, fmt.Errorf("can't marshal query param '%s' with type: %T", k, v) 54 46 } 55 47 } 56 48 }