1 Star 0 Fork 0

mirrors_back / lestrrat-go-jsval

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
string.go 683 Bytes
一键复制 编辑 原始数据 按行查看 历史
Daisuke Maki 提交于 2018-12-05 09:23 . Update paths
package builder
import (
"errors"
"github.com/lestrrat-go/jsschema"
"github.com/lestrrat-go/jsval"
)
func buildStringConstraint(ctx *buildctx, c *jsval.StringConstraint, s *schema.Schema) error {
if len(s.Type) > 0 {
if !s.Type.Contains(schema.StringType) {
return errors.New("schema is not for string")
}
}
if s.MaxLength.Initialized {
c.MaxLength(s.MaxLength.Val)
}
if s.MinLength.Initialized {
c.MinLength(s.MinLength.Val)
}
if pat := s.Pattern; pat != nil {
c.Regexp(pat)
}
if f := s.Format; f != "" {
c.Format(string(f))
}
if lst := s.Enum; len(lst) > 0 {
c.Enum(lst...)
}
if v := s.Default; v != nil {
c.Default(v)
}
return nil
}
1
https://gitee.com/mirrors_back/lestrrat-go-jsval.git
git@gitee.com:mirrors_back/lestrrat-go-jsval.git
mirrors_back
lestrrat-go-jsval
lestrrat-go-jsval
20277e9befc0

搜索帮助