package service
|
|
import (
|
"context"
|
)
|
|
type MysqlInitHandler struct{}
|
|
func NewMysqlInitHandler() *MysqlInitHandler {
|
return &MysqlInitHandler{}
|
}
|
|
func (h MysqlInitHandler) InitData(ctx context.Context, inits initSlice) error {
|
next, cancel := context.WithCancel(ctx)
|
defer func(c func()) { c() }(cancel)
|
for _, init := range inits {
|
if init.DataInserted(next) {
|
continue
|
}
|
if n, err := init.InitializeData(next); err != nil {
|
return err
|
} else {
|
next = n
|
}
|
}
|
return nil
|
}
|