github.com/emreu/go-swagger@v0.22.1/examples/task-tracker/restapi/operations/tasks/list_tasks_urlbuilder.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package tasks 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 // ListTasksURL generates an URL for the list tasks operation 17 type ListTasksURL struct { 18 PageSize *int32 19 SinceID *int64 20 Status []string 21 Tags []string 22 23 _basePath string 24 // avoid unkeyed usage 25 _ struct{} 26 } 27 28 // WithBasePath sets the base path for this url builder, only required when it's different from the 29 // base path specified in the swagger spec. 30 // When the value of the base path is an empty string 31 func (o *ListTasksURL) WithBasePath(bp string) *ListTasksURL { 32 o.SetBasePath(bp) 33 return o 34 } 35 36 // SetBasePath sets the base path for this url builder, only required when it's different from the 37 // base path specified in the swagger spec. 38 // When the value of the base path is an empty string 39 func (o *ListTasksURL) SetBasePath(bp string) { 40 o._basePath = bp 41 } 42 43 // Build a url path and query string 44 func (o *ListTasksURL) Build() (*url.URL, error) { 45 var _result url.URL 46 47 var _path = "/tasks" 48 49 _basePath := o._basePath 50 if _basePath == "" { 51 _basePath = "/api" 52 } 53 _result.Path = golangswaggerpaths.Join(_basePath, _path) 54 55 qs := make(url.Values) 56 57 var pageSizeQ string 58 if o.PageSize != nil { 59 pageSizeQ = swag.FormatInt32(*o.PageSize) 60 } 61 if pageSizeQ != "" { 62 qs.Set("pageSize", pageSizeQ) 63 } 64 65 var sinceIDQ string 66 if o.SinceID != nil { 67 sinceIDQ = swag.FormatInt64(*o.SinceID) 68 } 69 if sinceIDQ != "" { 70 qs.Set("sinceId", sinceIDQ) 71 } 72 73 var statusIR []string 74 for _, statusI := range o.Status { 75 statusIS := statusI 76 if statusIS != "" { 77 statusIR = append(statusIR, statusIS) 78 } 79 } 80 81 status := swag.JoinByFormat(statusIR, "pipes") 82 83 if len(status) > 0 { 84 qsv := status[0] 85 if qsv != "" { 86 qs.Set("status", qsv) 87 } 88 } 89 90 var tagsIR []string 91 for _, tagsI := range o.Tags { 92 tagsIS := tagsI 93 if tagsIS != "" { 94 tagsIR = append(tagsIR, tagsIS) 95 } 96 } 97 98 tags := swag.JoinByFormat(tagsIR, "") 99 100 if len(tags) > 0 { 101 qsv := tags[0] 102 if qsv != "" { 103 qs.Set("tags", qsv) 104 } 105 } 106 107 _result.RawQuery = qs.Encode() 108 109 return &_result, nil 110 } 111 112 // Must is a helper function to panic when the url builder returns an error 113 func (o *ListTasksURL) Must(u *url.URL, err error) *url.URL { 114 if err != nil { 115 panic(err) 116 } 117 if u == nil { 118 panic("url can't be nil") 119 } 120 return u 121 } 122 123 // String returns the string representation of the path with query string 124 func (o *ListTasksURL) String() string { 125 return o.Must(o.Build()).String() 126 } 127 128 // BuildFull builds a full url with scheme, host, path and query string 129 func (o *ListTasksURL) BuildFull(scheme, host string) (*url.URL, error) { 130 if scheme == "" { 131 return nil, errors.New("scheme is required for a full url on ListTasksURL") 132 } 133 if host == "" { 134 return nil, errors.New("host is required for a full url on ListTasksURL") 135 } 136 137 base, err := o.Build() 138 if err != nil { 139 return nil, err 140 } 141 142 base.Scheme = scheme 143 base.Host = host 144 return base, nil 145 } 146 147 // StringFull returns the string representation of a complete url 148 func (o *ListTasksURL) StringFull(scheme, host string) string { 149 return o.Must(o.BuildFull(scheme, host)).String() 150 }