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

Golang db.Conn函数代码示例

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

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



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

示例1: getProviderName

func getProviderName(host string) (*global.PredefClouds, error) {
	pdc := &global.PredefClouds{}

	conn, err := db.Conn(PREDEFCLOUDSBUCKET)

	if err != nil {
		return pdc, err
	}

	ferr := conn.FetchStruct(host, pdc)
	if ferr != nil {
		return pdc, ferr
	}

	sshkeyerr := downloadSshFiles(pdc, "key", 0600)
	if sshkeyerr != nil {
		return pdc, sshkeyerr
	}
	sshpuberr := downloadSshFiles(pdc, "pub", 0644)
	if sshpuberr != nil {
		return pdc, sshpuberr
	}

	return pdc, nil
}
开发者ID:LogeshEswar,项目名称:megamd,代码行数:25,代码来源:iaas.go


示例2: Checker

func (self *Server) Checker() {
	log.Info("verifying rabbitmq")
	factor, err := amqp.Factory()
	if err != nil {
		log.Error("Error: %v\nFailed to get the queue", err)
	}

	_, connerr := factor.Dial()
	if connerr != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n Please start rabbitmq service.\n", connerr)
		os.Exit(1)
	}
	log.Info("rabbitmq connected [ok]")

	log.Info("verifying riak")

	rconn, rerr := db.Conn("connection")
	if rerr != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", rerr)
		os.Exit(1)
	}

	data := "sampledata"
	ferr := rconn.StoreObject("sampleobject", data)
	if ferr != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", ferr)
		os.Exit(1)
	}
	defer rconn.Close()
	log.Info("riak connected [ok]")

}
开发者ID:LogeshEswar,项目名称:megamd,代码行数:32,代码来源:server.go


示例3: updateIndex

func updateIndex(ip string, pos uint) error {

	index := global.IPIndex{}
	res, err := index.Get(global.IPINDEXKEY)
	if err != nil {
		log.Error("Error: Riak didn't cooperate:\n%s.", err)
		return err
	}

	update := global.IPIndex{
		Ip:     ip,
		Subnet: res.Subnet,
		Index:  pos,
	}

	conn, connerr := db.Conn("ipindex")
	if connerr != nil {
		log.Error("Failed to riak connection : %s", connerr)
		return connerr
	}

	serr := conn.StoreStruct(global.IPINDEXKEY, &update)
	if serr != nil {
		log.Error("Failed to store the update index value : %s", serr)
		return serr
	}
	log.Info("Docker network index update was successfully.")
	return nil
}
开发者ID:LogeshEswar,项目名称:megamd,代码行数:29,代码来源:utils.go


示例4: getProviderName

func getProviderName(host string) (*global.PredefClouds, error) {
	pdc := &global.PredefClouds{}

	predefBucket, perr := config.GetString("riak:predefclouds")
	if perr != nil {
		return pdc, perr
	}
	conn, err := db.Conn(predefBucket)

	if err != nil {
		return pdc, err
	}

	ferr := conn.FetchStruct(host, pdc)
	if ferr != nil {
		return pdc, ferr
	}

	sshkeyerr := downloadSshFiles(pdc, "key", 0600)
	if sshkeyerr != nil {
		return pdc, sshkeyerr
	}
	sshpuberr := downloadSshFiles(pdc, "pub", 0644)
	if sshpuberr != nil {
		return pdc, sshpuberr
	}

	return pdc, nil
}
开发者ID:WH-Wang,项目名称:megamd,代码行数:29,代码来源:iaas.go


示例5: updatecomponent

/*
*
* UpdateComponent updates the ipaddress that is bound to the container
* It talks to riakdb and updates the respective component(s)
 */
