• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang common.MakeMultiError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/romana/core/common.MakeMultiError函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeMultiError函数的具体用法?Golang MakeMultiError怎么用?Golang MakeMultiError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: addSegment

func (mysqlStore *mysqlStore) addSegment(tenantId uint64, segment *Segment) error {
	var err error

	// TODO better way of getting sequence
	var segments []Segment
	mysqlStore.db.Where("tenant_id = ?", tenantId).Find(&segments)
	segment.Seq = uint64(len(segments) + 1)
	mysqlStore.db.NewRecord(*segment)
	segment.TenantId = tenantId
	mysqlStore.db.Create(segment)
	//	myId := segment.Id

	//	var segmentSeq uint64
	//
	//	for i := range segments {
	//		if segments[i].Id == myId {
	//			segmentSeq = uint64(i)
	//			segments[i].Seq = segmentSeq
	//			log.Printf("Sequence for segment %s is %d\n", segments[i].Name, segmentSeq)
	//			mysqlStore.db.Save(segment)
	//			break
	//		}
	//	}

	err = common.MakeMultiError(mysqlStore.db.GetErrors())
	if err != nil {
		return err
	}
	return nil
}
开发者ID:yangzhares,项目名称:core,代码行数:30,代码来源:mysql.go


示例2: addTenant

func (mysqlStore *mysqlStore) addTenant(tenant *Tenant) error {
	var tenants []Tenant
	mysqlStore.db.Find(&tenants)

	//	myId := tenant.Id
	tenant.Seq = uint64(len(tenants) + 1)
	mysqlStore.db.Create(tenant)
	mysqlStore.db.NewRecord(*tenant)

	// TODO better way of getting sequence
	//
	//	var tenantSeq uint64
	//	for i := range tenants {
	//		if tenants[i].Id == myId {
	//			tenantSeq = uint64(i)
	//			tenant.Seq = tenantSeq
	//			mysqlStore.db.Save(tenant)
	//			log.Printf("Sequence for tenant %s is %d\n", tenants[i].Name, tenantSeq)
	//			break
	//		}
	//	}

	err := common.MakeMultiError(mysqlStore.db.GetErrors())
	if err != nil {
		return err
	}
	return nil
}
开发者ID:yangzhares,项目名称:core,代码行数:28,代码来源:mysql.go


示例3: addIPtablesRuleUnsafe

// addIPtablesRuleUnsafe is a non thread safe implementation of addIPtablesRule.
// Unsafe implementation is needed for functions which are already managing same mutex.
func (firewallStore *firewallStore) addIPtablesRuleUnsafe(rule *IPtablesRule) error {

	db := firewallStore.DbStore.Db
	// db := firewallStore.GetDb()
	log.Info("In addIPtablesRule() after GetDb")
	if db == nil {
		panic("In addIPtablesRule(), db is nil")
	}

	firewallStore.DbStore.Db.Create(rule)
	log.Info("In addIPtablesRule() after Db.Create")
	if db.Error != nil {
		return db.Error
	}
	firewallStore.DbStore.Db.NewRecord(*rule)
	err := common.MakeMultiError(db.GetErrors())
	if err != nil {
		return err
	}
	if db.Error != nil {
		return db.Error
	}
	return nil

}
开发者ID:romana,项目名称:core,代码行数:27,代码来源:store.go


示例4: createSchema

func (mysqlStore *mysqlStore) createSchema(force bool) error {
	log.Println("in createSchema(", force, ")")
	// Connect to mysql database
	schemaName := mysqlStore.info.Database
	mysqlStore.info.Database = "mysql"
	mysqlStore.setConnString()
	err := mysqlStore.connect()

	if err != nil {
		return err
	}
	var sql string
	if force {
		sql = fmt.Sprintf("DROP DATABASE IF EXISTS %s", schemaName)
		res, err := mysqlStore.db.DB().Exec(sql)
		if err != nil {
			return err
		}

		rows, _ := res.RowsAffected()
		log.Println(sql, ": ", rows)
	}

	sql = fmt.Sprintf("CREATE DATABASE %s", schemaName)
	res, err := mysqlStore.db.DB().Exec(sql)
	if err != nil {
		return err
	}
	rows, _ := res.RowsAffected()
	log.Println(sql, ": ", rows)
	mysqlStore.info.Database = schemaName
	mysqlStore.setConnString()
	err = mysqlStore.connect()
	if err != nil {
		return err
	}
	log.Println("Creating vms table.")
	ipamVm := IpamVm{}
	mysqlStore.db.CreateTable(&ipamVm)
	// Sequence numbers are unique for VMs per host / tenant combination
	mysqlStore.db.Model(&IpamVm{}).AddUniqueIndex("idx_segment_host_seq", "segment_id", "host_id", "seq")

	//	log.Println("Creating hosts table.")
	//	mysqlStore.db.CreateTable(&IpamHost{})
	//
	//	log.Println("Creating segments table.")
	//	mysqlStore.db.CreateTable(&IpamHost{})

	errs := mysqlStore.db.GetErrors()
	log.Println("Errors", errs)
	err2 := common.MakeMultiError(errs)

	if err2 != nil {
		return err2
	}
	return nil

}
开发者ID:yangzhares,项目名称:core,代码行数:58,代码来源:mysql.go


