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


Golang logs.Error函数代码示例

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


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

示例1: Get

//curl localhost:9090/sshKeys/123456
func (this *SshKeysController) Get() {
	uid := this.Ctx.Input.Params[":objectId"]
	if uid == "" {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"param error"}`))
		this.StopRun()
	}

	dbconn, err := models.InitDbConn(0)
	if err != nil {
		logs.Error("db init error!", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"init db conn error"}`))
		this.StopRun()
	}
	defer dbconn.Close()

	sshKeysM := new(models.SshKeysManage)
	sshKeysOb, err := sshKeysM.GetAll(dbconn, uid, 0)
	if err != nil {
		logs.Error("sshkeysM getall error:", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"` + err.Error() + `"}`))
		this.StopRun()
	}
	this.Data["json"] = sshKeysOb
	this.ServeJson()
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:29,代码来源:sshKeysController.go

示例2: Get

func (this *SshProxyServerController) Get() {
	host := this.Ctx.Input.Params[":objectId"]
	if host == "" {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"param error"}`))
		this.StopRun()
	}

	dbconn, err := models.InitDbConn(0)
	if err != nil {
		logs.Error("init db conn error:", err, "logid:", 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"init db conn error"}`))
		this.StopRun()
	}
	defer dbconn.Close()

	sshProxyM := new(models.SshProxyManage)
	sshProxyOb, err := sshProxyM.Query(dbconn, host, 0)
	if err != nil {
		logs.Error("ssh proxy query error:", err, "logid:", 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"` + err.Error() + `"}`))
		this.StopRun()
	}
	logs.Normal("ssh post ok!", sshProxyOb, "logid:", 0)
	this.Data["json"] = sshProxyOb
	this.ServeJson()
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:29,代码来源:sshProxyServerController.go

示例3: Get

//curl -i -X GET 'localhost:9090/sshPort[/2200]'
func (this *SshPortController) Get() {
	portNum := this.Ctx.Input.Params[":objectId"]
	dbconn, err := models.InitDbConn(0)
	if err != nil {
		logs.Error("db init error:", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"init db conn error"}`))
		this.StopRun()
	}
	defer dbconn.Close()

	sshPortM := new(models.SshPortManage)
	//当没有传入具体的port值时,输出全部sshport对象
	if portNum == "" {
		sshPortObs, _ := sshPortM.QueryAll(dbconn, 0)
		this.Data["json"] = sshPortObs
		this.ServeJson()
		this.StopRun()
	}

	//输出portNum对应的sshPort信息
	sshPortOb, err := sshPortM.Query(dbconn, portNum, 0)
	if err != nil {
		logs.Error("ssh port query error:", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"` + err.Error() + `"}`))
		this.StopRun()
	}
	this.Data["json"] = sshPortOb
	this.ServeJson()
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:32,代码来源:sshPortController.go

示例4: GetByUid

