types.go 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package resource
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. )
  6. const DefaultTag = "latest"
  7. type Source struct {
  8. Repository string `json:"repository"`
  9. Tag Tag `json:"tag"`
  10. Username string `json:"username"`
  11. Password string `json:"password"`
  12. Debug bool `json:"debug"`
  13. }
  14. func (source *Source) Name() string {
  15. return fmt.Sprintf("%s:%s", source.Repository, source.Tag)
  16. }
  17. type Tag string
  18. func (tag *Tag) UnmarshalJSON(b []byte) error {
  19. var n json.Number
  20. err := json.Unmarshal(b, &n)
  21. if err != nil {
  22. return err
  23. }
  24. if n.String() == "" {
  25. *tag = Tag(DefaultTag)
  26. return nil
  27. }
  28. *tag = Tag(n.String())
  29. return nil
  30. }
  31. type Version struct {
  32. Digest string `json:"digest"`
  33. }
  34. type MetadataField struct {
  35. Name string `json:"name"`
  36. Value string `json:"value"`
  37. }
  38. type GetParams struct {
  39. RawFormat string `json:"format"`
  40. }
  41. func (p GetParams) Format() string {
  42. if p.RawFormat == "" {
  43. return "rootfs"
  44. }
  45. return p.RawFormat
  46. }
  47. type PutParams struct {
  48. Image string `json:"image"`
  49. }