示例5: findHost

func (mysqlStore *mysqlStore) findHost(id uint64) (Host, error) {
	host := Host{}
	mysqlStore.db.Where("id = ?", id).First(&host)
	err := common.MakeMultiError(mysqlStore.db.GetErrors())
	if err != nil {
		return host, err
	}
	return host, nil
}
开发者ID:yangzhares,项目名称:core,代码行数:9,代码来源:mysql.go


示例6: addHost

func (mysqlStore *mysqlStore) addHost(host *Host) (string, error) {
	mysqlStore.db.NewRecord(*host)
	mysqlStore.db.Create(host)
	err := common.MakeMultiError(mysqlStore.db.GetErrors())
	if err != nil {
		return "", err
	}
	return strconv.FormatUint(host.Id, 10), nil
}
开发者ID:yangzhares,项目名称:core,代码行数:9,代码来源:mysql.go


示例7: CreateSchemaPostProcess

// CreateSchemaPostProcess implements CreateSchemaPostProcess method of
// Service interface.
func (rootStore *rootStore) CreateSchemaPostProcess() error {
	passwd, err := rootStore.GetPasswordFunction()
	if err != nil {
		return err
	}
	sql := fmt.Sprintf("INSERT INTO users (username, password) VALUES (?, %s)", passwd)
	rootStore.DbStore.Db.Exec(sql, "admin", "password")
	rootStore.DbStore.Db.Exec("INSERT INTO roles (name) VALUES (admin)")
	//	rootStore.DbStore.Db.Exec("INSERT INTO roles (name) VALUES (admin)")
	return common.MakeMultiError(rootStore.DbStore.Db.GetErrors())
}
开发者ID:romana,项目名称:core,代码行数:13,代码来源:store.go


示例8: listSegments

func (mysqlStore *mysqlStore) listSegments(tenantId uint64) ([]Segment, error) {
	var segments []Segment
	log.Println("In listTenants()", &segments)
	mysqlStore.db.Where("tenant_id = ?", tenantId).Find(&segments)
	err := common.MakeMultiError(mysqlStore.db.GetErrors())
	if err != nil {
		return nil, err
	}
	log.Println(segments)
	return segments, nil
}
开发者ID:yangzhares,项目名称:core,代码行数:11,代码来源:mysql.go


示例9: listHosts

func (mysqlStore *mysqlStore) listHosts() ([]Host, error) {
	var hosts []Host
	log.Println("In listHosts()")
	mysqlStore.db.Find(&hosts)
	err := common.MakeMultiError(mysqlStore.db.GetErrors())
	if err != nil {
		return nil, err
	}
	log.Println("MySQL found hosts:", hosts)
	return hosts, nil
}
开发者ID:yangzhares,项目名称:core,代码行数:11,代码来源:mysql.go


示例10: listTenants

func (tenantStore *tenantStore) listTenants() ([]Tenant, error) {
	var tenants []Tenant
	log.Println("In listTenants()", &tenants)
	tenantStore.DbStore.Db.Find(&tenants)
	err := common.MakeMultiError(tenantStore.DbStore.Db.GetErrors())
	if err != nil {
		return nil, err
	}
	log.Println(tenants)
	return tenants, nil
}
开发者ID:romana,项目名称:core,代码行数:11,代码来源:store.go


示例11: listSegments