//curl -i -X GET localhost:9090/sshRules/9999
func (this *SshRulesController) GetByUid() {
	uid := this.Ctx.Input.Params[":uid"]
	if uid == "" {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"param error"}`))
		this.StopRun()
	}

	dbconn, err := models.InitDbConn(0)
	if err != nil {
		logs.Error("init db conn error:", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"init db conn error"}`))
		this.StopRun()
	}
	defer dbconn.Close()

	sshRulesM := new(models.SshRuleManage)
	rulelist, err := sshRulesM.QueryByUid(dbconn, uid, 0)
	if err != nil {
		logs.Error("ssh rule query by uid error:", err, 0)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"` + err.Error() + `"}`))
		this.StopRun()
	}
	this.Data["json"] = rulelist
	this.ServeJson()
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:29,代码来源:sshRulesController.go

示例5: DeleteContainerUserFromProxy

func DeleteContainerUserFromProxy(rulelist []SshRule, logid int64) error {
	logs.Normal("delete container from proxy:", rulelist, "logid:", logid)
	token := beego.AppConfig.String("proxy_url_token")
	//userdel
	for _, sshRuleOb := range rulelist {
		container := sshRuleOb.ContainerName
		proxyHost := sshRuleOb.ProxyHost
		//this url todo
		proxyDelUrl := proxyHost + ":9090/deleteContainer?container=" + container + "&logid=" + strconv.FormatInt(logid, 10) + "&token=" + token
		logs.Normal("curl delete container url:", proxyDelUrl, "logid:", logid)

		req := httplib.Get(proxyDelUrl)
		output := make(map[string]interface{})
		err := req.ToJson(&output)
		if err != nil {
			logs.Error("request from "+proxyDelUrl+" error:", err, logid)
			return err
		}

		if output["result"].(int) == 0 {
			logs.Normal(proxyDelUrl, "response ok!", logid)
			continue
		} else {
			logs.Error(proxyDelUrl+" error:", output["error"], logid)
		}
	}
	return nil
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:28,代码来源:util.go

示例6: Put

//curl localhost:9090/sshKeys -X PUT -i -d '{"uid":5544,"keyname":"testliuyanglong","publickey":"d","logid":"444444"}'
func (this *SshKeysController) Put() {
	requestBody := string(this.Ctx.Input.CopyBody())
	var sshKeysOb models.SshKeys
	err := json.Unmarshal(this.Ctx.Input.CopyBody(), &sshKeysOb)
	if err != nil {
		//fmt.Println(err)
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"param error"}`))
		this.StopRun()
	}
	logid, err := models.GetLogId(this.Ctx.Input.CopyBody())
	if err != nil {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"logid param error"}`))
		this.StopRun()
	}
	logs.Normal("param is:", requestBody, "logid:", logid)
	dbconn, err := models.InitDbConn(logid)
	if err != nil {
		logs.Error("init db conn error:", err, "logid:", logid)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"init db conn error"}`))
		this.StopRun()
	}
	defer dbconn.Close()
	dbconn.Exec("START TRANSACTION")
	logs.Normal("start transaction", "logid:", logid)
	sshKeysM := new(models.SshKeysManage)
	err = sshKeysM.Update(dbconn, sshKeysOb, logid)
	if err != nil {
		dbconn.Exec("ROLLBACK")
		logs.Normal("ROLLBACK", "logid:", logid)
		logs.Error("ssh keys update error:", err, "logid:", logid)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"` + err.Error() + `"}`))
		this.StopRun()
	}

	//reload ssh public key
	err = this.reloadSshPublicKeys(dbconn, strconv.Itoa(sshKeysOb.Uid), logid)
	if err != nil {
		dbconn.Exec("ROLLBACK")
		logs.Normal("ROLLBACK", "logid:", logid)
		logs.Error("reload ssh public key error:", err, "logid:", logid)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":` + err.Error() + `}`))
		this.StopRun()
	}
	dbconn.Exec("COMMIT")
	logs.Normal("COMMIT", "logid:", logid)
	logs.Normal("ssh key put ok", "logid:", logid)
	this.Ctx.Output.Body([]byte(`{"result":0}`))
	this.StopRun()
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:55,代码来源:sshKeysController.go

示例7: DeleteByContainer

//curl -i -X GET localhost:9090/sshRules/9999/aiaiia
func (this *SshRulesController) DeleteByContainer() {
	uid := this.Ctx.Input.Params[":uid"]
	containerName := this.Ctx.Input.Params[":container"]
	if uid == "" {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"param error"}`))
		this.StopRun()
	}
	logid, _ := this.GetInt("logid")
	if logid == 0 {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"logid param error"}`))
		this.StopRun()
	}
	logs.Normal("delete param:", "uid:", uid, "containerName:", containerName, "logid:", logid)
	dbconn, err := models.InitDbConn(logid)
	if err != nil {
		logs.Error("init db conn err:", err, "logid:", logid)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"init db conn error"}`))
		this.StopRun()
	}
	defer dbconn.Close()

	dbconn.Exec("START TRANSACTION")
	logs.Normal("start transaction", "logid:", logid)

	sshRulesM := new(models.SshRuleManage)
	delrule, _ := sshRulesM.Query(dbconn, uid, containerName, logid)
	err = sshRulesM.Delete(dbconn, uid, containerName, logid)
	if err != nil {
		dbconn.Exec("ROLLBACK")
		logs.Normal("ROLLBACK", "logid:", logid)
		logs.Error("delete err:", err, "logid:", logid)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"` + err.Error() + `"}`))
		this.StopRun()
	}

	err = models.DeleteContainerUserFromProxy([]models.SshRule{delrule}, logid)
	if err != nil {
		logs.Error("Delete single Container From Proxy error:", err, "logid:", logid)
		dbconn.Exec("ROLLBACK")
		logs.Normal("ROLLBACK", logid)
	}

	dbconn.Exec("COMMIT")
	logs.Normal("COMMIT", "logid:", logid)

	logs.Normal("delete OK!", "logid:", logid)
	this.Ctx.Output.Body([]byte(`{"result":0}`))
	this.StopRun()
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:54,代码来源:sshRulesController.go

