所以我想讓我的項目有這樣的項目集 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
- 1 回答
- 0 關注
- 170 瀏覽
添加回答
舉報
0/150
提交
取消