Storage: добавлено, что строки с суффиксом "==" - регистрозависимые

Этот коммит содержится в:
Softonik 2024-03-02 04:13:56 +03:00 коммит произвёл Nobody
родитель 79cc4608fa
коммит 62af6c08d2

Просмотреть файл

@ -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() {