[英]golang syntax error: unexpected in struct
type WebServer struct {
TodoService task.TodoService
UserService usr.UserService
SessionService session.Service
CategoryService task.CategoryService
WorkerService task.WorkerService
ApiWorkerService task.ApiWorkerService
BlacklistService task.BlacklistService
LabelService *labels.Service
StatusService *statuses.Service
InviteService *invites.Service
Runner *task.Runner
TaskForIP make(map[string]int)
Params WebServerParams
}
這是我當前的代碼,不是我的應用程序,並返回此錯誤:
app\infrastructure\web\webserver.go:41:23: syntax error: unexpected (, expecting
semicolon or newline or }
第41行是TaskForIP行,由於在應用程序中是必需的,因此我無法刪除make,我該如何解決?
更換
TaskForIP make(map[string]int)
至
TaskForIP map[string]int
嘗試這樣的事情:
package main
import (
"log"
)
type WebServer struct {
TodoService task.TodoService
UserService usr.UserService
SessionService session.Service
CategoryService task.CategoryService
WorkerService task.WorkerService
ApiWorkerService task.ApiWorkerService
BlacklistService task.BlacklistService
LabelService *labels.Service
StatusService *statuses.Service
InviteService *invites.Service
Runner *task.Runner
TaskForIP map[string]int
Params WebServerParams
}
func (ws WebServer) NewInstance() WebServer {
ws.TaskForIP = make(map[string]int)
return ws
}
func main() {
webServer := WebServer{}.NewInstance()
log.Println(webServer)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.