package utils import ( "encoding/json" "fmt" "strings" "github.com/99designs/gqlgen/client" "github.com/mitchellh/mapstructure" ) type Response struct { Data interface{} `json:"data"` Errors json.RawMessage `json:"errors"` Extensions map[string]interface{} `json:"extensions"` } func FilterEdgeRoles(roles []string) []string { edgeRoles := make([]string, 0) for _, role := range roles { if strings.HasPrefix(role, "EDGE") { edgeRoles = append(edgeRoles, role) } } return edgeRoles } func GetGraphqlResponse(body []byte) (*Response, error) { respDataRaw := &Response{} if body != nil { if err := json.Unmarshal(body, &respDataRaw); err != nil { return nil, fmt.Errorf("failed parse response body to json: %w", err) } } return respDataRaw, nil } func GetGraphqlRequest(body []byte) (*client.Request, error) { respDataRaw := &client.Request{} if body != nil { if err := json.Unmarshal(body, &respDataRaw); err != nil { return nil, fmt.Errorf("failed parse request body to json: %w", err) } } return respDataRaw, nil } func Unpack(data interface{}, into interface{}) error { d, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ Result: into, TagName: "json", ErrorUnused: false, ZeroFields: true, }) if err != nil { return fmt.Errorf("mapstructure: %s", err.Error()) } return d.Decode(data) }