Go语言中接口和实现的命名规范?

Go对于接口和其实现的命名规范是什么?

假设整个Web项目都依赖于接口,比如service:

type UserService interface {
    SignupByEmail(ctx *gin.Context, user domain.User) error
    LoginByEmail(ctx *gin.Context, user domain.User) (domain.User, error)
}

type UserServiceImp struct {
    userRepo repo.UserRepository
}

func NewUserServiceImp(userRepo repo.UserRepository) *UserServiceImp {
    return &UserServiceImp{userRepo: userRepo}
}

但是好像对于GO来说一般不像在Java一样在后面加interface或者Imp来标识,之前看到有人是直接以大小写的UserService和userService来区分接口和实现,但是这样的话构造函数就只能返回接口不能返回具体实现了。
对于repository也有相同的疑问,对于dao和cache我是直接接口UserDao然后实现UserMysqlDao用具体的dao实现来区别的。
有其他更优雅的符合Go的命名吗?

阅读 932
1 个回答

推荐一个谷歌的 go best practices 网站: best-practices, 希望对你有用。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题