add pttodo.NewRootFromFile, pttodo.NewTodosFromFile
This commit is contained in:
@@ -4,7 +4,10 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type Todo struct {
|
||||
@@ -17,6 +20,24 @@ type Todo struct {
|
||||
writeTS bool
|
||||
}
|
||||
|
||||
func NewTodosFromFile(p string) ([]Todo, error) {
|
||||
f, err := os.Open(p)
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var result []Todo
|
||||
if err := yaml.NewDecoder(f).Decode(&result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (todo Todo) ID() string {
|
||||
hash := crc32.NewIEEE()
|
||||
fmt.Fprintf(hash, "%d:%s", 0, todo.Todo)
|
||||
|
||||
Reference in New Issue
Block a user