This document summarizes a microservices meetup hosted by @mosa_siru. Key points include:
1. @mosa_siru is an engineer at DeNA and CTO of Gunosy.
2. The meetup covered Gunosy's architecture with over 45 GitHub repositories, 30 stacks, 10 Go APIs, and 10 Python batch processes using AWS services like Kinesis, Lambda, SQS and API Gateway.
3. Challenges discussed were managing 30 microservices, ensuring API latency below 50ms across availability zones, and handling 10 requests per second with nginx load balancing across 20 servers.
18. type User struct {
HP, Attack, Defense int
Job string
Condition int
}
先程の修正でもよさそうだが、
ユーザーは攻撃力の他にも属性を持つ事が多い
User がロジックを持ってしまうと、
各属性に関する処理を全て User が持つことになる
User クラスの責務がどんどん肥大化してしまう
27. type User struct {
Attack Attack //攻撃力
}
func (u User) GetAttack() int {
return u.Attack.GetPoint()
}
攻撃力計算ロジックは Attack クラスが持っているので、
User クラスは変わらない
28. type Attack struct {
Point int
AttackLogic AttackLogic
}
func (a Attack) GetPoint() int {
rand.Seed(time.Now().UnixNano())
return a.Point + rand.Intn(10) + a.AttackLogic.Calc()
}
type AttackLogic interface {
Calc() int
}
type XxxEvent struct {
Point int
}
func (x XxxEvent) Calc() int {
//Xxx というイベントでは攻撃力が2倍になる
return x.Point * 2
}
AttackLogic interface を新規作成
AttackLogic を満たすクラスを
Attack にセットすれば、
目的に合った攻撃力計算が可能になる
今回は Xxxイベント というイベント用の
AttackLogic を用意している
29. func main() {
point := 100
u := User{
Attack: Attack{
Point: point,
AttackLogic: XxxEvent {
Point: point,
},
},
}
fmt.Println(u.GetAttack())
}
AttackLogic の管理方法はちゃんと考える必要があるが、
時間ないので割愛