diff options
| -rw-r--r-- | .gitignore | 14 | ||||
| -rw-r--r-- | Makefile | 12 | ||||
| -rw-r--r-- | README.adoc | 2 | ||||
| -rw-r--r-- | _www-kamusku/assets/github.svg (renamed from _www-kbbi/assets/github.svg) | 0 | ||||
| -rw-r--r-- | _www-kamusku/assets/linux.svg (renamed from _www-kbbi/assets/linux.svg) | 0 | ||||
| -rw-r--r-- | _www-kamusku/assets/macos.svg (renamed from _www-kbbi/assets/macos.svg) | 0 | ||||
| -rw-r--r-- | _www-kamusku/assets/windows.svg (renamed from _www-kbbi/assets/windows.svg) | 0 | ||||
| -rw-r--r-- | _www-kamusku/index.html (renamed from _www-kbbi/index.html) | 0 | ||||
| -rw-r--r-- | _www-kamusku/index.js (renamed from _www-kbbi/index.js) | 0 | ||||
| -rw-r--r-- | _www-kamusku/kbbiclient.js (renamed from _www-kbbi/kbbiclient.js) | 0 | ||||
| -rw-r--r-- | active_client.go | 2 | ||||
| -rw-r--r-- | api_client.go | 2 | ||||
| -rw-r--r-- | api_client_test.go | 2 | ||||
| -rw-r--r-- | client.go | 2 | ||||
| -rw-r--r-- | cmd/bot-kamusku/app.yaml (renamed from cmd/bot-kbbi/app.yaml) | 4 | ||||
| -rw-r--r-- | cmd/bot-kamusku/main.go (renamed from cmd/bot-kbbi/main.go) | 8 | ||||
| -rw-r--r-- | cmd/kbbi/main.go | 9 | ||||
| -rw-r--r-- | cmd/www-kamusku/app.yaml (renamed from cmd/www-kbbi/app.yaml) | 0 | ||||
| -rw-r--r-- | cmd/www-kamusku/main.go (renamed from cmd/www-kbbi/main.go) | 4 | ||||
| -rw-r--r-- | daftar_kata.go | 2 | ||||
| -rw-r--r-- | definisi_kata.go | 2 | ||||
| -rw-r--r-- | definisi_response.go | 2 | ||||
| -rw-r--r-- | direct_client.go | 5 | ||||
| -rw-r--r-- | direct_client_test.go | 2 | ||||
| -rw-r--r-- | generate.go | 2 | ||||
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | internal/cmd/mergedic/main.go | 2 | ||||
| -rw-r--r-- | kamus_cache.go | 2 | ||||
| -rw-r--r-- | kamus_cache_test.go | 2 | ||||
| -rw-r--r-- | kamusku.go (renamed from kbbi.go) | 8 | ||||
| -rw-r--r-- | kamusku_test.go (renamed from kbbi_test.go) | 2 | ||||
| -rw-r--r-- | kata.go | 2 | ||||
| -rw-r--r-- | kata_test.go | 2 | ||||
| -rw-r--r-- | server.go | 51 | ||||
| -rw-r--r-- | telegram_bot.go | 16 |
35 files changed, 107 insertions, 58 deletions
@@ -1,13 +1,13 @@ -/_www-kbbi/bin/* -/bot-kbbi -/bot-kbbi-linux-amd64 -/cmd/www-kbbi/static.go +/_www-kamusku/bin/* +/bot-kamusku +/bot-kamusku-linux-amd64 +/cmd/www-kamusku/static.go /internal/cmd/mergedic/id_ID.dic /internal/cmd/mergedic/id_ID.dic.new /kamus.gob /kamus.gob.new -/kbbi +/kamusku /testdata/kamus.gob /testdata/kamus.gob.new -/www-kbbi -/www-kbbi-linux-amd64 +/www-kamusku +/www-kamusku-linux-amd64 @@ -18,6 +18,8 @@ lint: --disable=gomnd \ --disable=wsl \ --disable=gocognit \ + --disable=goerr113 \ + --disable=testpackage \ ./... test: @@ -45,18 +47,18 @@ release: deploy: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ - go build -o www-kbbi-linux-amd64 ./cmd/www-kbbi/ - rsync --progress ./www-kbbi-linux-amd64 www-kbbi:~/bin/www-kbbi - rsync --progress --recursive ./_www-kbbi/ www-kbbi:~/bin/_www-kbbi/ + go build -o www-kamusku-linux-amd64 ./cmd/www-kamusku/ + rsync --progress ./www-kamusku-linux-amd64 www-kamusku:~/bin/www-kamusku + rsync --progress --recursive ./_www-kamusku/ www-kamusku:~/bin/_www-kamusku/ deploy-bot: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ go build -o bot-kbbi-linux-amd64 ./cmd/bot-kbbi/ - rsync --progress ./bot-kbbi-linux-amd64 www-kbbi:~/bin/bot-kbbi + rsync --progress ./bot-kbbi-linux-amd64 www-kamusku:~/bin/bot-kbbi ## ## Development task ## dev-server: - DEBUG=1 go run ./cmd/www-kbbi + DEBUG=1 go run ./cmd/www-kamusku diff --git a/README.adoc b/README.adoc index 80b4375..d3127b6 100644 --- a/README.adoc +++ b/README.adoc @@ -1,4 +1,4 @@ -= kbbi += kamusku Proyek sumber terbuka implementasi antar-muka perintah dan API untuk Kamus Besar Bahasa Indonesia. diff --git a/_www-kbbi/assets/github.svg b/_www-kamusku/assets/github.svg index 3899712..3899712 100644 --- a/_www-kbbi/assets/github.svg +++ b/_www-kamusku/assets/github.svg diff --git a/_www-kbbi/assets/linux.svg b/_www-kamusku/assets/linux.svg index 4c2bbed..4c2bbed 100644 --- a/_www-kbbi/assets/linux.svg +++ b/_www-kamusku/assets/linux.svg diff --git a/_www-kbbi/assets/macos.svg b/_www-kamusku/assets/macos.svg index 701ef59..701ef59 100644 --- a/_www-kbbi/assets/macos.svg +++ b/_www-kamusku/assets/macos.svg diff --git a/_www-kbbi/assets/windows.svg b/_www-kamusku/assets/windows.svg index 8995329..8995329 100644 --- a/_www-kbbi/assets/windows.svg +++ b/_www-kamusku/assets/windows.svg diff --git a/_www-kbbi/index.html b/_www-kamusku/index.html index a9a5110..a9a5110 100644 --- a/_www-kbbi/index.html +++ b/_www-kamusku/index.html diff --git a/_www-kbbi/index.js b/_www-kamusku/index.js index f5f0217..f5f0217 100644 --- a/_www-kbbi/index.js +++ b/_www-kamusku/index.js diff --git a/_www-kbbi/kbbiclient.js b/_www-kamusku/kbbiclient.js index ab35633..ab35633 100644 --- a/_www-kbbi/kbbiclient.js +++ b/_www-kamusku/kbbiclient.js diff --git a/active_client.go b/active_client.go index 0aebd0b..fed49a6 100644 --- a/active_client.go +++ b/active_client.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku // // activeClient define an interface for an active client. diff --git a/api_client.go b/api_client.go index eb1c2f7..d85f419 100644 --- a/api_client.go +++ b/api_client.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "fmt" diff --git a/api_client_test.go b/api_client_test.go index f2e9a87..a7b408a 100644 --- a/api_client_test.go +++ b/api_client_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "testing" @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "fmt" diff --git a/cmd/bot-kbbi/app.yaml b/cmd/bot-kamusku/app.yaml index 89bf31a..74fd1f5 100644 --- a/cmd/bot-kbbi/app.yaml +++ b/cmd/bot-kamusku/app.yaml @@ -1,4 +1,4 @@ -service: bot-kbbi +service: bot runtime: go113 instance_class: F2 automatic_scaling: @@ -6,4 +6,4 @@ automatic_scaling: env_variables: DEBUG: "2" TELEGRAM_TOKEN: "1121465148:AAH9vI-DkHUOPGTmy1Js0dxKSHLYIIkXaIE" - TELEGRAM_WEBHOOK_URL: "https://bot-kbbi-dot-kamuskubot.df.r.appspot.com" + TELEGRAM_WEBHOOK_URL: "https://bot-dot-kamuskubot.df.r.appspot.com" diff --git a/cmd/bot-kbbi/main.go b/cmd/bot-kamusku/main.go index 91c2552..c2f60e2 100644 --- a/cmd/bot-kbbi/main.go +++ b/cmd/bot-kamusku/main.go @@ -3,8 +3,8 @@ // license that can be found in the LICENSE file. // -// Program bot-kbbi adalah Telegram Bot yang melayani pencarian definisi kata -// menggunakan perintah pesan di Telegram. +// Program bot-kamusku adalah Telegram Bot yang melayani pencarian definisi +// kata menggunakan perintah pesan di Telegram. // package main @@ -13,14 +13,14 @@ import ( "os" "os/signal" - "github.com/shuLhan/kbbi" + "github.com/shuLhan/kamusku" ) func main() { log.SetFlags(0) // Use the token and Webhook URL from environment variables. - tgbot, err := kbbi.NewTelegramBot("", "") + tgbot, err := kamusku.NewTelegramBot("", "") if err != nil { log.Fatal(err) } diff --git a/cmd/kbbi/main.go b/cmd/kbbi/main.go index 09b3a92..984596c 100644 --- a/cmd/kbbi/main.go +++ b/cmd/kbbi/main.go @@ -14,7 +14,7 @@ import ( "log" "sort" - "github.com/shuLhan/kbbi" + "github.com/shuLhan/kamusku" ) func main() { @@ -25,6 +25,7 @@ func main() { ) log.SetFlags(0) + log.SetPrefix("kbbi") flag.StringVar(&surel, "surel", "", "Nama pengguna") flag.StringVar(&sandi, "sandi", "", "Sandi pengguna") @@ -33,7 +34,7 @@ func main() { flag.Parse() - cl, err := kbbi.NewClient() + cl, err := kamusku.NewClient() if err != nil { log.Fatal(err) } @@ -41,7 +42,7 @@ func main() { if len(surel) > 0 && len(sandi) > 0 { err = cl.Login(surel, sandi) if err != nil { - log.Fatal("kbbi: ", err) + log.Fatal(err) } } @@ -87,7 +88,7 @@ func main() { } } -func listKataDasar(cl *kbbi.Client) { +func listKataDasar(cl *kamusku.Client) { kataDasar, err := cl.ListKataDasar() if err != nil { log.Println(err) diff --git a/cmd/www-kbbi/app.yaml b/cmd/www-kamusku/app.yaml index 580f7ea..580f7ea 100644 --- a/cmd/www-kbbi/app.yaml +++ b/cmd/www-kamusku/app.yaml diff --git a/cmd/www-kbbi/main.go b/cmd/www-kamusku/main.go index 370ed16..f559594 100644 --- a/cmd/www-kbbi/main.go +++ b/cmd/www-kamusku/main.go @@ -9,11 +9,11 @@ import ( "os" "os/signal" - "github.com/shuLhan/kbbi" + "github.com/shuLhan/kamusku" ) func main() { - server, err := kbbi.NewServer("") + server, err := kamusku.NewServer("") if err != nil { log.Fatal(err) } diff --git a/daftar_kata.go b/daftar_kata.go index 1560355..6232dcd 100644 --- a/daftar_kata.go +++ b/daftar_kata.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku type DaftarKata map[string]struct{} diff --git a/definisi_kata.go b/definisi_kata.go index 8d812f8..b050c6b 100644 --- a/definisi_kata.go +++ b/definisi_kata.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "fmt" diff --git a/definisi_response.go b/definisi_response.go index 91808eb..602d0e4 100644 --- a/definisi_response.go +++ b/definisi_response.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import "encoding/json" diff --git a/direct_client.go b/direct_client.go index 5817b51..61824b1 100644 --- a/direct_client.go +++ b/direct_client.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "bytes" @@ -20,6 +20,7 @@ import ( "strings" "github.com/shuLhan/share/lib/debug" + libhttp "github.com/shuLhan/share/lib/http" "github.com/shuLhan/share/lib/net/html" "golang.org/x/net/publicsuffix" ) @@ -212,7 +213,7 @@ func (cl *directClient) login(surel, sandi string) (err error) { return fmt.Errorf("Login: %w", err) } - req.Header.Set(headerNameContentType, headerValueContentType) + req.Header.Set(libhttp.HeaderContentType, libhttp.ContentTypeForm) res, err := cl.httpc.Do(req) if err != nil { diff --git a/direct_client_test.go b/direct_client_test.go index dd3b59b..533fc78 100644 --- a/direct_client_test.go +++ b/direct_client_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "io/ioutil" diff --git a/generate.go b/generate.go index 05137b0..5176311 100644 --- a/generate.go +++ b/generate.go @@ -4,4 +4,4 @@ //go:generate go run ./internal/generate -package kbbi +package kamusku @@ -1,4 +1,4 @@ -module github.com/shuLhan/kbbi +module github.com/shuLhan/kamusku go 1.13 diff --git a/internal/cmd/mergedic/main.go b/internal/cmd/mergedic/main.go index 33e644c..7cdba38 100644 --- a/internal/cmd/mergedic/main.go +++ b/internal/cmd/mergedic/main.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // -// Program mergedic merge daftar kata from kbbi with hunspell-id dictionary. +// Program mergedic merge daftar kata from KBBI with hunspell-id dictionary. // package main diff --git a/kamus_cache.go b/kamus_cache.go index add6ccb..52eb1f4 100644 --- a/kamus_cache.go +++ b/kamus_cache.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "bytes" diff --git a/kamus_cache_test.go b/kamus_cache_test.go index 44ccb92..09a51cf 100644 --- a/kamus_cache_test.go +++ b/kamus_cache_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "testing" @@ -3,10 +3,10 @@ // license that can be found in the LICENSE file. // -// Package kbbi is Go client for Kamus Besar Bahasa Indonesia at +// Package kamusku is Go client for Kamus Besar Bahasa Indonesia at // kbbi.kemdikbud.go.id. // -package kbbi +package kamusku import "time" @@ -27,10 +27,6 @@ const ( attrValueRootWord = "rootword" - headerNameACAO = "Access-Control-Allow-Origin" - headerNameContentType = "Content-Type" - headerValueContentType = "application/x-www-form-urlencoded" - tagNameAnchor = "a" tagNameFont = "font" tagNameHeader2 = "h2" diff --git a/kbbi_test.go b/kamusku_test.go index a9250aa..9967c1c 100644 --- a/kbbi_test.go +++ b/kamusku_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "log" @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "bytes" diff --git a/kata_test.go b/kata_test.go index fa64c96..d471575 100644 --- a/kata_test.go +++ b/kata_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "io/ioutil" @@ -2,18 +2,20 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "context" "fmt" "log" + "math/rand" stdhttp "net/http" "os" "strings" "sync" "time" + "github.com/shuLhan/share/lib/ascii" "github.com/shuLhan/share/lib/debug" "github.com/shuLhan/share/lib/http" ) @@ -21,7 +23,6 @@ import ( const ( envKbbiSandi = "KBBI_SANDI" envKbbiSurel = "KBBI_SUREL" - defRootDir = "_www-kbbi" defListen = ":3394" emptyResponse = "{}" ) @@ -36,12 +37,12 @@ type Server struct { // The client that forward request to official KBBI server. forwardc *directClient + stopped chan bool + wg sync.WaitGroup + // If offline is true and the word definition is not found on cache, // the server will not forward request to official KBBI server. offline bool - - wg sync.WaitGroup - stopped chan bool } // @@ -157,13 +158,22 @@ func (server *Server) dumpCache() { } } -func (server *Server) handleDefinisi( +// +// handleAdmin is endpoint to manage dictionary cache on the web. +// +func (server *Server) handleAdmin( httpRes stdhttp.ResponseWriter, httpReq *stdhttp.Request, reqBody []byte, ) (resBody []byte, err error) { - httpRes.Header().Set(headerNameACAO, "*") + return resBody, nil +} +func (server *Server) handleDefinisi( + httpRes stdhttp.ResponseWriter, + httpReq *stdhttp.Request, + reqBody []byte, +) (resBody []byte, err error) { paramKata := httpReq.Form.Get(paramNameKata) if len(paramKata) == 0 { return []byte(emptyResponse), nil @@ -229,5 +239,30 @@ func (server *Server) registerEndpoints() (err error) { ResponseType: http.ResponseTypeJSON, Call: server.handleDefinisi, } - return server.http.RegisterEndpoint(epDefinisi) + + err = server.http.RegisterEndpoint(epDefinisi) + if err != nil { + return fmt.Errorf("registerEndpoints %q: %w", pathAPIDefinisi, + err) + } + + rand.Seed(time.Now().Unix()) + pathAdmin := string(ascii.Random([]byte(ascii.LettersNumber), 16)) + + epAdmin := &http.Endpoint{ + Method: http.RequestMethodGet, + Path: pathAdmin, + RequestType: http.RequestTypeQuery, + ResponseType: http.ResponseTypeHTML, + Call: server.handleAdmin, + } + + err = server.http.RegisterEndpoint(epAdmin) + if err != nil { + return fmt.Errorf("registerEndpoints %q: %w", pathAdmin, err) + } + + fmt.Println("administration path:", pathAdmin) + + return nil } diff --git a/telegram_bot.go b/telegram_bot.go index 71adb94..061bb4c 100644 --- a/telegram_bot.go +++ b/telegram_bot.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package kbbi +package kamusku import ( "bytes" @@ -150,6 +150,20 @@ func (tgbot *TelegramBot) sendError(msg *bot.Message, parseMode, errMsg string) } } +//nolint: unused +func (tgbot *TelegramBot) sendShutdownNotice(msg *bot.Message) { + text := `Mohon maaf, KamuskuBot untuk sementara berhenti beroperasi dulu karena masalah legalitas. + +Kami sedang memperbarui kanal kamus ke id.wiktionary.org, yang lebih terbuka +dan bebas dipakai oleh publik. +` + _, err := tgbot.SendMessage(msg, "", text) + if err != nil { + log.Printf("sendShutdownNotice: %s", err) + return + } +} + func formatText(definisiKata DefinisiResponse) string { buf := &bytes.Buffer{} for k, kata := range definisiKata { |
