github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/courier/client/client_demo/client__generated.go (about)

     1  package client_demo
     2  
     3  import (
     4  	"fmt"
     5  	mime_multipart "mime/multipart"
     6  
     7  	golib_tools_courier "github.com/johnnyeven/libtools/courier"
     8  	golib_tools_courier_status_error "github.com/johnnyeven/libtools/courier/status_error"
     9  
    10  	golib_tools_courier_client "github.com/johnnyeven/libtools/courier/client"
    11  )
    12  
    13  type ClientDemoInterface interface {
    14  	Create(req CreateRequest, metas ...golib_tools_courier.Metadata) (resp *CreateResponse, err error)
    15  	FileDownload(metas ...golib_tools_courier.Metadata) (resp *FileDownloadResponse, err error)
    16  	FormMultipartWithFile(req FormMultipartWithFileRequest, metas ...golib_tools_courier.Metadata) (resp *FormMultipartWithFileResponse, err error)
    17  	FormMultipartWithFiles(req FormMultipartWithFilesRequest, metas ...golib_tools_courier.Metadata) (resp *FormMultipartWithFilesResponse, err error)
    18  	FormURLEncoded(req FormURLEncodedRequest, metas ...golib_tools_courier.Metadata) (resp *FormURLEncodedResponse, err error)
    19  	GetByID(req GetByIDRequest, metas ...golib_tools_courier.Metadata) (resp *GetByIDResponse, err error)
    20  }
    21  
    22  type ClientDemo struct {
    23  	golib_tools_courier_client.Client
    24  }
    25  
    26  func (ClientDemo) MarshalDefaults(v interface{}) {
    27  	if cl, ok := v.(*ClientDemo); ok {
    28  		cl.Name = "demo"
    29  		cl.Client.MarshalDefaults(&cl.Client)
    30  	}
    31  }
    32  
    33  func (c ClientDemo) Init() {
    34  	c.CheckService()
    35  }
    36  
    37  func (c ClientDemo) CheckService() {
    38  	err := c.Request(c.Name+".Check", "HEAD", "/", nil).
    39  		Do().
    40  		Into(nil)
    41  	statusErr := golib_tools_courier_status_error.FromError(err)
    42  	if statusErr.Code == int64(golib_tools_courier_status_error.RequestTimeout) {
    43  		panic(fmt.Errorf("service %s have some error %s", c.Name, statusErr))
    44  	}
    45  }
    46  
    47  type CreateRequest struct {
    48  	//
    49  	Body Data `fmt:"json" in:"body"`
    50  }
    51  
    52  func (c ClientDemo) Create(req CreateRequest, metas ...golib_tools_courier.Metadata) (resp *CreateResponse, err error) {
    53  	resp = &CreateResponse{}
    54  	resp.Meta = golib_tools_courier.Metadata{}
    55  
    56  	err = c.Request(c.Name+".Create", "POST", "/demo/crud/", req, metas...).
    57  		Do().
    58  		BindMeta(resp.Meta).
    59  		Into(&resp.Body)
    60  
    61  	return
    62  }
    63  
    64  type CreateResponse struct {
    65  	Meta golib_tools_courier.Metadata
    66  	Body []byte
    67  }
    68  
    69  func (c ClientDemo) FileDownload(metas ...golib_tools_courier.Metadata) (resp *FileDownloadResponse, err error) {
    70  	resp = &FileDownloadResponse{}
    71  	resp.Meta = golib_tools_courier.Metadata{}
    72  
    73  	err = c.Request(c.Name+".FileDownload", "GET", "/demo/files", nil, metas...).
    74  		Do().
    75  		BindMeta(resp.Meta).
    76  		Into(&resp.Body)
    77  
    78  	return
    79  }
    80  
    81  type FileDownloadResponse struct {
    82  	Meta golib_tools_courier.Metadata
    83  	Body []byte
    84  }
    85  
    86  type FormMultipartWithFileRequest struct {
    87  	//
    88  	Body struct {
    89  		//
    90  		Data Data `json:"data,omitempty"`
    91  		//
    92  		File *mime_multipart.FileHeader `json:"file"`
    93  		//
    94  		Slice []string `json:"slice,omitempty"`
    95  		//
    96  		String string `json:"string,omitempty"`
    97  	} `in:"formData,multipart"`
    98  }
    99  
   100  func (c ClientDemo) FormMultipartWithFile(req FormMultipartWithFileRequest, metas ...golib_tools_courier.Metadata) (resp *FormMultipartWithFileResponse, err error) {
   101  	resp = &FormMultipartWithFileResponse{}
   102  	resp.Meta = golib_tools_courier.Metadata{}
   103  
   104  	err = c.Request(c.Name+".FormMultipartWithFile", "POST", "/demo/forms/multipart", req, metas...).
   105  		Do().
   106  		BindMeta(resp.Meta).
   107  		Into(&resp.Body)
   108  
   109  	return
   110  }
   111  
   112  type FormMultipartWithFileResponse struct {
   113  	Meta golib_tools_courier.Metadata
   114  	Body []byte
   115  }
   116  
   117  type FormMultipartWithFilesRequest struct {
   118  	//
   119  	Body struct {
   120  		//
   121  		Files []*mime_multipart.FileHeader `json:"files"`
   122  	} `in:"formData,multipart"`
   123  }
   124  
   125  func (c ClientDemo) FormMultipartWithFiles(req FormMultipartWithFilesRequest, metas ...golib_tools_courier.Metadata) (resp *FormMultipartWithFilesResponse, err error) {
   126  	resp = &FormMultipartWithFilesResponse{}
   127  	resp.Meta = golib_tools_courier.Metadata{}
   128  
   129  	err = c.Request(c.Name+".FormMultipartWithFiles", "POST", "/demo/forms/multipart-with-files", req, metas...).
   130  		Do().
   131  		BindMeta(resp.Meta).
   132  		Into(&resp.Body)
   133  
   134  	return
   135  }
   136  
   137  type FormMultipartWithFilesResponse struct {
   138  	Meta golib_tools_courier.Metadata
   139  	Body []byte
   140  }
   141  
   142  type FormURLEncodedRequest struct {
   143  	//
   144  	Body struct {
   145  		//
   146  		Data Data `json:"data"`
   147  		//
   148  		Slice []string `json:"slice"`
   149  		//
   150  		String string `json:"string"`
   151  	} `in:"formData"`
   152  }
   153  
   154  func (c ClientDemo) FormURLEncoded(req FormURLEncodedRequest, metas ...golib_tools_courier.Metadata) (resp *FormURLEncodedResponse, err error) {
   155  	resp = &FormURLEncodedResponse{}
   156  	resp.Meta = golib_tools_courier.Metadata{}
   157  
   158  	err = c.Request(c.Name+".FormURLEncoded", "POST", "/demo/forms/url-encoded", req, metas...).
   159  		Do().
   160  		BindMeta(resp.Meta).
   161  		Into(&resp.Body)
   162  
   163  	return
   164  }
   165  
   166  type FormURLEncodedResponse struct {
   167  	Meta golib_tools_courier.Metadata
   168  	Body []byte
   169  }
   170  
   171  type GetByIDRequest struct {
   172  	//
   173  	Status ResourceStatus `in:"query" name:"status"`
   174  	//
   175  	ID string `in:"path" name:"id"`
   176  	//
   177  	Name string `in:"query" name:"name,omitempty"`
   178  	//
   179  	Label []string `in:"query" name:"label,omitempty"`
   180  }
   181  
   182  func (c ClientDemo) GetByID(req GetByIDRequest, metas ...golib_tools_courier.Metadata) (resp *GetByIDResponse, err error) {
   183  	resp = &GetByIDResponse{}
   184  	resp.Meta = golib_tools_courier.Metadata{}
   185  
   186  	err = c.Request(c.Name+".GetByID", "GET", "/demo/crud/:id", req, metas...).
   187  		Do().
   188  		BindMeta(resp.Meta).
   189  		Into(&resp.Body)
   190  
   191  	return
   192  }
   193  
   194  type GetByIDResponse struct {
   195  	Meta golib_tools_courier.Metadata
   196  	Body GetByID
   197  }
   198  
   199  func (c ClientDemo) Swagger(metas ...golib_tools_courier.Metadata) (resp *SwaggerResponse, err error) {
   200  	resp = &SwaggerResponse{}
   201  	resp.Meta = golib_tools_courier.Metadata{}
   202  
   203  	err = c.Request(c.Name+".Swagger", "GET", "/demo", nil, metas...).
   204  		Do().
   205  		BindMeta(resp.Meta).
   206  		Into(&resp.Body)
   207  
   208  	return
   209  }
   210  
   211  type SwaggerResponse struct {
   212  	Meta golib_tools_courier.Metadata
   213  	Body JSONBytes
   214  }