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


Golang LoaderEntry.AgentName方法代码示例

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


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

示例1: AllLoadersFromManifestID

// Return all the loader entries that match the targeting string for manifest mid
func (db *DB) AllLoadersFromManifestID(mid float64) (ret []mig.LoaderEntry, err error) {
	var mtarg string
	err = db.c.QueryRow(`SELECT target FROM manifests
		WHERE (status='active' OR status='staged') AND id=$1`, mid).Scan(&mtarg)
	if err != nil {
		return
	}
	qs := fmt.Sprintf(`SELECT id, loadername, name, lastseen, enabled
		FROM loaders WHERE enabled=TRUE AND %v`, mtarg)
	rows, err := db.c.Query(qs)
	if err != nil {
		return
	}
	if rows != nil {
		defer rows.Close()
	}
	for rows.Next() {
		var agtname sql.NullString
		nle := mig.LoaderEntry{}
		err = rows.Scan(&nle.ID, &nle.Name, &agtname, &nle.LastSeen, &nle.Enabled)
		if err != nil {
			return ret, err
		}
		// This should always be valid, if it is not that means we have a loader
		// entry updated with a valid env, but a NULL agent name. In that case we
		// just don't set the agent name in the loader entry.
		if agtname.Valid {
			nle.AgentName = agtname.String
		}
		ret = append(ret, nle)
	}
	return
}
开发者ID:ZhuHangpeng,项目名称:mig,代码行数:34,代码来源:loader.go

示例2: SearchLoaders

func (db *DB) SearchLoaders(p search.Parameters) (lrecords []mig.LoaderEntry, err error) {
	var rows *sql.Rows
	ids, err := makeIDsFromParams(p)
	columns := `loaders.id, loaders.loadername, loaders.name, loaders.lastseen, loaders.enabled`
	where := ""
	vals := []interface{}{}
	valctr := 0
	if p.Before.Before(time.Now().Add(search.DefaultWindow - time.Hour)) {
		where += fmt.Sprintf(`loaders.lastseen <= $%d `, valctr+1)
		vals = append(vals, p.Before)
		valctr += 1
	}
	if p.After.After(time.Now().Add(-(search.DefaultWindow - time.Hour))) {
		if valctr > 0 {
			where += " AND "
		}
		where += fmt.Sprintf(`loaders.lastseen >= $%d `, valctr+1)
		vals = append(vals, p.After)
		valctr += 1
	}
	if p.LoaderName != "%" {
		if valctr > 0 {
			where += " AND "
		}
		where += fmt.Sprintf(`loaders.loadername ILIKE $%d`, valctr+1)
		vals = append(vals, p.LoaderName)
		valctr += 1
	}
	if p.AgentName != "%" {
		if valctr > 0 {
			where += " AND "
		}
		where += fmt.Sprintf(`loaders.name ILIKE $%d`, valctr+1)
		vals = append(vals, p.AgentName)
		valctr += 1
	}
	if p.LoaderID != "∞" {
		if valctr > 0 {
			where += " AND "
		}
		where += fmt.Sprintf(`loaders.id >= $%d AND loaders.id <= $%d`,
			valctr+1, valctr+2)
		vals = append(vals, ids.minLdrID, ids.maxLdrID)
		valctr += 2
	}
	query := fmt.Sprintf(`SELECT %s FROM loaders WHERE %s ORDER BY loadername;`, columns, where)
	stmt, err := db.c.Prepare(query)
	if err != nil {
		err = fmt.Errorf("Error while preparing search statement: '%v' in '%s'", err, query)
		return
	}
	if stmt != nil {
		defer stmt.Close()
	}
	rows, err = stmt.Query(vals...)
	if err != nil {
		err = fmt.Errorf("Error while finding loaders: '%v'", err)
	}
	if rows != nil {
		defer rows.Close()
	}
	for rows.Next() {
		var le mig.LoaderEntry
		var agtnameNull sql.NullString
		err = rows.Scan(&le.ID, &le.Name, &agtnameNull, &le.LastSeen, &le.Enabled)
		if err != nil {
			err = fmt.Errorf("Failed to retrieve loader data: '%v'", err)
			return
		}
		le.AgentName = "unset"
		if agtnameNull.Valid {
			le.AgentName = agtnameNull.String
		}
		lrecords = append(lrecords, le)
	}
	if err := rows.Err(); err != nil {
		err = fmt.Errorf("Failed to complete database query: '%v'", err)
	}
	return
}
开发者ID:saakaifoundry,项目名称:mig,代码行数:80,代码来源:searches.go


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