func updatecomponent(assembly *global.AssemblyWithComponents, ipaddress string, id string, port string) {
	log.Debug("Update process for component with ip and container id")
	mySlice := make([]*global.KeyValuePair, 3)
	mySlice[0] = &global.KeyValuePair{Key: "ip", Value: ipaddress}
	mySlice[1] = &global.KeyValuePair{Key: "id", Value: id}
	mySlice[2] = &global.KeyValuePair{Key: "port", Value: port}

	update := global.Component{
		Id:                assembly.Components[0].Id,
		Name:              assembly.Components[0].Name,
		ToscaType:         assembly.Components[0].ToscaType,
		Inputs:            assembly.Components[0].Inputs,
		Outputs:           mySlice,
		Artifacts:         assembly.Components[0].Artifacts,
		RelatedComponents: assembly.Components[0].RelatedComponents,
		Operations:        assembly.Components[0].Operations,
		Status:            assembly.Components[0].Status,
		CreatedAt:         assembly.Components[0].CreatedAt,
	}

	conn, connerr := db.Conn("components")
	if connerr != nil {
		log.Error("Failed to riak connection : %s", connerr)
	}

	err := conn.StoreStruct(assembly.Components[0].Id, &update)
	if err != nil {
		log.Error("Failed to store the update component data : %s", err)
	}
	log.Info("Container component update was successfully.")
}
开发者ID:WH-Wang,项目名称:megamd,代码行数:36,代码来源:provisioner.go


示例6: GetAssemblyWithComponents

func (asm *Assembly) GetAssemblyWithComponents(asmId string) (*AssemblyWithComponents, error) {
	log.Info("Get Assembly message %v", asmId)
	var j = -1
	asmresult := &AssemblyWithComponents{}
	conn, err := db.Conn("assembly")
	if err != nil {
		return asmresult, err
	}
	//appout := &Requests{}
	ferr := conn.FetchStruct(asmId, asm)
	if ferr != nil {
		return asmresult, ferr
	}
	var arraycomponent = make([]*Component, len(asm.Components))
	for i := range asm.Components {
		t := strings.TrimSpace(asm.Components[i])
		if len(t) > 1 {
			componentID := asm.Components[i]
			component := Component{Id: componentID}
			com, err := component.Get(componentID)
			if err != nil {
				log.Error("Error: Riak didn't cooperate:\n%s.", err)
				return asmresult, err
			}
			j++
			arraycomponent[j] = com
		}
	}
	result := &AssemblyWithComponents{Id: asm.Id, Name: asm.Name, ToscaType: asm.ToscaType, Components: arraycomponent, Requirements: asm.Requirements, Policies: asm.Policies, Inputs: asm.Inputs, Outputs: asm.Outputs, Operations: asm.Operations, Status: asm.Status, CreatedAt: asm.CreatedAt}
	defer conn.Close()
	return result, nil
}
开发者ID:LogeshEswar,项目名称:megamd,代码行数:32,代码来源:global.go


示例7: downloadSshFiles

func downloadSshFiles(pdc *global.PredefClouds, keyvalue string, permission os.FileMode) error {
	sa := make([]string, 2)
	sa = strings.Split(pdc.Access.IdentityFile, "_")
	email, name := sa[0], sa[1]
	ssh := &db.SshObject{}
	sshBucket, serr := config.GetString("riak:ssh_files")
	if serr != nil {
		return serr
	}
	conn, err := db.Conn(sshBucket)
	if err != nil {
		return err
	}

	ferr := conn.FetchObject(pdc.Access.IdentityFile+"_"+keyvalue, ssh)
	if ferr != nil {
		return ferr
	}
	cloudkeysBucket, ckberr := config.GetString("riak:cloud_keys")
	if ckberr != nil {
		return ckberr
	}

	megam_home, ckberr := config.GetString("megam_home")
	if ckberr != nil {
		return ckberr
	}

	basePath := megam_home + cloudkeysBucket
	dir := path.Join(basePath, email)
	filePath := path.Join(dir, name+"."+keyvalue)
	if _, err := os.Stat(dir); os.IsNotExist(err) {
		fmt.Printf("no such file or directory: %s", dir)

		if errm := os.MkdirAll(dir, 0777); errm != nil {
			return errm
		}
		// open output file
		_, err := os.Create(filePath)
		if err != nil {
			return err
		}
	}
	errf := ioutil.WriteFile(filePath, []byte(ssh.Data), permission)
	if errf != nil {
		return errf
	}
	return nil
}
开发者ID:WH-Wang,项目名称:megamd,代码行数:49,代码来源:iaas.go


