我正在嘗試從 Golang 的地圖中洗掉一個專案。
這是代碼的粗略概念:
import (
"github.com/aws/aws-sdk-go/aws/session"
)
var sessions map[string]*session.Session
type config struct {
...
endPoint string
...
}
func newConfig() config {
var Config config = config{endPoint: "myEndpoint"}
return Config
}
func createSession(Config *config) error {
...
sessions = make(map[string]*session.Session)
...
session, err := session.NewSession( <session info here> )
sessions[Config.endPoint] = session
...
}
func main() {
Config := newConfig()
err := createSession()
...
if <some condition where i want to delete the session> {
delete(sessions, Config.endPoint)
}
}
但是我收到這個編譯錯誤:
# ./build_my_program.sh
./myprogram.go:9998:12: cannot use sessions (type map[string]*session.Session) as type *config in argument to delete
./myprogram.go:9999:29: cannot use Config.endPoint (type string) as type *session.Session in argument to delete
我不明白這里的問題。
唯一讓我懷疑的是在地圖中使用指標作為型別。假設我需要保留指標型別,關于如何解決的任何想法?
uj5u.com熱心網友回復:
內置delete函式func delete(*config, *session.Session) {}在包中被隱藏。重命名包中的函式。
uj5u.com熱心網友回復:
你在哪里宣告了一個deletefunc ?
package main
func delete(a, b string) {
}
func main() {
m := map[int]int{}
m[1] = 1
delete(m, 1)
}
./del.go:9:8: cannot use m (type map[int]int) as type string in argument to delete
./del.go:9:12: cannot use 1 (type untyped int) as type string in argument to delete
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/334903.html
標籤:走
下一篇:遞回遍歷任意數量的嵌套映射
