github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/generated/restapi/operations/pet/update_pet_with_form_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  	"strings"
    13  )
    14  
    15  // UpdatePetWithFormURL generates an URL for the update pet with form operation
    16  type UpdatePetWithFormURL struct {
    17  	PetID string
    18  
    19  	_basePath string
    20  	// avoid unkeyed usage
    21  	_ struct{}
    22  }
    23  
    24  // WithBasePath sets the base path for this url builder, only required when it's different from the
    25  // base path specified in the swagger spec.
    26  // When the value of the base path is an empty string
    27  func (o *UpdatePetWithFormURL) WithBasePath(bp string) *UpdatePetWithFormURL {
    28  	o.SetBasePath(bp)
    29  	return o
    30  }
    31  
    32  // SetBasePath sets the base path for this url builder, only required when it's different from the
    33  // base path specified in the swagger spec.
    34  // When the value of the base path is an empty string
    35  func (o *UpdatePetWithFormURL) SetBasePath(bp string) {
    36  	o._basePath = bp
    37  }
    38  
    39  // Build a url path and query string
    40  func (o *UpdatePetWithFormURL) Build() (*url.URL, error) {
    41  	var _result url.URL
    42  
    43  	var _path = "/pets/{petId}"
    44  
    45  	petID := o.PetID
    46  	if petID != "" {
    47  		_path = strings.Replace(_path, "{petId}", petID, -1)
    48  	} else {
    49  		return nil, errors.New("petId is required on UpdatePetWithFormURL")
    50  	}
    51  
    52  	_basePath := o._basePath
    53  	if _basePath == "" {
    54  		_basePath = "/v2"
    55  	}
    56  	_result.Path = golangswaggerpaths.Join(_basePath, _path)
    57  
    58  	return &_result, nil
    59  }
    60  
    61  // Must is a helper function to panic when the url builder returns an error
    62  func (o *UpdatePetWithFormURL) Must(u *url.URL, err error) *url.URL {
    63  	if err != nil {
    64  		panic(err)
    65  	}
    66  	if u == nil {
    67  		panic("url can't be nil")
    68  	}
    69  	return u
    70  }
    71  
    72  // String returns the string representation of the path with query string
    73  func (o *UpdatePetWithFormURL) String() string {
    74  	return o.Must(o.Build()).String()
    75  }
    76  
    77  // BuildFull builds a full url with scheme, host, path and query string
    78  func (o *UpdatePetWithFormURL) BuildFull(scheme, host string) (*url.URL, error) {
    79  	if scheme == "" {
    80  		return nil, errors.New("scheme is required for a full url on UpdatePetWithFormURL")
    81  	}
    82  	if host == "" {
    83  		return nil, errors.New("host is required for a full url on UpdatePetWithFormURL")
    84  	}
    85  
    86  	base, err := o.Build()
    87  	if err != nil {
    88  		return nil, err
    89  	}
    90  
    91  	base.Scheme = scheme
    92  	base.Host = host
    93  	return base, nil
    94  }
    95  
    96  // StringFull returns the string representation of a complete url
    97  func (o *UpdatePetWithFormURL) StringFull(scheme, host string) string {
    98  	return o.Must(o.BuildFull(scheme, host)).String()
    99  }