master
parent
44488aec2d
commit
29bc6a06b4
|
|
@ -2,6 +2,7 @@ package pttodo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
|
@ -44,7 +45,7 @@ func NewRootFromFile(p string) (Root, error) {
|
||||||
if err := yaml.NewDecoder(f).Decode(&result); err != nil {
|
if err := yaml.NewDecoder(f).Decode(&result); err != nil {
|
||||||
todos, err2 := NewTodosFromFile(p)
|
todos, err2 := NewTodosFromFile(p)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return Root{}, err
|
return Root{}, fmt.Errorf("failed to parse yaml from %s: %w", p, err)
|
||||||
}
|
}
|
||||||
result.Todo = todos
|
result.Todo = todos
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package pttodo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -17,7 +18,10 @@ func (schedule Schedule) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (schedule *Schedule) UnmarshalJSON(b []byte) error {
|
func (schedule *Schedule) UnmarshalJSON(b []byte) error {
|
||||||
return json.Unmarshal(b, (*string)(schedule))
|
if err := json.Unmarshal(b, (*string)(schedule)); err != nil {
|
||||||
|
return fmt.Errorf("failed to parse json from %q: %w", b, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (schedule Schedule) Next(t time.Time) (time.Time, error) {
|
func (schedule Schedule) Next(t time.Time) (time.Time, error) {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func NewTodosFromFile(p string) ([]Todo, error) {
|
||||||
|
|
||||||
var result []Todo
|
var result []Todo
|
||||||
if err := yaml.NewDecoder(f).Decode(&result); err != nil {
|
if err := yaml.NewDecoder(f).Decode(&result); err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to parse yaml from %s: %w", p, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package pttodo
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
|
@ -33,7 +34,10 @@ func (ts TS) MarshalYAML() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TS) UnmarshalJSON(b []byte) error {
|
func (ts *TS) UnmarshalJSON(b []byte) error {
|
||||||
return yaml.Unmarshal(b, ts)
|
if err := yaml.Unmarshal(b, ts); err != nil {
|
||||||
|
return fmt.Errorf("faild to unmarshal TS from %q: %w", b, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TS) UnmarshalYAML(unmarshaller func(interface{}) error) error {
|
func (ts *TS) UnmarshalYAML(unmarshaller func(interface{}) error) error {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue