You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's convenient to use webrpc as a schema source of truth for types, but sometimes it's nice to do use it for simple constants / configs / values across clients.
I'm proposing a new "value" type,
RIDL
# we can just define some json here
value NetworkNames: map<string,Chain> = '''{
"blah": { etc }
}'''
value AuthorName: string = "Peter"
package schema
import (
"fmt"
"strings"
)
// in the future.. see: https://github.com/webrpc/webrpc/issues/122
type Value struct {
Name string `json:"name"`
Type string `json:"type"`
Value interface{} `json:"value"`
// Schema *WebRPCSchema `json:"-"` // denormalize/back-reference
}
func (s *Value) Parse(schema *WebRPCSchema) error {
if s.Name == "" {
return fmt.Errorf("schema error: name cannot be empty")
}
if s.Value == nil {
return fmt.Errorf("schema error: value cannot be empty")
}
// check for duplicate names
nameList := map[string]struct{}{}
for _, sval := range schema.Values {
nName := strings.ToLower(sval.Name)
if _, ok := nameList[nName]; ok {
return fmt.Errorf("schema error: detected duplicate value name of '%s'", sval.Name)
}
nameList[nName] = struct{}{}
}
return nil
}
It's convenient to use webrpc as a schema source of truth for types, but sometimes it's nice to do use it for simple constants / configs / values across clients.
I'm proposing a new "value" type,
RIDL
JSON
The text was updated successfully, but these errors were encountered: