diff options
| author | Shulhan <ms@kilabit.info> | 2024-04-06 17:44:13 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-04-06 17:44:13 +0700 |
| commit | 3245b00f0246f7f2f0afd8635cfd3ff9bf2cf584 (patch) | |
| tree | 286817224a5d72569e4db335578b3549f566deda /dictionary.go | |
| parent | 6c7bfd42bc1128f5969e9e40b23d6b828601f7cb (diff) | |
| download | kamusku-3245b00f0246f7f2f0afd8635cfd3ff9bf2cf584.tar.xz | |
all: replace "share" module with "pakakeh.go"
The "share" module has been moved to new forge, SourceHut, with new name
"pakakeh.go".
Diffstat (limited to 'dictionary.go')
| -rw-r--r-- | dictionary.go | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/dictionary.go b/dictionary.go index 2dd309f..9164b25 100644 --- a/dictionary.go +++ b/dictionary.go @@ -8,22 +8,19 @@ import ( "bytes" "encoding/gob" "errors" - "io/ioutil" "log" "os" "sync" "git.sr.ht/~shulhan/kamusku" - libio "github.com/shuLhan/share/lib/io" + libos "git.sr.ht/~shulhan/pakakeh.go/lib/os" ) const ( defStorageName = "kamus.gob" ) -// // dictionary contains cache of words and its definitions. -// type dictionary struct { sync.Mutex cache map[string]*kamusku.Word @@ -31,9 +28,7 @@ type dictionary struct { storagePath string } -// // newDictionary create and initialize the cache for dictionary. -// func newDictionary(storagePath string) (dict *dictionary, err error) { if len(storagePath) == 0 { storagePath = defStorageName @@ -52,9 +47,7 @@ func newDictionary(storagePath string) (dict *dictionary, err error) { return dict, nil } -// // lookup the definition of word from cache or nil if not exist. -// func (dict *dictionary) lookup(word string) (kata *kamusku.Word) { dict.Lock() kata = dict.cache[word] @@ -62,24 +55,22 @@ func (dict *dictionary) lookup(word string) (kata *kamusku.Word) { return kata } -// // isChanging will return true if the last cache size is not equal with // current size. -// func (dict *dictionary) isChanging() bool { dict.Lock() defer dict.Unlock() return dict.lastSize != len(dict.cache) } -// // load the cached dictionary from storage. -// func (dict *dictionary) load() (err error) { dict.Lock() defer dict.Unlock() - v, err := ioutil.ReadFile(dict.storagePath) + var v []byte + + v, err = os.ReadFile(dict.storagePath) if err != nil { if errors.Is(err, os.ErrNotExist) { return nil @@ -113,9 +104,7 @@ func (dict *dictionary) load() (err error) { return nil } -// // set save the definition of word into cache. -// func (dict *dictionary) set(word string, kata *kamusku.Word) { if len(word) == 0 || kata == nil { return @@ -126,9 +115,7 @@ func (dict *dictionary) set(word string, kata *kamusku.Word) { dict.Unlock() } -// // store the cache to file only if the storage path is set. -// func (dict *dictionary) store() (err error) { if len(dict.storagePath) == 0 { return nil @@ -167,7 +154,7 @@ func (dict *dictionary) store() (err error) { log.Println("dictionary: store: ", err) } - err = libio.Copy(dict.storagePath, newStorage) + err = libos.Copy(dict.storagePath, newStorage) if err != nil { return err } |
