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的命名吗?
推荐一个谷歌的
go best practices
网站: best-practices, 希望对你有用。