golang语法错误:struct中意外

时间:2018-12-02 22:43:29

标签: go

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,我该如何解决?

2 个答案:

答案 0 :(得分:1)

替换

TaskForIP make(map[string]int)

收件人

TaskForIP map[string]int

答案 1 :(得分:1)

尝试这样的事情:

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)
}