From 62af6c08d2b4bfb44f35b5d39f1eacf5c1a65913 Mon Sep 17 00:00:00 2001 From: Softonik Date: Sat, 2 Mar 2024 04:13:56 +0300 Subject: [PATCH] =?UTF-8?q?Storage:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE,=20=D1=87=D1=82=D0=BE=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D0=B8=20=D1=81=20=D1=81=D1=83=D1=84=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D1=81=D0=BE=D0=BC=20"=3D=3D"=20-=20=D1=80=D0=B5=D0=B3?= =?UTF-8?q?=D0=B8=D1=81=D1=82=D1=80=D0=BE=D0=B7=D0=B0=D0=B2=D0=B8=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/storage/storage.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 4ac02af..bb99190 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -13,11 +13,11 @@ import ( ) type Storage struct { - filename string - fd *os.File - watcher *fsnotify.Watcher - list List - lock sync.RWMutex + filename string + fd *os.File + watcher *fsnotify.Watcher + list, listCase List + lock sync.RWMutex } type List []string @@ -40,7 +40,7 @@ func (s *Storage) reReadFile() error { return err } - var newlist List + var newlist, newlistCase List scanner := bufio.NewScanner(fd) for { @@ -50,13 +50,19 @@ func (s *Storage) reReadFile() error { } line := scanner.Text() - newlist = append(newlist, line) + + if strings.HasSuffix(line, "==") { + newlistCase = append(newlistCase, line[:len(line)-2]) + } else { + newlist = append(newlist, line) + } } s.lock.Lock() defer s.lock.Unlock() s.list = newlist + s.listCase = newlistCase return nil } @@ -148,6 +154,12 @@ func (s *Storage) GetList() *List { return &s.list } +func (s *Storage) GetListCase() *List { + s.lock.RLock() + defer s.lock.RUnlock() + + return &s.listCase +} func (s *Storage) AddLine(p, v string) error { return nil @@ -158,6 +170,7 @@ func (s *Storage) Save() error { } func (s *Storage) doSave() error { buf := strings.Join(s.list, "\n") + buf += strings.Join(s.listCase, "==\n") return lib.WriteFile(s.filename, buf) } func (s *Storage) makeBackup() {