// listSegments returns a list of segments for a specific tenant
// whose tenantId is specified.
func (tenantStore *tenantStore) listSegments(tenantId string) ([]Segment, error) {
	var segments []Segment
	db := tenantStore.DbStore.Db.Joins("JOIN tenants ON segments.tenant_id = tenants.id").
		Where("tenants.id = ? OR tenants.external_id = ?", tenantId, tenantId).
		Find(&segments)
	err := common.MakeMultiError(db.GetErrors())
	log.Printf("In listSegments(): %v, %v", segments, err)
	if err != nil {
		return nil, err
	}
	if db.Error != nil {
		return nil, db.Error
	}
	return segments, nil
}
开发者ID:romana,项目名称:core,代码行数:17,代码来源:store.go


示例12: listIPtablesRules

// listIPtablesRules returns a list of all firewall rules in a database.
func (firewallStore *firewallStore) listIPtablesRules() ([]IPtablesRule, error) {
	log.Info("Acquiring store mutex for listIPtablesRules")
	firewallStore.mu.Lock()
	defer func() {
		log.Info("Releasing store mutex for listIPtablesRules")
		firewallStore.mu.Unlock()
	}()
	log.Info("Acquired store mutex for listIPtablesRules")

	var iPtablesRule []IPtablesRule
	firewallStore.DbStore.Db.Find(&iPtablesRule)
	err := common.MakeMultiError(firewallStore.DbStore.Db.GetErrors())
	if err != nil {
		return nil, err
	}
	return iPtablesRule, nil
}
开发者ID:romana,项目名称:core,代码行数:18,代码来源:store.go


示例13: listRoutes

func (agentStore *agentStore) listRoutes() ([]Route, error) {
	log.Trace(trace.Inside, "Acquiring store mutex for listRoutes")
	agentStore.mu.Lock()
	defer func() {
		log.Trace(trace.Inside, "Releasing store mutex for listRoutes")
		agentStore.mu.Unlock()
	}()
	log.Trace(trace.Inside, "Acquired store mutex for listRoutes")

	var routes []Route
	agentStore.DbStore.Db.Find(&routes)
	err := common.MakeMultiError(agentStore.DbStore.Db.GetErrors())
	if err != nil {
		return nil, err
	}
	return routes, nil
}
开发者ID:romana,项目名称:core,代码行数:17,代码来源:store.go


示例14: deleteIPtablesRule

// deleteIPtablesRule deletes firewall rules from database.
func (firewallStore *firewallStore) deleteIPtablesRule(rule *IPtablesRule) error {
	log.Info("Acquiring store mutex for deleteIPtablesRule")
	firewallStore.mu.Lock()
	defer func() {
		log.Info("Releasing store mutex for deleteIPtablesRule")
		firewallStore.mu.Unlock()
	}()
	log.Info("Acquired store mutex for deleteIPtablesRule")

	db := firewallStore.DbStore.Db
	firewallStore.DbStore.Db.Delete(rule)
	err := common.MakeMultiError(db.GetErrors())
	if err != nil {
		return err
	}
	if db.Error != nil {
		return db.Error
	}

	return nil
}
开发者ID:romana,项目名称:core,代码行数:22,代码来源:store.go


示例15: findRouteByIface

func (agentStore *agentStore) findRouteByIface(routeIface string) (*Route, error) {
	log.Trace(trace.Inside, "Acquiring store mutex for findRoute")
	agentStore.mu.Lock()
	defer func() {
		log.Trace(trace.Inside, "Releasing store mutex for findRoute")
		agentStore.mu.Unlock()
	}()
	log.Trace(trace.Inside, "Acquired store mutex for findRoute")

	var route Route
	db := agentStore.DbStore.Db
	agentStore.DbStore.Db.Where("ip = ?", routeIface).First(&route)
	err := common.MakeMultiError(db.GetErrors())
	if err != nil {
		return nil, err
	}
	if db.Error != nil {
		return nil, db.Error
	}
	return &route, nil
}
开发者ID:romana,项目名称:core,代码行数:21,代码来源:store.go


示例16: deleteRoute

func (agentStore *agentStore) deleteRoute(route *Route) error {
	log.Trace(trace.Inside, "Acquiring store mutex for deleteRoute")
	agentStore.mu.Lock()
	defer func() {
		log.Trace(trace.Inside, "Releasing store mutex for deleteRoute")
		agentStore.mu.Unlock()
	}()
	log.Trace(trace.Inside, "Acquired store mutex for deleteRoute")

	db := agentStore.DbStore.Db
	agentStore.DbStore.Db.Delete(route)
	err := common.MakeMultiError(db.GetErrors())
	if err != nil {
		return err
	}
	if db.Error != nil {
		return db.Error
	}

	return nil
}
开发者ID:romana,项目名称:core,代码行数:21,代码来源:store.go


示例17: switchIPtablesRule

// switchIPtablesRule changes IPtablesRule state.
func (firewallStore *firewallStore) switchIPtablesRule(rule *IPtablesRule, op opSwitchIPtables) error {

	// Fast track return if nothing to be done
	if rule.State == op.String() {
		log.Infof("switchIPtablesRule nothing to be done for %s", rule.State)
		return nil
	}

	log.Info("Acquiring store mutex for switchIPtablesRule")
	firewallStore.mu.Lock()
	defer func() {
		log.Info("Releasing store mutex for switchIPtablesRule")
		firewallStore.mu.Unlock()
	}()
	log.Info("Acquired store mutex for switchIPtablesRule")

	// if toggle requested then reverse current state
	if op == toggleRule {
		if rule.State == setRuleInactive.String() {
			rule.State = setRuleActive.String()
		} else {
			rule.State = setRuleInactive.String()
		}
		// otherwise just assign op value
	} else {
		rule.State = op.String()
	}

	db := firewallStore.DbStore.Db
	firewallStore.DbStore.Db.Save(rule)
	err := common.MakeMultiError(db.GetErrors())
	if err != nil {
		return err
	}
	if db.Error != nil {
		return db.Error
	}

	return nil
}
开发者ID:romana,项目名称:core,代码行数:41,代码来源:store.go


示例18: findTenant

func (mysqlStore *mysqlStore) findTenant(id uint64) (Tenant, error) {
	var tenants []Tenant
	log.Println("In findTenant()")
	mysqlStore.db.Find(&tenants)
	err := common.MakeMultiError(mysqlStore.db.GetErrors())
	if err != nil {
		return Tenant{}, err
	}
	for i := range tenants {
		if tenants[i].Id == id {
			return tenants[i], nil
		}
	}
	return Tenant{}, errors.New("Not found")
	//	tenant := Tenant{}
	//	mysqlStore.db.Where("id = ?", id).First(&tenant)
	//	err := common.MakeMultiError(mysqlStore.db.GetErrors())
	//	if err != nil {
	//		return tenant, err
	//	}
	//	return tenant, nil
}
开发者ID:yangzhares,项目名称:core,代码行数:22,代码来源:mysql.go


示例19: findIPtablesRules

func (firewallStore *firewallStore) findIPtablesRules(subString string) (*[]IPtablesRule, error) {
	log.Info("Acquiring store mutex for findIPtablesRule")
	firewallStore.mu.Lock()
	defer func() {
		log.Info("Releasing store mutex for findIPtablesRule")
		firewallStore.mu.Unlock()
	}()
	log.Info("Acquired store mutex for findIPtablesRule")

	var rules []IPtablesRule
	db := firewallStore.DbStore.Db
	searchString := "%" + subString + "%"
	firewallStore.DbStore.Db.Where("body LIKE ?", searchString).Find(&rules)
	err := common.MakeMultiError(db.GetErrors())
	if err != nil {
		return nil, err
	}
	if db.Error != nil {
		return nil, db.Error
	}
	return &rules, nil
}
开发者ID:romana,项目名称:core,代码行数:22,代码来源:store.go


示例20: findSegment

func (mysqlStore *mysqlStore) findSegment(tenantId uint64, id uint64) (Segment, error) {
	var segments []Segment
	log.Println("In listSegments()")
	mysqlStore.db.Where("tenant_id = ?", tenantId).Find(&segments)
	err := common.MakeMultiError(mysqlStore.db.GetErrors())
	if err != nil {
		return Segment{}, err
	}
	for i := range segments {
		if segments[i].Id == id {
			return segments[i], nil
		}
	}
	return Segment{}, errors.New("Not found")
	//	segment := Segment{}
	//	mysqlStore.db.Where("tenant_id = ? AND id = ?", tenantId, id).First(&segment)
	//	err := common.MakeMultiError(mysqlStore.db.GetErrors())
	//	if err != nil {
	//		return segment, err
	//	}
	//	return segment, nil
}
开发者ID:yangzhares,项目名称:core,代码行数:22,代码来源:mysql.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang rlog.Infof函数代码示例发布时间:2022-05-28
下一篇:
Golang cli.App类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap