github.com/johnlanni/go-swagger@v0.19.0/examples/generated/restapi/operations/user/login_user_urlbuilder.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package user 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 // LoginUserURL generates an URL for the login user operation 15 type LoginUserURL struct { 16 Password *string 17 Username *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 *LoginUserURL) WithBasePath(bp string) *LoginUserURL { 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 *LoginUserURL) SetBasePath(bp string) { 36 o._basePath = bp 37 } 38 39 // Build a url path and query string 40 func (o *LoginUserURL) Build() (*url.URL, error) { 41 var _result url.URL 42 43 var _path = "/users/login" 44 45 _basePath := o._basePath 46 if _basePath == "" { 47 _basePath = "/v2" 48 } 49 _result.Path = golangswaggerpaths.Join(_basePath, _path) 50 51 qs := make(url.Values) 52 53 var password string 54 if o.Password != nil { 55 password = *o.Password 56 } 57 if password != "" { 58 qs.Set("password", password) 59 } 60 61 var username string 62 if o.Username != nil { 63 username = *o.Username 64 } 65 if username != "" { 66 qs.Set("username", username) 67 } 68 69 _result.RawQuery = qs.Encode() 70 71 return &_result, nil 72 } 73 74 // Must is a helper function to panic when the url builder returns an error 75 func (o *LoginUserURL) Must(u *url.URL, err error) *url.URL { 76 if err != nil { 77 panic(err) 78 } 79 if u == nil { 80 panic("url can't be nil") 81 } 82 return u 83 } 84 85 // String returns the string representation of the path with query string 86 func (o *LoginUserURL) String() string { 87 return o.Must(o.Build()).String() 88 } 89 90 // BuildFull builds a full url with scheme, host, path and query string 91 func (o *LoginUserURL) BuildFull(scheme, host string) (*url.URL, error) { 92 if scheme == "" { 93 return nil, errors.New("scheme is required for a full url on LoginUserURL") 94 } 95 if host == "" { 96 return nil, errors.New("host is required for a full url on LoginUserURL") 97 } 98 99 base, err := o.Build() 100 if err != nil { 101 return nil, err 102 } 103 104 base.Scheme = scheme 105 base.Host = host 106 return base, nil 107 } 108 109 // StringFull returns the string representation of a complete url 110 func (o *LoginUserURL) StringFull(scheme, host string) string { 111 return o.Must(o.BuildFull(scheme, host)).String() 112 }