github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/generated/restapi/operations/pet/find_pets_by_status_urlbuilder.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package pet
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the generate command
     7  
     8  import (
     9  	"errors"
    10  	"net/url"
    11  	golangswaggerpaths "path"
    12  
    13  	"github.com/go-openapi/swag"
    14  )
    15  
    16  // FindPetsByStatusURL generates an URL for the find pets by status operation
    17  type FindPetsByStatusURL struct {
    18  	Status []string
    19  
    20  	_basePath string
    21  	// avoid unkeyed usage
    22  	_ struct{}
    23  }
    24  
    25  // WithBasePath sets the base path for this url builder, only required when it's different from the
    26  // base path specified in the swagger spec.
    27  // When the value of the base path is an empty string
    28  func (o *FindPetsByStatusURL) WithBasePath(bp string) *FindPetsByStatusURL {
    29  	o.SetBasePath(bp)
    30  	return o
    31  }
    32  
    33  // SetBasePath sets the base path for this url builder, only required when it's different from the
    34  // base path specified in the swagger spec.
    35  // When the value of the base path is an empty string
    36  func (o *FindPetsByStatusURL) SetBasePath(bp string) {
    37  	o._basePath = bp
    38  }
    39  
    40  // Build a url path and query string
    41  func (o *FindPetsByStatusURL) Build() (*url.URL, error) {
    42  	var _result url.URL
    43  
    44  	var _path = "/pets/findByStatus"
    45  
    46  	_basePath := o._basePath
    47  	if _basePath == "" {
    48  		_basePath = "/v2"
    49  	}
    50  	_result.Path = golangswaggerpaths.Join(_basePath, _path)
    51  
    52  	qs := make(url.Values)
    53  
    54  	var statusIR []string
    55  	for _, statusI := range o.Status {
    56  		statusIS := statusI
    57  		if statusIS != "" {
    58  			statusIR = append(statusIR, statusIS)
    59  		}
    60  	}
    61  
    62  	status := swag.JoinByFormat(statusIR, "multi")
    63  
    64  	for _, qsv := range status {
    65  		qs.Add("status", qsv)
    66  	}
    67  
    68  	_result.RawQuery = qs.Encode()
    69  
    70  	return &_result, nil
    71  }
    72  
    73  // Must is a helper function to panic when the url builder returns an error
    74  func (o *FindPetsByStatusURL) Must(u *url.URL, err error) *url.URL {
    75  	if err != nil {
    76  		panic(err)
    77  	}
    78  	if u == nil {
    79  		panic("url can't be nil")
    80  	}
    81  	return u
    82  }
    83  
    84  // String returns the string representation of the path with query string
    85  func (o *FindPetsByStatusURL) String() string {
    86  	return o.Must(o.Build()).String()
    87  }
    88  
    89  // BuildFull builds a full url with scheme, host, path and query string
    90  func (o *FindPetsByStatusURL) BuildFull(scheme, host string) (*url.URL, error) {
    91  	if scheme == "" {
    92  		return nil, errors.New("scheme is required for a full url on FindPetsByStatusURL")
    93  	}
    94  	if host == "" {
    95  		return nil, errors.New("host is required for a full url on FindPetsByStatusURL")
    96  	}
    97  
    98  	base, err := o.Build()
    99  	if err != nil {
   100  		return nil, err
   101  	}
   102  
   103  	base.Scheme = scheme
   104  	base.Host = host
   105  	return base, nil
   106  }
   107  
   108  // StringFull returns the string representation of a complete url
   109  func (o *FindPetsByStatusURL) StringFull(scheme, host string) string {
   110  	return o.Must(o.BuildFull(scheme, host)).String()
   111  }