structures.go raw

   1  package client
   2  
   3  import (
   4  	"fmt"
   5  	"net/http"
   6  )
   7  
   8  // Config struct wraps the credential info for the Client.
   9  type Config struct {
  10  	Username  string
  11  	Password  string
  12  	HostURL   string
  13  	UserAgent string
  14  }
  15  
  16  // Client struct wraps the http client, config and ultradns api base url.
  17  type Client struct {
  18  	httpClient *http.Client
  19  	baseURL    string
  20  	userAgent  string
  21  	logger     logger
  22  }
  23  
  24  // Response wraps the success and error response data.
  25  type Response struct {
  26  	Data      interface{}
  27  	ErrorList []*ErrorResponse
  28  	Error     *ErrorResponse
  29  	retry     int
  30  }
  31  
  32  // ErrorResponse wraps the structure ultradns error response.
  33  type ErrorResponse struct {
  34  	ErrorCode        int    `json:"errorCode,omitempty"`
  35  	ErrorMessage     string `json:"errorMessage,omitempty"`
  36  	ErrorString      string `json:"error,omitempty"`
  37  	ErrorDescription string `json:"error_description,omitempty"`
  38  }
  39  
  40  // SuccessResponse wraps the structure ultradns success response.
  41  type SuccessResponse struct {
  42  	Message string `json:"message,omitempty"`
  43  }
  44  
  45  func (e ErrorResponse) String() string {
  46  	return fmt.Sprintf("{ code: '%v', message: '%v' }", e.ErrorCode, e.ErrorMessage)
  47  }
  48  
  49  func Target(i interface{}) *Response {
  50  	return &Response{Data: i}
  51  }
  52