Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.99 KB | None | 0 0
  1. func getRackID(site, name string) int {
  2.     url := "https://netbox.cloud.selectel.org/api/dcim/racks/?site=" + site
  3.     req, _ := http.NewRequest("GET", url, nil)
  4.     //
  5.     req.Header.Set("accept", "application/json; indent=4")
  6.     req.Header.Set("Content-Type", "application/json")
  7.     req.Header.Set("Authorization", "Token "+"")
  8.  
  9.     client := &http.Client{}
  10.     resp, _ := client.Do(req)
  11.     body, _ := ioutil.ReadAll(resp.Body)
  12.     var res = &Response{}
  13.     js :=json.Unmarshal(body,res)
  14.     fmt.Print(js)
  15.     defer resp.Body.Close()
  16.     return 0
  17.  
  18. type Site struct {
  19.     Id   int    `json:"id"`
  20.     Url  string `json:"url"`
  21.     Name string `json:"name"`
  22.     Slug string `json:"slug"`
  23. }
  24.  
  25. type RackGroup struct {
  26.     Id        int    `json:"id"`
  27.     Url       string `json:"url"`
  28.     Name      string `json:"name"`
  29.     Slug      string `json:"slug"`
  30.     RackCount int    `json:"rack_count"`
  31. }
  32.  
  33. type Tenant struct {
  34.     Id   int    `json:"id"`
  35.     Url  string `json:"url"`
  36.     Name string `json:"name"`
  37.     Slug string `json:"slug"`
  38. }
  39.  
  40. type Status struct {
  41.     Label string `json:"label"`
  42.     Value int    `json:"value"`
  43. }
  44.  
  45. type Role struct {
  46.     Id        int    `json:"id"`
  47.     Url       string `json:"url"`
  48.     Name      string `json:"name"`
  49.     Slug      string `json:"slug"`
  50.     RackCount int    `json:"rack_count"`
  51. }
  52.  
  53. type Type struct {
  54.     Label string `json:"label"`
  55.     Value int    `json:"value"`
  56. }
  57.  
  58. type Width struct {
  59.     Label string `json:"label"`
  60.     Value int    `json:"value"`
  61. }
  62.  
  63. type OuterUnit struct {
  64.     Label string `json:"label"`
  65.     Value int    `json:"value"`
  66. }
  67.  
  68. type Results struct {
  69.     Id             int               `json:"id"`
  70.     Name           string            `json:"name"`
  71.     FacilityId     string            `json:"facility_id"`
  72.     DisplayName    string            `json:"display_name"`
  73.     Site           Site              `json:"site"`
  74.     Group          RackGroup         `json:"group"`
  75.     Tenant         Tenant            `json:"tenant"`
  76.     Status         Status            `json:"status"`
  77.     Role           Role              `json:"role"`
  78.     Serial         string            `json:"serial"`
  79.     AssetTag       string            `json:"asset_tag"`
  80.     Type           Type              `json:"type"`
  81.     Width          Width             `json:"width"`
  82.     Uheight        int               `json:"u_height"`
  83.     DescUnits      bool              `json:"desc_units"`
  84.     OuterWidth     int               `json:"outer_width"`
  85.     OuterDepth     int               `json:"outer_depth"`
  86.     OuterUnit      OuterUnit         `json:"outer_unit"`
  87.     Comments       string            `json:"comments"`
  88.     Tags           []string          `json:"tags"`
  89.     CustomFields   map[string]string `json:"custom_fields"`
  90.     Created        string            `json:"created"`
  91.     LastUpdated    string            `json:"last_updated"`
  92.     DeviceCount    int               `json:"device_count"`
  93.     PowerfeedCount int               `json:"powerfeed_count"`
  94. }
  95.  
  96. type Response struct {
  97.     Count    int       `json:"count"`
  98.     Next     string    `json:"next"`
  99.     Previous string    `json:"previous"`
  100.     Results  []Results `json:"results"`
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement