You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudbroker/tasks/models.go

91 lines
1.5 KiB

package tasks
import (
"encoding/json"
"fmt"
"strconv"
)
// Global variable for converting field to desired data type
type InfoResult int
// Method for convert field
func (r *InfoResult) UnmarshalJSON(b []byte) error {
if b[0] == '"' {
b := b[1 : len(b)-1]
if len(b) == 0 {
*r = 0
return nil
}
n, err := strconv.Atoi(string(b))
if err != nil {
return err
}
*r = InfoResult(n)
} else if b[0] == '[' {
res := []interface{}{}
if err := json.Unmarshal(b, &res); err != nil {
return err
}
if n, ok := res[0].(float64); ok {
*r = InfoResult(n)
} else {
return fmt.Errorf("could not unmarshal %v into int", res[0])
}
} else {
n, err := strconv.Atoi(string(b))
if err != nil {
return err
}
*r = InfoResult(n)
}
return nil
}
// Detailed information about task
type RecordTask struct {
// Updated by
UpdatedBy string `json:"updatedBy"`
ItemTask
}
type ItemTask struct {
// Audit ID
AuditID string `json:"auditId"`
// Completed
Completed bool `json:"completed"`
// Error
Error string `json:"error"`
// List of logs
Log []string `json:"log"`
// Final result
Result InfoResult `json:"result"`
// Stage
Stage string `json:"stage"`
// Status
Status string `json:"status"`
// Update time
UpdateTime uint64 `json:"updateTime"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
// List of tasks
type ListTasks struct {
// Data
Data []ItemTask `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}