diff options
| author | Shulhan <ms@kilabit.info> | 2024-04-17 23:51:53 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-04-18 00:41:07 +0700 |
| commit | a28f1684d9b427149f7a8f03f865bdf57eafc08e (patch) | |
| tree | a9b9244afedef99490d453672dc8b56e662f90bf | |
| parent | 51d14a2686c8ec0dbd876312dd76eec54df0d617 (diff) | |
| download | kamusku-a28f1684d9b427149f7a8f03f865bdf57eafc08e.tar.xz | |
all: rename the module to "kamusku"
| -rw-r--r-- | active_client.go | 8 | ||||
| -rw-r--r-- | api_client.go | 8 | ||||
| -rw-r--r-- | api_client_test.go | 26 | ||||
| -rw-r--r-- | client.go | 12 | ||||
| -rw-r--r-- | cmd/kamusd/main.go | 6 | ||||
| -rw-r--r-- | cmd/kamusku-telegram-bot/main.go | 6 | ||||
| -rw-r--r-- | dictionary.go | 12 | ||||
| -rw-r--r-- | dictionary_test.go | 2 | ||||
| -rw-r--r-- | go.mod | 12 | ||||
| -rw-r--r-- | go.sum | 16 | ||||
| -rw-r--r-- | internal/cmd/embed/main.go | 9 | ||||
| -rw-r--r-- | kamusku.go (renamed from kamusd.go) | 4 | ||||
| -rw-r--r-- | kamusku_test.go (renamed from kamusd_test.go) | 12 | ||||
| -rw-r--r-- | memfs_www.go | 12 | ||||
| -rw-r--r-- | server.go | 12 | ||||
| -rw-r--r-- | telegram_bot.go | 6 |
16 files changed, 88 insertions, 75 deletions
diff --git a/active_client.go b/active_client.go index 805bf44..bd9f189 100644 --- a/active_client.go +++ b/active_client.go @@ -1,14 +1,14 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -package kamusd +package kamusku import ( - "git.sr.ht/~shulhan/kamusku" + "git.sr.ht/~shulhan/kbbi" ) // activeClient define an interface for an active client. type activeClient interface { - Lookup(words []string) (res kamusku.LookupResponse, err error) - ListRootWords() (rootWords kamusku.Words, err error) + Lookup(words []string) (res kbbi.LookupResponse, err error) + ListRootWords() (rootWords kbbi.Words, err error) } diff --git a/api_client.go b/api_client.go index e2c8bb8..77fce29 100644 --- a/api_client.go +++ b/api_client.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -package kamusd +package kamusku import ( "encoding/json" @@ -11,7 +11,7 @@ import ( "net/url" "strings" - "git.sr.ht/~shulhan/kamusku" + "git.sr.ht/~shulhan/kbbi" ) // apiClient is client that connect to cached server API. @@ -38,7 +38,7 @@ func newAPIClient(url string) (client *apiClient) { } // Lookup the definition of words through server API. -func (client *apiClient) Lookup(words []string) (res kamusku.LookupResponse, err error) { +func (client *apiClient) Lookup(words []string) (res kbbi.LookupResponse, err error) { if len(words) == 0 { return nil, nil } @@ -80,7 +80,7 @@ func (client *apiClient) Lookup(words []string) (res kamusku.LookupResponse, err } // ListRootWords list all of the root words in dictionary. -func (client *apiClient) ListRootWords() (res kamusku.Words, err error) { +func (client *apiClient) ListRootWords() (res kbbi.Words, err error) { //TODO: return cached list. return res, nil } diff --git a/api_client_test.go b/api_client_test.go index 6554660..a56175c 100644 --- a/api_client_test.go +++ b/api_client_test.go @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -package kamusd +package kamusku import ( "testing" - "git.sr.ht/~shulhan/kamusku" + "git.sr.ht/~shulhan/kbbi" "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) @@ -18,7 +18,7 @@ func TestApiClient_Lookup_offline(t *testing.T) { cases := []struct { desc string words []string - exp kamusku.LookupResponse + exp kbbi.LookupResponse expError string }{{ desc: "With empty input", @@ -28,13 +28,13 @@ func TestApiClient_Lookup_offline(t *testing.T) { }, { desc: "With valid word in cache", words: []string{"mengeja"}, - exp: kamusku.LookupResponse{ + exp: kbbi.LookupResponse{ "mengeja": testKataMengeja, }, }, { desc: "With duplicate words", words: []string{"mengeja", "mengeja"}, - exp: kamusku.LookupResponse{ + exp: kbbi.LookupResponse{ "mengeja": testKataMengeja, }, }} @@ -48,7 +48,7 @@ func TestApiClient_Lookup_offline(t *testing.T) { continue } - test.Assert(t, `kamusku.LookupResponse`, c.exp, got) + test.Assert(t, `kbbi.LookupResponse`, c.exp, got) } } @@ -62,29 +62,29 @@ func TestApiClient_Lookup_online(t *testing.T) { cases := []struct { desc string words []string - exp kamusku.LookupResponse + exp kbbi.LookupResponse expError string }{{ desc: "With empty input", }, { desc: "With valid word in cache", words: []string{"mengeja"}, - exp: kamusku.LookupResponse{ + exp: kbbi.LookupResponse{ "mengeja": testKataMengeja, }, }, { desc: "With duplicate words", words: []string{"mengeja", "mengeja"}, - exp: kamusku.LookupResponse{ + exp: kbbi.LookupResponse{ "mengeja": testKataMengeja, }, }, { desc: "With one of the word not in cache", words: []string{"mengeja", "eja"}, - exp: kamusku.LookupResponse{ - "mengeja": testKataMengeja, - "eja": &kamusku.Word{ - Definition: []*kamusku.WordDefinition{{ + exp: kbbi.LookupResponse{ + `mengeja`: testKataMengeja, + `eja`: &kbbi.Word{ + Definition: []*kbbi.WordDefinition{{ Value: "lafal huruf satu demi satu", Classes: []string{"Verba: kata kerja"}, }}, @@ -1,26 +1,26 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -package kamusd +package kamusku import ( "fmt" - "git.sr.ht/~shulhan/kamusku" + "git.sr.ht/~shulhan/kbbi" ) // Client for dictionary API and official KBBI server. type Client struct { active activeClient api *apiClient - kbbic *kamusku.KbbiClient + kbbic *kbbi.Client } // NewClient create and initialize new client. func NewClient() (cl *Client, err error) { cl = &Client{} - cl.kbbic, err = kamusku.NewKbbiClient() + cl.kbbic, err = kbbi.NewClient() if err != nil { return nil, err } @@ -37,7 +37,7 @@ func NewClient() (cl *Client, err error) { } // Lookup lookup definition of words. -func (cl *Client) Lookup(words []string) (res kamusku.LookupResponse, err error) { +func (cl *Client) Lookup(words []string) (res kbbi.LookupResponse, err error) { if cl.active != nil { return cl.active.Lookup(words) } @@ -57,7 +57,7 @@ func (cl *Client) IsAuthenticated() bool { } // ListRootWords list all of the root words in dictionary. -func (cl *Client) ListRootWords() (res kamusku.Words, err error) { +func (cl *Client) ListRootWords() (res kbbi.Words, err error) { if cl.active != nil { return cl.active.ListRootWords() } diff --git a/cmd/kamusd/main.go b/cmd/kamusd/main.go index c37eb59..e9999f7 100644 --- a/cmd/kamusd/main.go +++ b/cmd/kamusd/main.go @@ -8,13 +8,13 @@ import ( "os" "os/signal" - "git.sr.ht/~shulhan/kamusd" + "git.sr.ht/~shulhan/kamusku" ) func main() { - log.SetPrefix("kamusd: ") + log.SetPrefix(`kamusd: `) - server, err := kamusd.NewServer("") + server, err := kamusku.NewServer(``) if err != nil { log.Fatal(err) } diff --git a/cmd/kamusku-telegram-bot/main.go b/cmd/kamusku-telegram-bot/main.go index cd0151c..3dc0828 100644 --- a/cmd/kamusku-telegram-bot/main.go +++ b/cmd/kamusku-telegram-bot/main.go @@ -10,11 +10,11 @@ import ( "os" "os/signal" - "git.sr.ht/~shulhan/kamusd" + "git.sr.ht/~shulhan/kamusku" ) func main() { - log.SetPrefix("kamusku-telegram-bot: ") + log.SetPrefix(`kamusku-telegram-bot: `) var ( tgToken = `1121465148:AAE6Yf0YevYcyC--eCZyMqSpVia-pK5iFM4` @@ -22,7 +22,7 @@ func main() { ) // Use the token and Webhook URL from environment variables. - tgbot, err := kamusd.NewTelegramBot(tgToken, tgWebhook) + tgbot, err := kamusku.NewTelegramBot(tgToken, tgWebhook) if err != nil { log.Fatal(err) } diff --git a/dictionary.go b/dictionary.go index 611dd7f..e58151f 100644 --- a/dictionary.go +++ b/dictionary.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -package kamusd +package kamusku import ( "bytes" @@ -11,7 +11,7 @@ import ( "os" "sync" - "git.sr.ht/~shulhan/kamusku" + "git.sr.ht/~shulhan/kbbi" libos "git.sr.ht/~shulhan/pakakeh.go/lib/os" ) @@ -22,7 +22,7 @@ const ( // dictionary contains cache of words and its definitions. type dictionary struct { sync.Mutex - cache map[string]*kamusku.Word + cache map[string]*kbbi.Word lastSize int storagePath string } @@ -34,7 +34,7 @@ func newDictionary(storagePath string) (dict *dictionary, err error) { } dict = &dictionary{ - cache: make(map[string]*kamusku.Word), + cache: make(map[string]*kbbi.Word), storagePath: storagePath, } @@ -47,7 +47,7 @@ func newDictionary(storagePath string) (dict *dictionary, err error) { } // lookup the definition of word from cache or nil if not exist. -func (dict *dictionary) lookup(word string) (kata *kamusku.Word) { +func (dict *dictionary) lookup(word string) (kata *kbbi.Word) { dict.Lock() kata = dict.cache[word] dict.Unlock() @@ -104,7 +104,7 @@ func (dict *dictionary) load() (err error) { } // set save the definition of word into cache. -func (dict *dictionary) set(word string, kata *kamusku.Word) { +func (dict *dictionary) set(word string, kata *kbbi.Word) { if len(word) == 0 || kata == nil { return } diff --git a/dictionary_test.go b/dictionary_test.go index bc8e8bb..0830ee5 100644 --- a/dictionary_test.go +++ b/dictionary_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -package kamusd +package kamusku import ( "testing" @@ -1,20 +1,20 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: CC0-1.0 -module git.sr.ht/~shulhan/kamusd +module git.sr.ht/~shulhan/kamusku go 1.21 require ( - git.sr.ht/~shulhan/kamusku v0.1.0 - git.sr.ht/~shulhan/pakakeh.go v0.54.0 + git.sr.ht/~shulhan/kbbi v0.1.1-0.20240417163139-a6629b6a1f40 + git.sr.ht/~shulhan/pakakeh.go v0.54.1-0.20240416175429-f319122b7363 ) require ( - golang.org/x/net v0.22.0 // indirect - golang.org/x/sys v0.18.0 // indirect + golang.org/x/net v0.24.0 // indirect + golang.org/x/sys v0.19.0 // indirect ) -//replace git.sr.ht/~shulhan/kamusku => ../kamusku +//replace git.sr.ht/~shulhan/kbbi => ../kbbi //replace git.sr.ht/~shulhan/pakakeh.go => ../pakakeh.go @@ -1,8 +1,8 @@ -git.sr.ht/~shulhan/kamusku v0.1.0 h1:ri2tquQ5y9dQ2UMgkwZxC/XMURKdoGR4T3UvE7nOG9Y= -git.sr.ht/~shulhan/kamusku v0.1.0/go.mod h1:MVu5y/PKsG6r29S9oNECDmlDfQ0/GaX6+DNUF3XbVj8= -git.sr.ht/~shulhan/pakakeh.go v0.54.0 h1:pwTQiJSyE5xTaWNR0FnWsszJ+0Z5hB2ufNLXcy8z0y8= -git.sr.ht/~shulhan/pakakeh.go v0.54.0/go.mod h1:ys7WNtXm03x0M59oqrqBjXnc+wRCX8JBXyE/W8+KVbw= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +git.sr.ht/~shulhan/kbbi v0.1.1-0.20240417163139-a6629b6a1f40 h1:GU1+NOFJkGy+VpCMsvNgLqM2/ShKr6anZaE/UoEKjz8= +git.sr.ht/~shulhan/kbbi v0.1.1-0.20240417163139-a6629b6a1f40/go.mod h1:eRPiyedqx9p38Jp2hKcM/l6nmhaE7HlpnFptO9p68bI= +git.sr.ht/~shulhan/pakakeh.go v0.54.1-0.20240416175429-f319122b7363 h1:ieuTxaGu3ccH6sRM+hv6Pfg/xBUtodIYE90Bmx0s1Bk= +git.sr.ht/~shulhan/pakakeh.go v0.54.1-0.20240416175429-f319122b7363/go.mod h1:hJHTZtPS9bOKMNtLljEdJZKHj3eOAXe7fuHcfI6vceY= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/internal/cmd/embed/main.go b/internal/cmd/embed/main.go index 51db740..0350eb1 100644 --- a/internal/cmd/embed/main.go +++ b/internal/cmd/embed/main.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2024 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later + package main import ( @@ -11,9 +14,13 @@ func main() { opts = memfs.Options{ Root: `_www`, Embed: memfs.EmbedOptions{ - PackageName: `kamusd`, + PackageName: `kamusku`, VarName: `memfsWWW`, GoFileName: `memfs_www.go`, + CommentHeader: `// SPDX-FileCopyrightText: 2024 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later + +`, }, } @@ -1,9 +1,9 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -// Package kamusd provide HTTP server API for Kamusku client and Kamusku +// Package kamusku provide HTTP server API for Kamusku client and Kamusku // Telegram bot. -package kamusd +package kamusku import ( "time" diff --git a/kamusd_test.go b/kamusku_test.go index 62cd9ed..3d2989f 100644 --- a/kamusd_test.go +++ b/kamusku_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -package kamusd +package kamusku import ( "log" @@ -9,12 +9,12 @@ import ( "testing" "time" - "git.sr.ht/~shulhan/kamusku" + "git.sr.ht/~shulhan/kbbi" libnet "git.sr.ht/~shulhan/pakakeh.go/lib/net" ) const ( - testServerAPI = "http://127.0.0.1" + defListen + testServerAPI = `http://` + defListen testKamusStorage = "testdata/kamus.gob" ) @@ -22,9 +22,9 @@ const ( var ( testServer *Server - testKataMengeja = &kamusku.Word{ + testKataMengeja = &kbbi.Word{ Root: "eja", - Definition: []*kamusku.WordDefinition{{ + Definition: []*kbbi.WordDefinition{{ Value: "melafalkan (menyebutkan) huruf-huruf satu demi satu", Classes: []string{"Verba: kata kerja"}, Examples: []string{ @@ -52,7 +52,7 @@ func TestMain(m *testing.M) { } }() - err = libnet.WaitAlive(`tcp`, `127.0.0.1`+defListen, 3*time.Second) + err = libnet.WaitAlive(`tcp`, defListen, 3*time.Second) if err != nil { log.Fatal(err) } diff --git a/memfs_www.go b/memfs_www.go index 433074e..f05b34e 100644 --- a/memfs_www.go +++ b/memfs_www.go @@ -1,6 +1,9 @@ +// SPDX-FileCopyrightText: 2024 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later + // Code generated by git.sr.ht/~shulhan/pakakeh.go/lib/memfs DO NOT EDIT. -package kamusd +package kamusku import ( "git.sr.ht/~shulhan/pakakeh.go/lib/memfs" @@ -248,8 +251,11 @@ func init() { Excludes: []string{ }, Embed: memfs.EmbedOptions{ - CommentHeader: ``, - PackageName: "kamusd", + CommentHeader: `// SPDX-FileCopyrightText: 2024 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later + +`, + PackageName: "kamusku", VarName: "memfsWWW", GoFileName: "memfs_www.go", WithoutModTime: false, @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -package kamusd +package kamusku import ( "context" @@ -13,18 +13,18 @@ import ( "sync" "time" - "git.sr.ht/~shulhan/kamusku" + "git.sr.ht/~shulhan/kbbi" "git.sr.ht/~shulhan/pakakeh.go/lib/ascii" libhttp "git.sr.ht/~shulhan/pakakeh.go/lib/http" ) -// Server for kamusku with caching and spell checking functionalities. +// Server for kbbi with caching and spell checking functionalities. type Server struct { httpd *libhttp.Server kamus *dictionary // The client that forward request to official KBBI server. - kbbic *kamusku.KbbiClient + kbbic *kbbi.Client stopped chan bool wg sync.WaitGroup @@ -64,7 +64,7 @@ func NewServer(dictionaryStorage string) (server *Server, err error) { return nil, fmt.Errorf(`%s: %w`, logp, err) } - server.kbbic, err = kamusku.NewKbbiClient() + server.kbbic, err = kbbi.NewClient() if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } @@ -148,7 +148,7 @@ func (server *Server) handleDefinisi(epr *libhttp.EndpointRequest) (resBody []by } inputs := strings.Split(paramKata, ",") - res := make(kamusku.LookupResponse, len(inputs)) + res := make(kbbi.LookupResponse, len(inputs)) for _, in := range inputs { in = strings.TrimSpace(in) diff --git a/telegram_bot.go b/telegram_bot.go index d3c2606..b01b66e 100644 --- a/telegram_bot.go +++ b/telegram_bot.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later -package kamusd +package kamusku import ( "bytes" @@ -10,7 +10,7 @@ import ( "os" "strings" - "git.sr.ht/~shulhan/kamusku" + "git.sr.ht/~shulhan/kbbi" "git.sr.ht/~shulhan/pakakeh.go/api/telegram/bot" ) @@ -154,7 +154,7 @@ dan bebas dipakai oleh publik. } } -func formatText(wordDef kamusku.LookupResponse) string { +func formatText(wordDef kbbi.LookupResponse) string { buf := &bytes.Buffer{} for k, kata := range wordDef { fmt.Fprintf(buf, "<b>%s</b>\n", k) |
