generated from VLADIMIR/template
add parser
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package schedule_storage
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"pinned_message/internal/models"
|
||||
)
|
||||
|
||||
type ScheduleStorage struct {
|
||||
filepath string
|
||||
}
|
||||
|
||||
func NewScheduleStorage(
|
||||
filepath string,
|
||||
) *ScheduleStorage {
|
||||
return &ScheduleStorage{
|
||||
filepath: filepath,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ScheduleStorage) SaveSchedule(days []*models.Day) error {
|
||||
data, err := json.Marshal(days)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(s.filepath, data, 0x777); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("save story to: %s", s.filepath)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user