github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/internal/command/jsonprovider/schema.go (about)

     1  package jsonprovider
     2  
     3  import (
     4  	"github.com/eliastor/durgaform/internal/configs/configschema"
     5  )
     6  
     7  type schema struct {
     8  	Version uint64 `json:"version"`
     9  	Block   *block `json:"block,omitempty"`
    10  }
    11  
    12  // marshalSchema is a convenience wrapper around mashalBlock. Schema version
    13  // should be set by the caller.
    14  func marshalSchema(block *configschema.Block) *schema {
    15  	if block == nil {
    16  		return &schema{}
    17  	}
    18  
    19  	var ret schema
    20  	ret.Block = marshalBlock(block)
    21  
    22  	return &ret
    23  }
    24  
    25  func marshalSchemas(blocks map[string]*configschema.Block, rVersions map[string]uint64) map[string]*schema {
    26  	if blocks == nil {
    27  		return map[string]*schema{}
    28  	}
    29  	ret := make(map[string]*schema, len(blocks))
    30  	for k, v := range blocks {
    31  		ret[k] = marshalSchema(v)
    32  		version, ok := rVersions[k]
    33  		if ok {
    34  			ret[k].Version = version
    35  		}
    36  	}
    37  	return ret
    38  }