dongsheng8664 2018-12-02 23:55
浏览 16

Golang的引用类型

I have this

var Map = map[string]Model{}

var (
    mtx    sync.Mutex
    people Map
)

I am getting this error:

enter image description here

Is there any way of referencing the type of the Map, something like this:

var (
    mtx    sync.Mutex
    people reflect.Type(Map)  // <<< ?
)

or should I just resort to declare the type like so:

type Map map[string]Model

and the initializing the map like I do on line 54? I was just trying to initialize the map in the file without having to do it in the Init func.

  • 写回答

3条回答 默认 最新

  • duancaoqin6683 2018-12-03 00:03
    关注

    I'm not sure I understood your problem but you can do something like this:

     var Map = map[string]Model{}
    
     var (
       mtx sync.Mutex
       people = Map
     )
    

    That way people is initialized as same as Map.

    评论

报告相同问题?

悬赏问题

  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题