Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
verify candidates-num
Browse files Browse the repository at this point in the history
  • Loading branch information
high-moctane committed Nov 28, 2019
1 parent e647478 commit f7b3137
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nextword.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ type Nextword struct {

// NewNextword returns new Nextword. If dataPath is not valid, err will be not nil.
func NewNextword(dataPath string, params *NextwordParams) (*Nextword, error) {
// dataPath
fi, err := os.Stat(dataPath)
if err != nil {
return nil, errors.New(`"NEXTWORD_DATA_PATH" environment variable is not set`)
}
if !fi.IsDir() {
return nil, errors.New(`invalid "NEXTWORD_DATA_PATH"`)
}

// candidate-num
if params.CandidateNum <= 0 {
return nil, errors.New("candidate-num must be positive intager")
}

return &Nextword{
DataPath: dataPath,
ReadLineBufSize: ReadLineBufSize,
Expand Down

0 comments on commit f7b3137

Please sign in to comment.