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