diff options
| author | Shulhan <ms@kilabit.info> | 2024-04-06 16:32:57 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-04-06 16:32:57 +0700 |
| commit | 772747f4051085443b38db8fb8f01ada41e89fc5 (patch) | |
| tree | 940c196b79018ff9ae1e592c6db9a000eb4044fe | |
| parent | 424583f727bf5d7da0552780ba369834a73c36d3 (diff) | |
| download | kbbi-772747f4051085443b38db8fb8f01ada41e89fc5.tar.xz | |
all: replace "share" module with "pakakeh.go" module
The "share" module repository has been moved to SourceHut with new name
"pakakeh.go".
For more information on why we moved, see the project page at
https://sr.ht/~shulhan/pakakeh.go.
| -rw-r--r-- | cmd/kamusku/main.go | 2 | ||||
| -rw-r--r-- | go.mod | 8 | ||||
| -rw-r--r-- | go.sum | 29 | ||||
| -rw-r--r-- | kamusku.go | 2 | ||||
| -rw-r--r-- | kbbi_client.go | 45 | ||||
| -rw-r--r-- | kbbi_client_test.go | 4 | ||||
| -rw-r--r-- | lookup_response.go | 2 | ||||
| -rw-r--r-- | word.go | 10 | ||||
| -rw-r--r-- | word_definition.go | 6 | ||||
| -rw-r--r-- | word_test.go | 10 | ||||
| -rw-r--r-- | words.go | 4 |
11 files changed, 30 insertions, 92 deletions
diff --git a/cmd/kamusku/main.go b/cmd/kamusku/main.go index b48a791..01c492b 100644 --- a/cmd/kamusku/main.go +++ b/cmd/kamusku/main.go @@ -2,10 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// // Program kamusku is the command-line interface to Kamus Besar Bahasa // Indonesia (KBBI). -// package main import ( @@ -1,8 +1,10 @@ module git.sr.ht/~shulhan/kamusku -go 1.15 +go 1.21 require ( - github.com/shuLhan/share v0.22.0 - golang.org/x/net v0.0.0-20210119194325-5f4716e94777 + git.sr.ht/~shulhan/pakakeh.go v0.54.0 + golang.org/x/net v0.22.0 ) + +require golang.org/x/sys v0.18.0 // indirect @@ -1,23 +1,6 @@ -git.sr.ht/~shulhan/asciidoctor-go v0.0.0-20201205130914-be765f32b57b/go.mod h1:ejaxKeBMNL5EpP2zjRP4B8zuOr+MM4ZyGwE3y7807WI= -git.sr.ht/~shulhan/ciigo v0.3.0/go.mod h1:Y5FvSiJg88qshoR1ktj4fLzM5sk1pZcV0kJGU8GAuTo= -github.com/shuLhan/share v0.20.2-0.20201122173411-e8b3bf5ee6e9/go.mod h1:oBv+CGHG6u4Sa71+nJJJji8mCgPAadywjsB3I3k/b0o= -github.com/shuLhan/share v0.20.2-0.20201205202022-66069b9e49fe/go.mod h1:oBv+CGHG6u4Sa71+nJJJji8mCgPAadywjsB3I3k/b0o= -github.com/shuLhan/share v0.22.0 h1:oTV1M0X3TqyhwSoT0BxVBmnUZLbhkvRwmhyV0KkTOR4= -github.com/shuLhan/share v0.22.0/go.mod h1:u9caerexlcxmPVDttj7PnkxCBDY6yBRTZ+gGR+1tO98= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +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= @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// // Package kamusku is the Go library to access the Bahasa Indonesia dictionary // from https://kbbi.kemdikbud.go.id. -// package kamusku diff --git a/kbbi_client.go b/kbbi_client.go index 23767b4..0caee38 100644 --- a/kbbi_client.go +++ b/kbbi_client.go @@ -9,7 +9,7 @@ import ( "encoding/gob" "errors" "fmt" - "io/ioutil" + "io" "log" "net/http" "net/http/cookiejar" @@ -20,9 +20,8 @@ import ( "strings" "time" - "github.com/shuLhan/share/lib/debug" - libhttp "github.com/shuLhan/share/lib/http" - "github.com/shuLhan/share/lib/net/html" + "git.sr.ht/~shulhan/pakakeh.go/lib/html" + libhttp "git.sr.ht/~shulhan/pakakeh.go/lib/http" "golang.org/x/net/publicsuffix" ) @@ -64,9 +63,7 @@ const ( maxPageNumber = 501 ) -// // KbbiClient client for official KBBI web using HTTP. -// type KbbiClient struct { baseDir string cookieURL *url.URL @@ -74,10 +71,8 @@ type KbbiClient struct { httpc *http.Client } -// // NewKbbiClient create and initialize new client that connect directly to // KBBI official website. -// func NewKbbiClient() (cl *KbbiClient, err error) { cookieURL, err := url.Parse(kbbiUrlBase) if err != nil { @@ -113,9 +108,7 @@ func NewKbbiClient() (cl *KbbiClient, err error) { return cl, nil } -// // Lookup lookup definition of one or more words. -// func (cl *KbbiClient) Lookup(ins []string) (res LookupResponse, err error) { res = make(LookupResponse, len(ins)) @@ -137,16 +130,12 @@ func (cl *KbbiClient) Lookup(ins []string) (res LookupResponse, err error) { defer httpRes.Body.Close() - body, err := ioutil.ReadAll(httpRes.Body) + body, err := io.ReadAll(httpRes.Body) if err != nil { kata.err = err continue } - if debug.Value >= 3 { - fmt.Printf(">>> HTML body for %s:\n%s", entriURL, body) - } - err = kata.parseHTMLEntri(in, body) if err != nil { kata.err = err @@ -160,9 +149,7 @@ func (cl *KbbiClient) Lookup(ins []string) (res LookupResponse, err error) { return res, nil } -// // ListRootWords list all of the root words in dictionary. -// func (cl *KbbiClient) ListRootWords() (rootWords Words, err error) { params := url.Values{ paramNameMasukan: []string{paramValueDasar}, @@ -189,7 +176,7 @@ func (cl *KbbiClient) ListRootWords() (rootWords Words, err error) { defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return rootWords, fmt.Errorf("ListRootWords: page %d: %w", pageNumber, err) @@ -213,17 +200,13 @@ func (cl *KbbiClient) ListRootWords() (rootWords Words, err error) { return rootWords, nil } -// // IsAuthenticated will return true if the client already login; otherwise it // will return false. -// func (cl *KbbiClient) IsAuthenticated() bool { return len(cl.cookies) > 0 } -// // Login authenticate the client using user email and password. -// func (cl *KbbiClient) Login(email, pass string) (err error) { tokenLogin, err := cl.preLogin() if err != nil { @@ -253,7 +236,7 @@ func (cl *KbbiClient) Login(email, pass string) (err error) { defer res.Body.Close() - resBody, err := ioutil.ReadAll(res.Body) + resBody, err := io.ReadAll(res.Body) if err != nil { return fmt.Errorf("Login: %w", err) } @@ -269,9 +252,7 @@ func (cl *KbbiClient) Login(email, pass string) (err error) { return nil } -// // setCookies for HTTP request that need an authentication. -// func (cl *KbbiClient) setCookies() { cl.httpc.Jar.SetCookies(cl.cookieURL, cl.cookies) } @@ -304,9 +285,7 @@ func (cl *KbbiClient) parseHTMLRootWords(htmlBody []byte) ( return rootWords, nil } -// // parseHTMLLogin get the token at the form login. -// func (cl *KbbiClient) parseHTMLLogin(htmlBody []byte) ( token string, err error, ) { @@ -332,9 +311,7 @@ func (cl *KbbiClient) parseHTMLLogin(htmlBody []byte) ( return "", fmt.Errorf("token login not found") } -// // preLogin initialize the client to get the first cookie. -// func (cl *KbbiClient) preLogin() (token string, err error) { req, err := http.NewRequest(http.MethodGet, kbbiUrlLogin, nil) if err != nil { @@ -348,7 +325,7 @@ func (cl *KbbiClient) preLogin() (token string, err error) { defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return "", err } @@ -361,9 +338,7 @@ func (cl *KbbiClient) preLogin() (token string, err error) { return token, nil } -// // loadCookies load the KBBI cookies from file. -// func (cl *KbbiClient) loadCookies() (err error) { cl.baseDir, err = os.UserConfigDir() if err != nil { @@ -377,7 +352,7 @@ func (cl *KbbiClient) loadCookies() (err error) { return nil } - body, err := ioutil.ReadFile(f) + body, err := os.ReadFile(f) if err != nil { return fmt.Errorf("loadCookies: %w", err) } @@ -392,9 +367,7 @@ func (cl *KbbiClient) loadCookies() (err error) { return nil } -// // saveCookies store the client cookies to the file for future use. -// func (cl *KbbiClient) saveCookies() { err := os.MkdirAll(filepath.Join(cl.baseDir, configDir), 0700) if err != nil { @@ -410,7 +383,7 @@ func (cl *KbbiClient) saveCookies() { log.Println("saveCookies: ", err) } - err = ioutil.WriteFile(f, buf.Bytes(), 0600) + err = os.WriteFile(f, buf.Bytes(), 0600) if err != nil { log.Println("saveCookies: ", err) } diff --git a/kbbi_client_test.go b/kbbi_client_test.go index d83ab5c..d96d5ad 100644 --- a/kbbi_client_test.go +++ b/kbbi_client_test.go @@ -5,12 +5,12 @@ package kamusku import ( - "io/ioutil" + "os" "testing" ) func TestClient_parseHTMLKataDasar(t *testing.T) { - htmlBody, err := ioutil.ReadFile("testdata/kbbi_dasar.html") + htmlBody, err := os.ReadFile(`testdata/kbbi_dasar.html`) if err != nil { t.Fatal(err) } diff --git a/lookup_response.go b/lookup_response.go index aac9175..f2d9bea 100644 --- a/lookup_response.go +++ b/lookup_response.go @@ -4,7 +4,5 @@ package kamusku -// // LookupResponse contains mapping of word and its definition. -// type LookupResponse map[string]*Word @@ -7,12 +7,10 @@ package kamusku import ( "bytes" - "github.com/shuLhan/share/lib/net/html" + "git.sr.ht/~shulhan/pakakeh.go/lib/html" ) -// // Word store the single root word and its definitions. -// type Word struct { Root string `json:"dasar,omitempty"` // The root word Definition []*WordDefinition `json:"definisi"` // The word definition. @@ -24,17 +22,13 @@ type Word struct { err error } -// // Err return an error from retrieving definition. -// func (word *Word) Err() error { return word.err } -// // parseHTMLEntri parse HTML body from "/entri/<word>" page to find the // definition of the word. -// func (word *Word) parseHTMLEntri(in string, htmlBody []byte) (err error) { iter, err := html.Parse(bytes.NewReader(htmlBody)) if err != nil { @@ -73,10 +67,8 @@ func (word *Word) parseHTMLEntri(in string, htmlBody []byte) (err error) { return nil } -// // parseRootWord given an HMTL element "h2" find a possible root word and // return true; otherwise it will return false. -// func (word *Word) parseRootWord(h2 *html.Node) bool { el := h2.GetFirstChild() if el.Data != tagNameSpan { diff --git a/word_definition.go b/word_definition.go index 86b05bd..8f6113a 100644 --- a/word_definition.go +++ b/word_definition.go @@ -8,14 +8,12 @@ import ( "fmt" "strings" - "github.com/shuLhan/share/lib/net/html" - libstrings "github.com/shuLhan/share/lib/strings" + "git.sr.ht/~shulhan/pakakeh.go/lib/html" + libstrings "git.sr.ht/~shulhan/pakakeh.go/lib/strings" ) -// // WordDefinition contains the meaning of word in dictionary, and optional // attribute for word classifications and examples. -// type WordDefinition struct { Value string `json:"isi"` Classes []string `json:"kelas,omitempty"` diff --git a/word_test.go b/word_test.go index 5dcb468..cfc0de5 100644 --- a/word_test.go +++ b/word_test.go @@ -5,10 +5,10 @@ package kamusku import ( - "io/ioutil" + "os" "testing" - "github.com/shuLhan/share/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) func TestWord_parseHTMLEntri(t *testing.T) { @@ -45,7 +45,7 @@ func TestWord_parseHTMLEntri(t *testing.T) { }} for _, c := range cases { - htmlBody, err := ioutil.ReadFile(c.infile) + htmlBody, err := os.ReadFile(c.infile) if err != nil { t.Fatal(err) } @@ -58,9 +58,9 @@ func TestWord_parseHTMLEntri(t *testing.T) { } for x, def := range c.exp.Definition { - test.Assert(t, "Definition", def, got.Definition[x], true) + test.Assert(t, `Definition`, def, got.Definition[x]) } - test.Assert(t, c.infile, c.exp, got, true) + test.Assert(t, c.infile, c.exp, got) } } @@ -4,14 +4,10 @@ package kamusku -// // Words contains list of words. -// type Words map[string]struct{} -// // merge other map into current map. -// func (words Words) merge(in Words) Words { for k := range in { words[k] = struct{}{} |
