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

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

從 golang 中的參數調用 const

從 golang 中的參數調用 const

Go
白衣染霜花 2023-04-24 17:00:18
所以我想讓我的項目有這樣的項目集 GoTraining   -Controllers       ListController   -Service       ListService that doing business process and       calling data Access Object (DAO) to get data   -DAO       List query and Model(Const)   -.gitignore   -config.conf   -main.go   -readme.md那只是我的結構的圖片,現在我感到困惑的地方我在 dao 中創建了一個名為 customerDao.go 的包,并將我的所有查詢寫在 const 中,我嘗試創建一個名為 queryFilter 的函數,并將 queryType 作為參數,我想要出于某種原因,根據我作為參數獲得的 queryType 搜索 const,它給我一條錯誤消息說“語法錯誤:意外的常量,期待表達式 (8,16)”誰能告訴我我在這里做錯了什么?
查看完整描述

1 回答

?
吃雞游戲

TA貢獻1829條經驗 獲得超7個贊

您似乎在假設queryGetAllCustomer“屬于” const。Const 不是一個作用域,而只是一個訪問修飾符,這兩個片段產生相同的結果:


const (

    queryGetAllCustomer = "..."

    queryGetOneCustomer = "..."

)


// and...


const queryGetAllCustomer = "..."

const queryGetOneCustomer = "..."

因此,您可以簡單地引用該值queryGetAllCustomer(或dao.QueryGetAllCustomer從另一個包,如果它被導出):


queryText := queryGetAllCustomer


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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