|
| 1 | +// Code generated by gen/gen_test.go DO NOT EDIT. |
| 2 | + |
| 3 | +package namesilo |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "encoding/xml" |
| 8 | + "fmt" |
| 9 | + "io" |
| 10 | + "net/http" |
| 11 | +) |
| 12 | +{{range $key, $value := .Names }} |
| 13 | +// {{ $value.Upper }} Execute operation {{ $value.Lower }}. |
| 14 | +func (c *Client) {{ $value.Upper }}(ctx context.Context, params *{{ $value.Upper }}Params) (*{{ $value.Upper }}, error) { |
| 15 | + resp, err := c.get(ctx, "{{ $value.Lower }}", params) |
| 16 | + if err != nil { |
| 17 | + return nil, err |
| 18 | + } |
| 19 | + |
| 20 | + defer func() { _ = resp.Body.Close() }() |
| 21 | + |
| 22 | + if resp.StatusCode != http.StatusOK { |
| 23 | + return nil, fmt.Errorf("error: HTTP status code %v", resp.StatusCode) |
| 24 | + } |
| 25 | + |
| 26 | + bytes, err := io.ReadAll(resp.Body) |
| 27 | + if err != nil { |
| 28 | + return nil, err |
| 29 | + } |
| 30 | + |
| 31 | + op := &{{ $value.Upper }}{} |
| 32 | + |
| 33 | + err = xml.Unmarshal(bytes, op) |
| 34 | + if err != nil { |
| 35 | + return nil, fmt.Errorf("failed to decode: %w: %s", err, bytes) |
| 36 | + } |
| 37 | + |
| 38 | + switch op.Reply.Code { |
| 39 | + case SuccessfulAPIOperation: |
| 40 | + // Successful API operation |
| 41 | + return op, nil |
| 42 | + case SuccessfulRegistration: |
| 43 | + // Successful registration, but not all provided hosts were valid resulting in our nameservers being used |
| 44 | + return op, nil |
| 45 | + case SuccessfulOrder: |
| 46 | + // Successful order, but there was an error with the contact information provided so your account default contact profile was used |
| 47 | + return op, nil |
| 48 | + default: |
| 49 | + // error |
| 50 | + return op, fmt.Errorf("code: %s, details: %s", op.Reply.Code, op.Reply.Detail) |
| 51 | + } |
| 52 | +} |
| 53 | +{{end}} |
0 commit comments