package netboxgo import ( "context" "net/http" "net/url" "github.com/gorilla/schema" ) type DeviceRolesService service type DeviceRoles struct { Count int `json:"count"` Next string `json:"next"` Previous string `json:"previous"` Results []DeviceRole `json:"results"` } type DeviceRole struct { ID int `json:"id"` URL string `json:"url"` Name string `json:"name"` Slug string `json:"slug"` Color string `json:"color"` VMRole bool `json:"vm_role"` Description string `json:"description"` DeviceCount int `json:"device_count"` VirtualmachineCount int `json:"virtualmachine_count"` } // DeviceTypeFilter is used to filter dcim_device_roles query to the Netbox API type DeviceRoleFilter struct { Offset int64 `schema:"offset,omitempty"` Limit int64 `schema:"limit,omitempty"` // User specific filters ID string `schema:"id,omitempty"` Name string `schema:"name,omitempty"` Slug string `schema:"slug,omitempty"` Color string `schema:"color,omitempty"` VMRole string `schema:"vm_role,omitempty"` Q string `schema:"q,omitempty"` } const deviceRolesPath = dcimPath + "/device-roles" // List deviceroles. DeviceRoleFilter is used to list based on filter queries. func (s *DeviceRolesService) List(ctx context.Context, f *DeviceRoleFilter) (*DeviceRoles, error) { var deviceroles DeviceRoles var query string var req *http.Request var err error encoder := schema.NewEncoder() form := url.Values{} err = encoder.Encode(f, form) if err != nil { return &deviceroles, err } query = form.Encode() req, err = s.client.newRequest(ctx, "GET", deviceRolesPath, query, nil) if err != nil { return &deviceroles, err } _, err = s.client.do(req, &deviceroles) if err != nil { return &deviceroles, err } return &deviceroles, nil } // var err error // var req *http.Request // req, err = s.client.newRequest(ctx, "POST", deviceRolesPath, "", c) // if err != nil { // return fmt.Errorf("unable to create request: %w", err) // } // _, err = s.client.do(req, nil) // if err != nil { // return fmt.Errorf("unable to do request: %w", err) // } // return nil // } // // Update a device-role // func (s *DeviceRolesService) Update(ctx context.Context, id string, c *UpdateDevice) error { // var req *http.Request // var err error // path := fmt.Sprintf("%s/%s", deviceRolesPath, id) // req, err = s.client.newRequest(ctx, "PATCH", path, "", c) // if err != nil { // return fmt.Errorf("unable to create request: %w", err) // } // _, err = s.client.do(req, nil) // if err != nil { // return fmt.Errorf("unable to do request: %w", err) // } // return nil // }