从其他包导入的结构未定义

编程入门 行业动态 更新时间:2024-10-25 22:26:45
本文介绍了从其他包导入的结构未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我讨厌的问题.我的models/model.go

Here is my noobish problem. I have this struct in my models/model.go

package models import ( "time" "gopkg.in/mgo.v2/bson" ) type Horse struct { Id bson.ObjectId `bson:"_id,omitempty"` Title string Description string CreatedOn time.Time Creator string Visits int Score int }

在我的controllers/crud.go中,我正在尝试使用Horse结构

And in my controllers/crud.go I'm trying to use Horse struct

package controllers import ( "html/template" "log" "net/http" "horseapp/models" ) [...] var horseStore = make(map[string]Horse) //This raises undefined error

但是当我go install horseapp时我得到了undefined: Horse.

这是怎么了?如何解决?

What is wrong here and how to fix it?

推荐答案

使用

var horseStore = make(map[string]models.Horse)

从另一个包访问标识符时,必须始终在包名前加上一个包名和一个点:package.Identifier

When accessing an identifier from another package you will always have to prefix it with the packages name and a dot: package.Identifier

更多推荐

从其他包导入的结构未定义

本文发布于:2023-11-28 13:27:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:结构   未定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!