diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-04 10:41:59 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-04 10:41:59 +0300 |
| commit | c40a0fc690a94ab1e9f3253f4e85b394769b3617 (patch) | |
| tree | 2acabaeb3dcea644a5b603d0756da1bf49a9b651 /internal/entry | |
| parent | 68b2a1ba2615c19642c8417d1350b9c6b867b1bb (diff) | |
can read content and can mark as posted the entry
Diffstat (limited to 'internal/entry')
| -rw-r--r-- | internal/entry/entry.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/entry/entry.go b/internal/entry/entry.go index 6934eba..7bb4930 100644 --- a/internal/entry/entry.go +++ b/internal/entry/entry.go @@ -1,7 +1,9 @@ package entry import ( + "errors" "fmt" + "os" "strings" "time" @@ -80,3 +82,22 @@ func New(filePath string) (Entry, error) { return e, nil } + +func (e Entry) Content() (string, error) { + bytes, err := os.ReadFile(e.Path) + return string(bytes), err +} + +func (e *Entry) MarkPosted() error { + if e.State != Queued { + return errors.New("entry is not queued") + } + if e.State == Posted { + return errors.New("entry is already posted") + } + if err := os.Rename(e.Path, strings.TrimSuffix(e.Path, ".queued")+".posted"); err != nil { + return err + } + e.State = Posted + return nil +} |
