gitea源码

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