当前位置: 首页>>代码示例>>Golang>>正文


Golang Validation.Range方法代码示例

本文整理汇总了Golang中github.com/astaxie/beego/validation.Validation.Range方法的典型用法代码示例。如果您正苦于以下问题:Golang Validation.Range方法的具体用法?Golang Validation.Range怎么用?Golang Validation.Range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/astaxie/beego/validation.Validation的用法示例。


在下文中一共展示了Validation.Range方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: validateConfigSpecs

func (p *Plugin) validateConfigSpecs(path string) bool {
	valid := validation.Validation{}

	data, err := ioutil.ReadFile(path)
	if err != nil {
		return false
	}

	json.Unmarshal(data, &p.config)

	//Validate mandatory fields.
	if result := valid.Required(p.config.Version, "Version"); !result.Ok {
		p.errorLog = append(p.errorLog, "Version cannot be empty")
	}
	//Version must complient with  SemVer v2.0.0
	if result := valid.Match(p.config.Version, regexp.MustCompile("^(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$"), "Version"); !result.Ok {
		p.errorLog = append(p.errorLog, "Version must be in format of X.X.X (complient to Semver v2.0.0)")
	}
	if result := valid.Required(p.config.Platform.OS, "OS"); !result.Ok {
		p.errorLog = append(p.errorLog, "OS can be not empty")
	}
	if result := valid.Required(p.config.Platform.Arch, "Platform.Arch"); !result.Ok {
		p.errorLog = append(p.errorLog, "Platform.Arch is empty")
	}

	for _, env := range p.config.Process.Env {
		//If Process defined, env cannot be empty
		if result := valid.Required(env, "Process.Env"); !result.Ok {
			p.errorLog = append(p.errorLog, "Atleast one Process.Env is empty")
			break
		}
	}
	if result := valid.Required(p.config.Root.Path, "Root.Path"); !result.Ok {
		p.errorLog = append(p.errorLog, "Root.Path is empty")
	}
	//Iterate over Mount array
	for _, mount := range p.config.Mounts {
		//If Mount points defined, it must define these three.
		if result := valid.Required(mount.Source, "Mount.Source"); !result.Ok {
			p.errorLog = append(p.errorLog, "Atleast one Mount.Source is empty")
			break
		}
		if result := valid.Required(mount.Destination, "Mount.Destination"); !result.Ok {
			p.errorLog = append(p.errorLog, "Atleast one Mount.Destination is empty")
			break
		}
	}

	//Iterate over Mount array
	for _, mount := range p.config.Mounts {
		//If Mount points defined, it must define these three.
		if result := valid.Required(mount.Type, "Mount.Type"); !result.Ok {
			p.errorLog = append(p.errorLog, "Atleast one Mount.Type is empty")
			break
		}
		if result := valid.Required(mount.Source, "Mount.Source"); !result.Ok {
			p.errorLog = append(p.errorLog, "Atleast one Mount.Source is empty")
			break
		}
	}
	// Hooks Prestart
	for _, hook := range p.config.Hooks.Prestart {
		if result := valid.Required(hook.Path, "Hooks.Path"); !result.Ok {
			p.errorLog = append(p.errorLog, "Prestart hook Path cannot be empty")
			break
		}
	}

	// Hooks Poststop
	for _, hook := range p.config.Hooks.Poststop {
		if result := valid.Required(hook.Path, "Hooks.Path"); !result.Ok {
			p.errorLog = append(p.errorLog, "Poststop hook Path cannot be empty")
			break
		}
	}

	// UIDMappings mapping check.
	for _, uid := range p.config.Linux.UIDMappings {
		if result := valid.Range(uid.HostID, 0, 2147483647, "IDMapping.HostID"); !result.Ok {
			p.errorLog = append(p.errorLog, "UIDMapping's HostID must be valid integer")
			break
		}
		if result := valid.Range(uid.ContainerID, 0, 2147483647, "IDMapping.ContainerID"); !result.Ok {
			p.errorLog = append(p.errorLog, "UIDMapping's ContainerID must be valid integer")
			break
		}
		if result := valid.Range(uid.Size, 0, 2147483647, "IDMapping.Size"); !result.Ok {
			p.errorLog = append(p.errorLog, "UIDMapping's Size must be valid integer")
			break
		}
	}

	// GIDMappings mapping check.
	for _, gid := range p.config.Linux.GIDMappings {
		if result := valid.Range(gid.HostID, 0, 2147483647, "IDMapping.HostID"); !result.Ok {
			p.errorLog = append(p.errorLog, "GIDMapping's HostID must be valid integer")
			break
		}
		if result := valid.Range(gid.ContainerID, 0, 2147483647, "IDMapping.ContainerID"); !result.Ok {
			p.errorLog = append(p.errorLog, "GIDMapping's ContainerID must be valid integer")
//.........这里部分代码省略.........
开发者ID:kunalkushwaha,项目名称:octool,代码行数:101,代码来源:linux.go


注:本文中的github.com/astaxie/beego/validation.Validation.Range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。