Go语言六边形架构:端口与适配器
Go语言六边形架构:端口与适配器
1. 六边形架构
type UserRepository interface { Save(user *User) error FindByID(id string) (*User, error) } type MySQLUserRepository struct{} func (r *MySQLUserRepository) Save(user *User) error { // MySQL实现 }2. 总结
六边形架构实现业务逻辑与基础设施的解耦,提高代码可测试性。
