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


Golang Container.S方法代码示例

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


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

示例1: mergeVolumeConfig

// Merge guest volume/block device configuration with any volumes found in
// host container.
func mergeVolumeConfig(volumeconfig []volumeConfig, guest *gabs.Container) (err error) {
	var mounts *gabs.Container
	if guest.ExistsP("mount") {
		mounts = guest.S("mount")
	} else {
		mounts, _ = guest.ObjectP("mount")
	}
	mmap, _ := mounts.ChildrenMap()
	for _, mount := range mmap {
		var source string
		var path string
		var ok bool
		if source, ok = mount.Path("source").Data().(string); !ok {
			continue
		}
		if path, ok = mount.Path("path").Data().(string); !ok {
			continue
		}
		if source == "blk" && strings.HasPrefix(path, "/dev/ld") {
			return fmt.Errorf("Guest configuration defines " +
				"/dev/ld* block devices, cannot merge with " +
				"host volumes")
		}
	}
	blkIndex := 0
	for _, v := range volumeconfig {
		mp := "/" + v.name
		obj, _ := guest.Object("mount", mp)
		obj.Set("blk", "source")
		obj.Set(fmt.Sprintf("/dev/ld%va", blkIndex), "path")
		blkIndex += 1
	}
	return
}
开发者ID:sjfloat,项目名称:docker-unikernel-runner,代码行数:36,代码来源:guest.go

示例2: scrapeApps

func (e *Exporter) scrapeApps(json *gabs.Container, ch chan<- prometheus.Metric) {
	elements, _ := json.S("apps").Children()
	states := map[string]string{
		"running":    "tasksRunning",
		"staged":     "tasksStaged",
		"healthy":    "tasksHealthy",
		"unhealthy":  "tasksUnhealthy",
		"cpus":       "cpus",
		"mem_in_mb":  "mem",
		"disk_in_mb": "disk",
		"gpus":       "gpus",
		"avg_uptime": "taskStats.startedAfterLastScaling.stats.lifeTime.averageSeconds",
	}

	name := "app_instances"
	gauge, new := e.Gauges.Fetch(name, "Marathon app instance count", "app")
	if new {
		log.Infof("Added gauge %q\n", name)
	}
	gauge.Reset()

	for _, app := range elements {
		id := app.Path("id").Data().(string)
		data := app.Path("instances").Data()
		count, ok := data.(float64)
		if !ok {
			log.Debugf(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for number of app instances\n", data))
			continue
		}

		gauge.WithLabelValues(id).Set(count)

		for key, value := range states {
			name := fmt.Sprintf("app_task_%s", key)
			gauge, new := e.Gauges.Fetch(name, fmt.Sprintf("Marathon app task %s count", key), "app")
			if new {
				log.Infof("Added gauge %q\n", name)
			}

			data := app.Path(value).Data()
			count, ok := data.(float64)
			if !ok {
				log.Debugf(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for number of \"%s\" tasks\n", data, key))
				continue
			}

			gauge.WithLabelValues(id).Set(count)
		}
	}
}
开发者ID:gettyimages,项目名称:marathon_exporter,代码行数:50,代码来源:exporter.go

示例3: PushEvent

// TODO: Properly get commit count
func PushEvent(data *gabs.Container) {
	repo, _ := data.S("repository", "full_name").Data().(string)
	user, _ := data.S("pusher", "name").Data().(string)
	gitio := GitioShort(data.S("head_commit", "url").Data().(string))
	commits, _ := data.S("commits").Children()

	cobj, _ := data.S("commits").ChildrenMap()
	fmt.Printf("[!] Commit # %d\n", len(cobj))
	commitlen := strconv.Itoa(len(cobj))

	message <- "[" + repo + "] " + user + " pushed " + commitlen + " commits " + gitio

	for _, commit := range commits {
		hash := commit.S("id").Data().(string)[0:6]
		msg := commit.S("message").Data().(string)
		user := commit.S("author", "name").Data().(string)

		message <- "[" + repo + "] " + user + " " + hash + " - " + msg
	}
}
开发者ID:XAMPP,项目名称:Gakin,代码行数:21,代码来源:main.go

示例4: PullRequestEvent

func PullRequestEvent(data *gabs.Container) {
	action := data.S("action").Data().(string)

	repo, _ := data.S("repository", "full_name").Data().(string)
	user, _ := data.S("pull_request", "user", "login").Data().(string)
	title, _ := data.S("pull_request", "title").Data().(string)
	inum, _ := data.S("pull_request", "number").Data().(string)

	gitio := GitioShort(data.S("pull_request", "html_url").Data().(string))

	switch action {
	case "opened":
		message <- "[" + repo + "] " + user + " opened pull request #" + inum + " \"" + title + "\" " + gitio
	case "closed":
		if data.S("pull_request", "merged").Data().(bool) {
			message <- "[" + repo + "] " + user + " merged pull request #" + inum + " \"" + title + "\" " + gitio
		} else {
			message <- "[" + repo + "] " + user + " closed pull request #" + inum + " \"" + title + "\" " + gitio
		}
	case "assigned":
		assignee, _ := data.S("pull_request", "assignee", "login").Data().(string)
		message <- "[" + repo + "] " + user + " assigned pull request #" + inum + " \"" + title + "\" to " + assignee + " " + gitio
	default:
		// Ignore it
	}
}
开发者ID:XAMPP,项目名称:Gakin,代码行数:26,代码来源:main.go

示例5: IssuesEvent

func IssuesEvent(data *gabs.Container) {
	action := data.S("action").Data().(string)

	repo, _ := data.S("repository", "full_name").Data().(string)
	user, _ := data.S("issue", "user", "login").Data().(string)
	title, _ := data.S("issue", "title").Data().(string)
	inum, _ := data.S("issue", "id").Data().(string)

	gitio := GitioShort(data.S("issue", "html_url").Data().(string))

	switch action {
	case "opened":
		message <- "[" + repo + "] " + user + " opened issue #" + inum + " \"" + title + "\" " + gitio
	case "closed":
		message <- "[" + repo + "] " + user + " closed issue #" + inum + " \"" + title + "\" " + gitio
	case "reopened":
		message <- "[" + repo + "] " + user + " reopened issue #" + inum + " \"" + title + "\" " + gitio
	case "assigned":
		assignee, _ := data.S("issue", "assignee", "login").Data().(string)
		message <- "[" + repo + "] " + user + " assigned issue #" + inum + " \"" + title + "\" to " + assignee + " " + gitio
	default:
		// Ignore it
	}
}
开发者ID:XAMPP,项目名称:Gakin,代码行数:24,代码来源:main.go


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