包导入

huangapple go评论84阅读模式
英文:

Package imports

问题

我有一个名为modelpackage,还有两个文件都使用了model包(user.go和task.go)。

我的问题是:在这两个文件中,我都导入了appengineappengine\datasotre库,我需要这样做吗?还是有更好的方法可以做到这一点?

user.go

package model

import "appengine"
import "appengine/datastore"

type User struct {
  name
}

func (u *User) Save(c appengine.Context) (*User, error){
}

task.go

package model
import "appengine"
import "appengine/datastore"

type Task struct {
  name
}

func (u *Task) Save(c appengine.Context) (*Task, error){
}
英文:

I have one package called model and two files which both are using the model package (user.go, task.go).

My question: In both files I am importing the appengine and appengine\datasotre libs, do I need to do so?, or there is a better way of doing this?

user.go

package model

import "appengine"
import "appengine/datastore"


type User struct {
  name
}
func (u *User) Save(c appengine.Context) (*User, error){
}

task.go

package model
import "appengine"
import "appengine/datastore"

type Task struct {
  name
}

func (u *Task) Save(c appengine.Context) (*Task, error){
}

答案1

得分: 3

是的。导入是按文件而不是按包工作的。

我建议安装goimports来处理导入。

英文:

Yes. Imports work per file, not per package.

I recommend installing goimports to handle imports for you.

huangapple
  • 本文由 发表于 2015年1月22日 05:26:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/28077155.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定