示例8: Post

//curl -i -X POST localhost:9090/sshRules/9999 -d '{"name":"aiaiia","port":4242,"rule":"~~~~","uid":9999}'
func (this *SshRulesController) Post() {
	var sshRulesOb models.SshRule
	requestBody := string(this.Ctx.Input.RequestBody)

	err := json.Unmarshal(this.Ctx.Input.RequestBody, &sshRulesOb)
	if err != nil {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"param error"}`))
		this.StopRun()
	}
	logid, err := models.GetLogId(this.Ctx.Input.RequestBody)
	if err != nil {
		this.Ctx.Output.SetStatus(403)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"logid param error"}`))
		this.StopRun()
	}
	logs.Normal("post data:", string(requestBody), "logid:", logid)
	dbconn, err := models.InitDbConn(logid)
	if err != nil {
		logs.Error("init db conn error:", err, "logid:", logid)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":"init db conn error"}`))
		this.StopRun()
	}
	defer dbconn.Close()

	dbconn.Exec("START TRANSACTION")
	logs.Normal("start transaction", "logid:", logid)

	sshRulesM := new(models.SshRuleManage)
	err = sshRulesM.Insert(dbconn, sshRulesOb, logid)
	if err != nil {
		dbconn.Exec("ROLLBACK")
		logs.Normal("ROLLBACK", "logid:", logid)
		logs.Error("ssh rules insert error:", err, "logid:", logid)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":` + err.Error() + `}`))
		this.StopRun()
	}

	if err = this.reloadRules(dbconn, sshRulesOb, logid); err != nil {
		dbconn.Exec("ROLLBACK")
		logs.Normal("ROLLBACK", "logid:", logid)
		logs.Error("reload rules error:", err, "logid:", logid)
		this.Ctx.Output.SetStatus(500)
		this.Ctx.Output.Body([]byte(`{"result":1,"error":` + err.Error() + `}`))
		this.StopRun()
	}
	dbconn.Exec("COMMIT")
	logs.Normal("COMMIT", "logid:", logid)
	logs.Normal("post OK!", "logid:", logid)
	this.Ctx.Output.Body([]byte(`{"result":0}`))
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:54,代码来源:sshRulesController.go

示例9: Insert

