github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/command/jsonformat/jsondiff/types.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package jsondiff
     5  
     6  import "fmt"
     7  
     8  type Type string
     9  
    10  const (
    11  	Number Type = "number"
    12  	Object Type = "object"
    13  	Array  Type = "array"
    14  	Bool   Type = "bool"
    15  	String Type = "string"
    16  	Null   Type = "null"
    17  )
    18  
    19  func GetType(json interface{}) Type {
    20  	switch json.(type) {
    21  	case []interface{}:
    22  		return Array
    23  	case float64:
    24  		return Number
    25  	case string:
    26  		return String
    27  	case bool:
    28  		return Bool
    29  	case nil:
    30  		return Null
    31  	case map[string]interface{}:
    32  		return Object
    33  	default:
    34  		panic(fmt.Sprintf("unrecognized json type %T", json))
    35  	}
    36  }