diff --git a/character.go b/character.go index 7ca8c5a6..632ad590 100644 --- a/character.go +++ b/character.go @@ -8,10 +8,10 @@ import ( //Character 字符 type Character struct { - Hash string `xorm:"pk hash"` - PinYin []string `xorm:"default() notnull pin_yin"` //拼音 - Ch string `xorm:"default() notnull ch"` //字符 - ScienceStroke string `xorm:"science_stroke" json:"science_stroke"` + Hash string `xorm:"pk hash"` + PinYin []string `xorm:"default() notnull pin_yin"` //拼音 + Ch string `xorm:"default() notnull ch"` //字符 + //ScienceStroke string `xorm:"science_stroke" json:"science_stroke"` Radical string `xorm:"default() notnull radical"` //部首 RadicalStroke int `xorm:"default(0) notnull radical_stroke"` //部首笔画 Stroke int `xorm:"default() notnull stroke"` //总笔画数 diff --git a/cmd/console/main.go b/cmd/console/main.go index 2f8ea4d3..62e6f236 100644 --- a/cmd/console/main.go +++ b/cmd/console/main.go @@ -48,7 +48,7 @@ func main() { return nil } app.Action = func(context *cli.Context) error { - e := f.MakeName() + e := f.MakeName(context.Context) if e != nil { return e } diff --git a/fate.go b/fate.go index d435c5fe..c6a0fb18 100644 --- a/fate.go +++ b/fate.go @@ -1,6 +1,7 @@ package fate import ( + "context" "strings" "time" @@ -16,7 +17,7 @@ var DefaultStrokeMin = 0 var HardMode = false type Fate interface { - MakeName() (e error) + MakeName(ctx context.Context) (e error) XiYong() *XiYong //SetCharDB(engine *xorm.Engine) //GetLastCharacter() error @@ -122,7 +123,7 @@ func (f *fateImpl) getLastCharacter() error { return nil } -func (f *fateImpl) MakeName() (e error) { +func (f *fateImpl) MakeName(ctx context.Context) (e error) { n, e := CountWuGeLucky(f.db) if e != nil { return Wrap(e, "count total error") @@ -154,6 +155,12 @@ func (f *fateImpl) MakeName() (e error) { var tmpChar []*Character //supplyFilter := false for n := range name { + select { + case <-ctx.Done(): + return + default: + + } if f.debug { log.With("name", n.String()).Info("name") }