README ¶ service 业务逻辑层,处于 handler 层和 repository 层之间 service 只能通过 repository 层获取数据 面向接口编程 依赖接口,不要依赖实现 如果有事务处理,在这一层进行处理 如果是调用的第三方服务,请不要加 cache, 避免缓存不一致(对方更新数据,这边无法知晓) 由于 service 会被 http 或 rpc 调用,默认会提供 http 调用的,比如:GetUserInfo(), 如果 rpc 需要调用,可以对 GetUserInfo() 进行一层封装, 比如:GetUser()。 Reference https://github.com/qiangxue/go-rest-api https://github.com/irahardianto/service-pattern-go https://github.com/golang-standards/project-layout https://www.youtube.com/watch?v=oL6JBUk6tj0 https://peter.bourgon.org/blog/2017/06/09/theory-of-modern-go.html https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1 按需写 service 服务层逻辑 Go 编程实战:如何组织代码、编写测试? https://github.com/sdgmf/go-project-sample Golang微服务最佳实践 layout 常见大型 Web 项目分层 在 Golang 中尝试简洁架构 Expand ▾ Collapse ▴ Documentation ¶ Index ¶ type Service func New() (s *Service) func (s *Service) Close() func (s *Service) Ping() error func (s *Service) UserSvc() user.UserService Constants ¶ This section is empty. Variables ¶ This section is empty. Functions ¶ This section is empty. Types ¶ type Service ¶ type Service struct { // contains filtered or unexported fields } Service struct var ( // Svc global service var Svc *Service ) func New ¶ func New() (s *Service) New init service func (*Service) Close ¶ func (s *Service) Close() Close service func (*Service) Ping ¶ func (s *Service) Ping() error Ping service func (*Service) UserSvc ¶ func (s *Service) UserSvc() user.UserService UserSvc return user service Source Files ¶ View all Source files service.go Directories ¶ Show internal Expand all Path Synopsis sms user vcode Click to show internal directories. Click to hide internal directories.