github.com/kaisawind/go-swagger@v0.19.0/examples/tutorials/custom-server/gen/restapi/operations/get_greeting_urlbuilder.go (about)

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