client.go 612 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package metadata
  2. import (
  3. "net/http"
  4. "net/url"
  5. "github.com/packethost/packngo"
  6. )
  7. const (
  8. baseUrl = "https://metadata.packet.net"
  9. )
  10. type Client struct {
  11. client *packngo.Client
  12. Metadata MetadataService
  13. Userdata UserdataService
  14. }
  15. type MetadataService interface {
  16. Get() (Metadata, error)
  17. }
  18. type UserdataService interface {
  19. Get() (string, error)
  20. }
  21. func NewClient(httpClient *http.Client) *Client {
  22. c := packngo.NewClient("", "", httpClient)
  23. c.BaseURL, _ = url.Parse(baseUrl)
  24. return &Client{
  25. client: c,
  26. Metadata: &MetadataServiceOp{client: c},
  27. Userdata: &UserdataServiceOp{client: c},
  28. }
  29. }