github.com/vcilabs/webrpc@v0.5.2-0.20201116131534-162e27b1b33b/schema/parser.go (about)

     1  package schema
     2  
     3  import (
     4  	"encoding/json"
     5  	"regexp"
     6  )
     7  
     8  type Parser interface {
     9  	Parse(schema *WebRPCSchema) error
    10  }
    11  
    12  func ParseSchemaJSON(jsondata []byte) (*WebRPCSchema, error) {
    13  	var schema *WebRPCSchema
    14  	err := json.Unmarshal(jsondata, &schema)
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  
    19  	err = schema.Validate()
    20  	if err != nil {
    21  		return schema, err
    22  	}
    23  
    24  	return schema, nil
    25  }
    26  
    27  var NameWhitelistRexp = regexp.MustCompile(`^[a-zA-Z]+[a-zA-Z0-9_]*$`)
    28  
    29  func IsValidArgName(s string) bool {
    30  	if !NameWhitelistRexp.MatchString(s) {
    31  		return false
    32  	}
    33  	return true
    34  }