...

Source file src/victortoso.com/qapi-go/pkg/qapi/helpers.go

Documentation: victortoso.com/qapi-go/pkg/qapi

     1  package qapi
     2  
     3  import (
     4  	"encoding/json"
     5  	"strings"
     6  )
     7  
     8  // Alias for go version lower than 1.18
     9  type Any = interface{}
    10  
    11  // Creates a decoder that errors on unknown Fields
    12  // Returns true if successfully decoded @from string @into type
    13  // Returns false without error is failed with "unknown field"
    14  // Returns false with error is a different error was found
    15  func StrictDecode(into interface{}, from []byte) error {
    16  	dec := json.NewDecoder(strings.NewReader(string(from)))
    17  	dec.DisallowUnknownFields()
    18  
    19  	if err := dec.Decode(into); err != nil {
    20  		return err
    21  	}
    22  	return nil
    23  }
    24  

View as plain text