func ValidateSchema(schema, cfg string) []serror.SnapError {
	return cfgValidator.validateSchema(schema, cfg)
}
Validate an input JSON string against the input schema (and return a set of errors
or nil if the input JSON string matches the constraints defined in that schema)
package cfgfile
import (
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
	"github.com/ghodss/yaml"
	"github.com/intelsdi-x/snap/core/serror"
	"github.com/xeipuuv/gojsonschema"
)
type reader interface {
	ReadFile(s string) ([]byte, error)
}
type cfgReaderType struct{}
func (r *cfgReaderType) ReadFile(s string) ([]byte, error) {
	return ioutil.ReadFile(s)
}
var cfgReader reader
type schemaValidator interface {
	validateSchema(schema, cfg string) []serror.SnapError
}
type schemaValidatorType struct{}
func (r *schemaValidatorType) validateSchema(schema, cfg string) []serror.SnapError {
	schemaLoader := gojsonschema.NewStringLoader(schema)
	testDoc := gojsonschema.NewStringLoader(cfg)
	result, err := gojsonschema.Validate(schemaLoader, testDoc)
	var serrors []serror.SnapError
	if err != nil {
		serrors = append(serrors, serror.New(err))
		return serrors
	}
	if result.Valid() {
		return nil
	}
	for _, err := range result.Errors() {
		serr := serror.New(errors.New("Validate schema error"))
		serr.SetFields(map[string]interface{}{
			"value":       err.Value(),
			"context":     err.Context().String("::"),
			"description": err.Description(),
		})
		serrors = append(serrors, serr)
	}
	return serrors
}
var cfgValidator schemaValidator
func init() {
	cfgReader = &cfgReaderType{}
	cfgValidator = &schemaValidatorType{}
}
func Read(path string, v interface{}, schema string) []serror.SnapError {
	b, err := cfgReader.ReadFile(path)
	if err != nil {
		return []serror.SnapError{serror.New(err)}
	}
	b = []byte(os.ExpandEnv(string(b)))
	jb, err := yaml.YAMLToJSON(b)
	if err != nil {
		return []serror.SnapError{serror.New(fmt.Errorf("error converting YAML to JSON: %v", err))}
	}
	if errors := cfgValidator.validateSchema(schema, string(jb)); errors != nil {
		return errors
	}
	if parseErr := json.Unmarshal(jb, v); parseErr != nil {
		tmpErr := strings.TrimPrefix(parseErr.Error(), "error converting YAML to JSON: yaml: ")
		errRet := strings.TrimPrefix(tmpErr, "error unmarshaling JSON: json: ")
		return []serror.SnapError{serror.New(fmt.Errorf("Error while parsing configuration file: %v", errRet))}
	}
	return nil
}