summaryrefslogtreecommitdiff
path: root/internal/entry
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-01 10:05:11 +0300
committerPaul Buetow <paul@buetow.org>2024-10-01 10:05:11 +0300
commit74bcb110cba9cd22b88c561115e332d500de7716 (patch)
tree080287b50ff69e2e601e5ab781da500a93c4b43c /internal/entry
parentcbdce79d25206573d1f79c9c647dcaa251b69463 (diff)
use of entry.Entry around the code base
Diffstat (limited to 'internal/entry')
-rw-r--r--internal/entry/entry.go29
1 files changed, 18 insertions, 11 deletions
diff --git a/internal/entry/entry.go b/internal/entry/entry.go
index 4e837a0..6934eba 100644
--- a/internal/entry/entry.go
+++ b/internal/entry/entry.go
@@ -30,7 +30,7 @@ func (s State) String() string {
}
// The time this code was written a:round, actually.
-const oldestValidTime = "20240922-102800"
+const oldestValidTime = "20240912-102800"
type Entry struct {
Path string
@@ -38,28 +38,35 @@ type Entry struct {
State State
}
+func (e Entry) String() string {
+ return fmt.Sprintf("Path:%s;Stamp:%s,State:%s",
+ e.Path, e.Time.Format(format.Time), e.State)
+}
+
+var Zero = Entry{}
+
// filePath format: /foo/foobarbaz.something.here.txt.STAMP.{posted,queued}
func New(filePath string) (Entry, error) {
- ent := Entry{Path: filePath}
+ e := Entry{Path: filePath}
// We want to get the STAMP!
parts := strings.Split(filePath, ".")
if len(parts) < 4 {
- return ent, fmt.Errorf("not a valid entry path: %s", filePath)
+ return e, fmt.Errorf("not a valid entry path: %s", filePath)
}
switch parts[len(parts)-1] {
case "queued":
- ent.State = Queued
+ e.State = Queued
case "posted":
- ent.State = Posted
+ e.State = Posted
default:
- return ent, fmt.Errorf("can't parse state from path: %s", filePath)
+ return e, fmt.Errorf("can't parse state from path: %s", filePath)
}
var err error
- if ent.Time, err = time.Parse(format.Time, parts[len(parts)-2]); err != nil {
- return ent, err
+ if e.Time, err = time.Parse(format.Time, parts[len(parts)-2]); err != nil {
+ return e, err
}
oldestValid, err := time.Parse(format.Time, oldestValidTime)
@@ -67,9 +74,9 @@ func New(filePath string) (Entry, error) {
panic(err)
}
- if ent.Time.Before(oldestValid) {
- return ent, fmt.Errorf("entry time does not seem legic, it is too old: %v", ent.Time)
+ if e.Time.Before(oldestValid) {
+ return e, fmt.Errorf("entry time does not seem legit, it is too old: %v", e.Time)
}
- return ent, nil
+ return e, nil
}