當前位置: 首頁>>代碼示例>>Golang>>正文


Golang common.MakeMultiError函數代碼示例

本文整理匯總了Golang中github.com/romana/core/common.MakeMultiError函數的典型用法代碼示例。如果您正苦於以下問題:Golang MakeMultiError函數的具體用法?Golang MakeMultiError怎麽用?Golang MakeMultiError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MakeMultiError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/romana/core/common.MakeMultiError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。