code.gitea.io/gitea@v1.21.7/routers/api/packages/nuget/links.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package nuget 5 6 import ( 7 "fmt" 8 "net/url" 9 ) 10 11 type nextOptions struct { 12 Path string 13 Query url.Values 14 } 15 16 type linkBuilder struct { 17 Base string 18 Next *nextOptions 19 } 20 21 // GetRegistrationIndexURL builds the registration index url 22 func (l *linkBuilder) GetRegistrationIndexURL(id string) string { 23 return fmt.Sprintf("%s/registration/%s/index.json", l.Base, id) 24 } 25 26 // GetRegistrationLeafURL builds the registration leaf url 27 func (l *linkBuilder) GetRegistrationLeafURL(id, version string) string { 28 return fmt.Sprintf("%s/registration/%s/%s.json", l.Base, id, version) 29 } 30 31 // GetPackageDownloadURL builds the download url 32 func (l *linkBuilder) GetPackageDownloadURL(id, version string) string { 33 return fmt.Sprintf("%s/package/%s/%s/%s.%s.nupkg", l.Base, id, version, id, version) 34 } 35 36 // GetPackageMetadataURL builds the package metadata url 37 func (l *linkBuilder) GetPackageMetadataURL(id, version string) string { 38 return fmt.Sprintf("%s/Packages(Id='%s',Version='%s')", l.Base, id, version) 39 } 40 41 func (l *linkBuilder) GetNextURL() string { 42 u, _ := url.Parse(l.Base) 43 u = u.JoinPath(l.Next.Path) 44 q := u.Query() 45 for k, vs := range l.Next.Query { 46 for _, v := range vs { 47 q.Add(k, v) 48 } 49 } 50 u.RawQuery = q.Encode() 51 return u.String() 52 }