chore: splitting monolith into packages
This commit is contained in:
29
utils/write_backlog.go
Normal file
29
utils/write_backlog.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"gotask-cli/models"
|
||||
)
|
||||
|
||||
const tempPath string = "./tasks.save"
|
||||
|
||||
func SaveBacklog(backlog []models.Task, path string) {
|
||||
if _, err := os.Stat(tempPath); err == nil {
|
||||
err = os.Remove(tempPath)
|
||||
} else if errors.Is(err, os.ErrNotExist) {
|
||||
} else {
|
||||
Check(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
f, err := os.Create(tempPath)
|
||||
Check(err)
|
||||
defer f.Close()
|
||||
backlogJSON, _ := json.MarshalIndent(backlog, "", "\t")
|
||||
f.Write(backlogJSON)
|
||||
|
||||
err = os.Rename(tempPath, path)
|
||||
Check(err)
|
||||
}
|
||||
Reference in New Issue
Block a user