示例8: Get

/**
**fetch the ip index data from riak and parse the json to struct
**/
func (req *IPIndex) Get(key string) (*IPIndex, error) {
	log.Info("Get IPIndex value %v", key)
	conn, err := db.Conn("ipindex")
	if err != nil {
		return req, err
	}
	ferr := conn.FetchStruct(key, req)
	if ferr != nil {
		return req, ferr
	}
	defer conn.Close()

	return req, nil

}
开发者ID:LogeshEswar,项目名称:megamd,代码行数:18,代码来源:global.go


示例9: GetAccessKeys

func GetAccessKeys(pdc *global.PredefClouds) (*AccessKeys, error) {
	keys := &AccessKeys{}

	conn, err := db.Conn(CLOUDACCESSKEYSBUCKET)
	if err != nil {
		return keys, err
	}

	ferr := conn.FetchStruct(pdc.Access.VaultLocation, keys)
	if ferr != nil {
		return keys, ferr
	}

	return keys, nil
}
开发者ID:LogeshEswar,项目名称:megamd,代码行数:15,代码来源:iaas.go


示例10: GetPredefClouds

func GetPredefClouds(host string) (*global.PredefClouds, error) {
	pdc := &global.PredefClouds{}

	conn, err := db.Conn(PREDEFCLOUDSBUCKET)

	if err != nil {
		return pdc, err
	}

	ferr := conn.FetchStruct(host, pdc)
	if ferr != nil {
		return pdc, ferr
	}
	return pdc, nil
}
开发者ID:LogeshEswar,项目名称:megamd,代码行数:15,代码来源:assembly.go


示例11: GetAccessKeys

func GetAccessKeys(pdc *global.PredefClouds) (*AccessKeys, error) {
	keys := &AccessKeys{}
	cakbBucket, cakberr := config.GetString("riak:cloud_access_keys")
	if cakberr != nil {
		return keys, cakberr
	}

	conn, err := db.Conn(cakbBucket)
	if err != nil {
		return keys, err
	}

	ferr := conn.FetchStruct(pdc.Access.VaultLocation, keys)
	if ferr != nil {
		return keys, ferr
	}

	return keys, nil
}
开发者ID:WH-Wang,项目名称:megamd,代码行数:19,代码来源:iaas.go


示例12: GetPredefClouds

func GetPredefClouds(host string) (*global.PredefClouds, error) {
	pdc := &global.PredefClouds{}

	predefBucket, perr := config.GetString("riak:predefclouds")
	if perr != nil {
		return pdc, perr
	}
	conn, err := db.Conn(predefBucket)

	if err != nil {
		return pdc, err
	}

	ferr := conn.FetchStruct(host, pdc)
	if ferr != nil {
		return pdc, ferr
	}
	return pdc, nil
}
开发者ID:WH-Wang,项目名称:megamd,代码行数:19,代码来源:assembly.go


示例13: IPInit

func (self *Server) IPInit() {

	rconn, rerr := db.Conn("ipindex")
	if rerr != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", rerr)
		os.Exit(1)
	}

	index := global.IPIndex{}
	subnet, _ := config.GetString("swarm:subnet")
	_, err := index.Get(global.IPINDEXKEY)
	if err != nil {
		data := &global.IPIndex{Ip: subnet, Subnet: subnet, Index: 1}
		res2B, _ := json.Marshal(data)
		ferr := rconn.StoreObject(global.IPINDEXKEY, string(res2B))
		if ferr != nil {
			fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", ferr)
			os.Exit(1)
		}
	}

	defer rconn.Close()
}
开发者ID:LogeshEswar,项目名称:megamd,代码行数:23,代码来源:server.go


示例14:

}

