亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在go中調用另一個函數?

如何在go中調用另一個函數?

Go
阿晨1998 2023-06-05 13:26:15
我想從 Insert 函數調用 GetUsers,但我不知道。func GetUsers(c echo.Context) error{  result := models.GetUsers()  return c.Render(http.StatusOK, "users.html", result)}func Insert(c echo.Context) error{  models.Insert()  return c.GetUsers()}
查看完整描述

1 回答

?
四季花海

TA貢獻1811條經驗 獲得超5個贊

Insert您可以通過簡單地使用來調用它GetUsers。


func Insert(c echo.Context) error{

    models.Insert()

    return GetUsers(c)

}

您使用的語法c.GetUsers()需要GetUsers是一個聲明為其Context接收者類型的方法——在echo包中——如下所示:


// package echo

func (c Context) GetUsers() error {

    …

}


// package other

func Insert(c echo.Context) error{

    models.Insert()

    return c.GetUsers()

}

但我假設這不是你想要的,因為Context慣用的不應該包含用戶。


查看完整回答
反對 回復 2023-06-05
  • 1 回答
  • 0 關注
  • 157 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號