services.UserRegister()
services.User
- [other directories here]/
- services/
- user.go
- [other service structs here]
- main.go
services/user.go
package services
type User struct { ... }
func NewUserService(){ ... }
func (u User) Register() { ... }
servicesservice
services
- services/
- app_user.go // the AppUser struct
- [other services here]
- map_user.go // the MapUser struct
- [other services here]
- user.go // the User interface
- [other service structs here]
servicesUseruser.go
services.New(...)services
One of the simplest ideas I had to solve this is to go against convention and embrace repetition:
- services/
- userService/
- app.go // the AppUser struct
- map.go // the MapUser struct
- interface.go // the User interface
- [other services here]
userService.UserService
I've looked at all kinds of web application templates, and none of them (beyond the ones that are incredibly barebones) have an elegant solution to this structural. Most (if not all) of them simply omit interfaces completely to solve it, which is unacceptable.
Any tips or hints?