var updateStatus = action.Action{
	Name: "updatestatus",
	Forward: func(ctx action.FWContext) (action.Result, error) {
		var app global.AssemblyWithComponents
		switch ctx.Params[0].(type) {
		case global.AssemblyWithComponents:
			app = ctx.Params[0].(global.AssemblyWithComponents)
		case *global.AssemblyWithComponents:
			app = *ctx.Params[0].(*global.AssemblyWithComponents)
		default:
			return nil, errors.New("First parameter must be App or *global.AssemblyWithComponents.")
		}
		asm := &global.Assembly{}
		conn, err := db.Conn("assembly")
		if err != nil {
			return nil, err
		}

		ferr := conn.FetchStruct(app.Id, asm)
		if ferr != nil {
			return nil, ferr
		}

		update := global.Assembly{
			Id:           asm.Id,
			JsonClaz:     asm.JsonClaz,
			Name:         asm.Name,
			Components:   asm.Components,
			ToscaType:    asm.ToscaType,
开发者ID:WH-Wang,项目名称:megamd,代码行数:31,代码来源:actions.go


示例15: uploadENVVariables

func uploadENVVariables(asm *global.AssemblyWithComponents, com *global.Component) error {
	megam_home, ckberr := config.GetString("megam_home")
	if ckberr != nil {
		return ckberr
	}

	conn, err := db.Conn("assemblies")
	if err != nil {
		return err
	}

	act_id, actberr := config.GetString("account_id")
	if actberr != nil {
		return actberr
	}

	arr, ferr := conn.FetchObjectByIndex("assemblies", ASSEMBLIESINDEX, act_id, "", "")
	if ferr != nil {
		return ferr
	}

	for i := range arr {
		s := global.BytesToString(arr[i])
		rassemblies := &global.Assemblies{}
		rams, ramserr := rassemblies.Get(s)
		if ramserr != nil {
			return ramserr
		}
		for l := range rams.Assemblies {
			if len(rams.Assemblies[l]) > 0 {
				assembly := global.Assembly{Id: rams.Assemblies[l]}
				rasm, rasmerr := assembly.GetAssemblyWithComponents(rams.Assemblies[l])
				if rasmerr != nil {
					log.Error("Error: Riak didn't cooperate:\n%s.", rasmerr)
					return rasmerr
				}

				for j := range com.RelatedComponents {
					if len(com.RelatedComponents[j]) > 0 {
						rasmname := strings.Split(com.RelatedComponents[j], "/")
						assemblyname := strings.Split(rasmname[0], ".")[0]
						if rasm.Name == assemblyname {
							for rc := range rasm.Components {
								if rasm.Components[rc] != nil {
									if rasmname[1] == rasm.Components[rc].Name {
										basePath := megam_home
										dir := path.Join(basePath, com.Name)
										filePath := path.Join(dir, "env.sh")
										if _, err := os.Stat(dir); os.IsNotExist(err) {
											fmt.Printf("no such file or directory: %s", dir)

											if errm := os.MkdirAll(dir, 0777); errm != nil {
												return errm
											}
											// open output file
											_, err := os.Create(filePath)
											if err != nil {
												return err
											}
										}

										str := "BINDED_HOST_NAME=" + rasm.Components[rc].Name + "\n" + "HOST=" + rasm.Name + "." + GetParsedValue(rasm.Inputs, "domain") + "\n" + "\nDBNAME=" + com.Name + "\n" + "PORT=" + GetParsedValue(rasm.Components[rc].Inputs, "port") + "\nUSERNAME=" + GetParsedValue(rasm.Components[rc].Inputs, "username") + "\nPASSWORD=" + GetParsedValue(rasm.Components[rc].Inputs, "password") + "\nDBUSER=" + GetParsedValue(rasm.Components[rc].Inputs, "username") + "\nDBPASSWORD=" + GetParsedValue(rasm.Components[rc].Inputs, "dbpassword") + "\n"
										errf := ioutil.WriteFile(filePath, []byte(str), 0644)
										if errf != nil {
											return errf
										}
										//return nil
									}
								}
							}
						}
					}
				}
			}
		}
	}

	return nil
}
开发者ID:rajthilakmca,项目名称:megamgulp,代码行数:79,代码来源:policy.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Go 语言教程发布时间:2022-01-22
下一篇:
Golang cmd.Colorfy函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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