func (u *SshRuleManage) Insert(conn *sql.DB, sshRuleOb SshRule, logid int64) error {
	tableName := u.TableName()
	sqli := "INSERT INTO " + tableName + " (containerName,sshPort,proxyHost,uiIpPort,uid,addTime) VALUES (?,?,?,?,?,?)"
	logs.Normal("insert sql:", sqli, sshRuleOb, "logid:", logid)
	stmt, sterr := conn.Prepare(sqli)
	if sterr != nil {
		logs.Error("conn prepare error:", sterr, sqli, "logid:", logid)
		return sterr
	}
	if _, err := stmt.Exec(sshRuleOb.ContainerName, sshRuleOb.PublicPort, sshRuleOb.ProxyHost, sshRuleOb.UiIpPort, sshRuleOb.Uid, time.Now().Format("2006-01-02 15:04:05")); err != nil {
		logs.Error("sql exec error:", err, sqli, "logid:", logid)
		return err
	}
	return nil
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:15,代码来源:ssh_rules.go

示例10: Insert

func (u *SshKeysManage) Insert(conn *sql.DB, sshKeysOb SshKeys, logid int64) error {
	tableName := u.TableName()
	sqli := "INSERT INTO " + tableName + " (uid,keyName,publicKey,addTime) VALUES (?,?,?,?)"
	stmt, sterr := conn.Prepare(sqli)
	if sterr != nil {
		logs.Error("sql prepare error:", sterr, "logid:", logid)
		return sterr
	}
	if _, err := stmt.Exec(sshKeysOb.Uid, sshKeysOb.KeyName, sshKeysOb.PublicKey, time.Now().Format("2006-01-02 15:04:05")); err != nil {
		logs.Error("sql exec error:", sterr, " the sql is:", sqli, sshKeysOb, "logid:", logid)
		return err
	}
	logs.Normal("sql insert OK!", sqli, sshKeysOb, "logid:", logid)
	return nil
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:15,代码来源:ssh_keys.go

示例11: Insert

func (u *SshProxyManage) Insert(conn *sql.DB, sshProxyOb SshProxyMachine, logid int64) error {
	tableName := u.TableName()
	sqli := "INSERT INTO " + tableName + " (machineHost,userNumber,isAvail,addTime) VALUES (?,?,?,?)"
	logs.Normal("insert:", sqli, sshProxyOb, "logid:", logid)
	stmt, sterr := conn.Prepare(sqli)
	if sterr != nil {
		logs.Error("conn prepare error:", sterr, "logid:", logid)
		return sterr
	}
	if _, err := stmt.Exec(sshProxyOb.MachineHost, sshProxyOb.UserNumber, sshProxyOb.IsAvail, time.Now().Format("2006-01-02 15:04:05")); err != nil {
		logs.Error("stmt exec error:", err, "logid:", logid)
		return err
	}
	return nil
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:15,代码来源:ssh_proxy_machine.go

示例12: GetBestUsePort

func (this *SshPortController) GetBestUsePort(logid int64) (models.SshPort, error) {
	dbconn, err := models.InitDbConn(logid)
	if err != nil {
		logs.Error("init db conn err:", err, "logid:", logid)
		return models.SshPort{}, err
	}
	defer dbconn.Close()

	sshPortM := new(models.SshPortManage)
	portOb, err := sshPortM.GetBestUsePort(dbconn, logid)
	if err != nil {
		logs.Error("ssh port get best userport error:", err, "logid:", logid)
	}
	logs.Normal("get best use port ok!", portOb, "logid:", logid)
	return portOb, err
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:16,代码来源:sshPortController.go

示例13: Update

func (u *SshRuleManage) Update(conn *sql.DB, ruleOb SshRule, logid int64) error {
	tableName := u.TableName()
	if ruleOb.ContainerName == "" {
		return errors.New("ssh rule object is not good! miss primary key!")
	}
	param := make([]interface{}, 0)
	param = append(param, ruleOb.ContainerName)
	sqlu := "update " + tableName + " set containerName = '" + ruleOb.ContainerName + "'"
	if ruleOb.ProxyHost != "" {
		sqlu += " ,proxyHost='" + ruleOb.ProxyHost + "'"
		param = append(param, ruleOb.ProxyHost)
	}
	if ruleOb.PublicPort != 0 {
		portstr := strconv.Itoa(ruleOb.PublicPort)
		sqlu += " ,sshPort=" + portstr
		param = append(param, ruleOb.PublicPort)
	}
	if ruleOb.UiIpPort != "" {
		sqlu += " ,uiIpPort='" + ruleOb.UiIpPort + "'"
		param = append(param, ruleOb.UiIpPort)
	}

	uidstr := strconv.Itoa(ruleOb.Uid)
	sqlu += " where containerName = '" + ruleOb.ContainerName + "' and uid = " + uidstr
	logs.Normal("sql update:", sqlu, "logid:", logid)
	param = append(param, ruleOb.ContainerName)
	_, err := conn.Exec(sqlu)
	if err != nil {
		logs.Error("conn exec error:", err, "logid:", logid)
	}
	return err
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:32,代码来源:ssh_rules.go

示例14: reloadRules

func (this *SshRulesController) reloadRules(conn *sql.DB, sshRulesOb models.SshRule, logid int64) error {
	sshKeyOb := new(models.SshKeysManage)
	keylist, err := sshKeyOb.GetAll(conn, strconv.Itoa(sshRulesOb.Uid), logid)
	if err != nil {
		logs.Error("ssh key get all error:", err, "logid:", logid)
		return err
	}
	if len(keylist) <= 0 {
		return nil
	}
	err = models.UpdateRule([]models.SshRule{sshRulesOb}, keylist, logid)
	if err != nil {
		logs.Error("update rule error:", err, "rule list:", sshRulesOb, "key list:", keylist, "logid:", logid)
	}
	return err
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:16,代码来源:sshRulesController.go

示例15: UpdateNumber

func (this *SshPortController) UpdateNumber(port, num string, isplus bool, logid int64) error {
	dbconn, err := models.InitDbConn(logid)
	if err != nil {
		logs.Error("init db conn err:", err, "logid:", logid)
		return err
	}
	defer dbconn.Close()

	sshPortM := new(models.SshPortManage)
	err = sshPortM.Update(dbconn, port, num, isplus, logid)
	if err != nil {
		logs.Error("ssh port update error:", err, "logid:", logid)
		return err
	}
	logs.Normal("ssh updatenumber OK", logid)
	return nil
}
开发者ID:a4m,项目名称:bae_ssh_manage,代码行数:17,代码来源:sshPortController.go


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