-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,351 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ name: 100% Coverage | |
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
jobs: | ||
coverage: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# コントリビュート(参加)について | ||
|
||
## PullRequest 先 | ||
|
||
- `main` ブランチ | ||
- PR に慣れていない方 👉 [How To Pull Request](https://github.com/Qithub-BOT/QiiCipher/blob/master/.github/HOW_TO_PULL_REQUEST.md) | QiiCipher | Qithub @ GitHub | ||
|
||
## マージ・ルール | ||
|
||
- `squash` `merge` マージ | ||
|
||
テストおよびレビューをパスした PR は、コミットを 1 つにまとめてマージします。そのため、**コミット・ログの綺麗さは気にする必要はありません**。どんどん試行錯誤してください。 | ||
|
||
## PR 時の注意(レギュレーション) | ||
|
||
PR もしくは [Draft PR](https://github.blog/jp/2019-02-19-introducing-draft-pull-requests/) されると CI による各種テストが自動実行されます。 | ||
|
||
これらのテストをパスしないと、レビューおよびマージは行われません。 | ||
|
||
1. 構文・文法チェック(lint)と静的解析 | ||
- Golang 及びシェルスクリプトの構文テストが行われます。 | ||
- `shfmt` ........... シェル・スクリプトの構文チェック | ||
- `shellcheck` ...... シェル・スクリプトの静的解析 | ||
- `gofmt` ........... Golang の構文チェック | ||
- `golangci-lint` ... Golang の静的解析チェック | ||
2. ユニット・テスト | ||
- `go test ./src/...` によるユニット・テストが行われます。`./.github/run-tests-coverage.sh` でもテストできます。 | ||
3. カバレッジ・テスト | ||
- 各々のパッケージ(ディレクトリ)にテストが 1 つでも設置されていた場合、カバレッジが 100% にならないとパスしません。 | ||
- 未カバーの箇所を確認したい場合は ``./.github/run-tests-coverage.sh --verbose` で確認できます。 | ||
4. ドキュメントの更新チェック | ||
- 各パッケージ(ディレクトリ)にある README.md は [gomarkdoc](https://github.com/princjef/gomarkdoc) で自動作成されたドキュメントです。 | ||
- CI では変更がドキュメントに反映されているかのテストが行われます。`./.github/update-docs.sh` で更新してください。(要 gomarkdoc) | ||
|
||
これらの確認や開発に必要な環境の Dockerfile を [./.devcontainer](.devcontainer) に用意しています。ご活用ください。 | ||
|
||
## なんかわけわかめ | ||
|
||
- 遠慮なく [Discussions](https://github.com/Qithub-BOT/QiiTrans/discussions) の Q&A で聞いてください。 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
<!-- Code generated by gomarkdoc. DO NOT EDIT --> | ||
|
||
# cache | ||
|
||
```go | ||
import "github.com/Qithub-BOT/QiiTrans/src/cache" | ||
``` | ||
|
||
Package cache は key\-value 型の簡易 DB です\. | ||
|
||
New\(\) でインスタンスが作成されると、テンポラリ・ディレクトリにキャッシュ用のディレクトリを作成します。 主に "Set\(\<翻訳前テキスト\>\, \<翻訳後テキスト\>\)" のように、翻訳結果をキャッシュするのに使われます。 デフォルトで共通のキャッシュ・ディレクトリを利用します。異なるキャッシュにしたい場合は任意のキャッシュ ID を指定します。 | ||
|
||
``` | ||
myCache := cache.New("myCache") | ||
``` | ||
|
||
主なメソッド | ||
|
||
``` | ||
Set(key, value) ... キャッシュの作成・更新をします | ||
Get(key) ... キャッシュから値を取得します。 | ||
ClearAll() ... キャッシュ・ディレクトリを削除します。 | ||
``` | ||
|
||
## Index | ||
|
||
- [Constants](<#constants>) | ||
- [type TCache](<#type-tcache>) | ||
- [func New(cacheID ...string) *TCache](<#func-new>) | ||
- [func (c *TCache) ClearAll()](<#func-tcache-clearall>) | ||
- [func (c *TCache) CloseDB()](<#func-tcache-closedb>) | ||
- [func (c *TCache) Get(key string) (string, error)](<#func-tcache-get>) | ||
- [func (c *TCache) GetPathDirCache() string](<#func-tcache-getpathdircache>) | ||
- [func (c *TCache) GetValueInByte(keyHashed []byte) ([]byte, error)](<#func-tcache-getvalueinbyte>) | ||
- [func (c *TCache) OpenDB() (err error)](<#func-tcache-opendb>) | ||
- [func (c *TCache) Set(key string, value string) (err error)](<#func-tcache-set>) | ||
- [func (c *TCache) hash64(content string) []byte](<#func-tcache-hash64>) | ||
|
||
|
||
## Constants | ||
|
||
```go | ||
const ( | ||
NameDirCacheDefault = "QiiTrans" | ||
) | ||
``` | ||
|
||
## type [TCache](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.go#L9-L13>) | ||
|
||
```go | ||
type TCache struct { | ||
cacheDB *badger.DB | ||
NameDirCache string | ||
PathDirTemp string | ||
} | ||
``` | ||
|
||
### func [New](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/New.go#L10>) | ||
|
||
```go | ||
func New(cacheID ...string) *TCache | ||
``` | ||
|
||
New は TCache の新規オブジェクトのポインタを返します\. デフォルトで共通のキャッシュを利用します。各々異なるキャッシュにしたい場合は、引数に ID を指定します\. | ||
|
||
<details><summary>Example</summary> | ||
<p> | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Qithub-BOT/QiiTrans/src/cache" | ||
) | ||
|
||
func main() { | ||
// 汎用のキャッシュにしたくない場合は ID を指定する。この場合は "my sample DB". | ||
c := cache.New("my sample DB") | ||
|
||
// 終了時にキャッシュを削除したい場合は defer で ClearAll する | ||
defer c.ClearAll() | ||
|
||
phraseOriginal := "Hello, world!" | ||
phraseTranslated := "世界よ、こんにちは!" | ||
|
||
// Set でキャッシュに登録 | ||
_ = c.Set(phraseOriginal, phraseTranslated) | ||
|
||
// Get でキャッシュから取得 | ||
result, _ := c.Get(phraseOriginal) | ||
|
||
fmt.Println(result) | ||
} | ||
``` | ||
|
||
#### Output | ||
|
||
``` | ||
世界よ、こんにちは! | ||
``` | ||
|
||
</p> | ||
</details> | ||
|
||
### func \(\*TCache\) [ClearAll](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.ClearAll.go#L10>) | ||
|
||
```go | ||
func (c *TCache) ClearAll() | ||
``` | ||
|
||
ClearAll はキャッシュ・データを削除します\. | ||
|
||
### func \(\*TCache\) [CloseDB](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.CloseDB.go#L7>) | ||
|
||
```go | ||
func (c *TCache) CloseDB() | ||
``` | ||
|
||
### func \(\*TCache\) [Get](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.Get.go#L5>) | ||
|
||
```go | ||
func (c *TCache) Get(key string) (string, error) | ||
``` | ||
|
||
Get はキャッシュから key を探索し、その値を文字列で返します\. キャッシュに key がない場合はエラーを返します\. | ||
|
||
### func \(\*TCache\) [GetPathDirCache](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.GetPathDirCache.go#L6>) | ||
|
||
```go | ||
func (c *TCache) GetPathDirCache() string | ||
``` | ||
|
||
GetPathDirCache は現在のキャッシュ先のディレクトリを返します\. | ||
|
||
### func \(\*TCache\) [GetValueInByte](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.GetValueInByte.go#L6>) | ||
|
||
```go | ||
func (c *TCache) GetValueInByte(keyHashed []byte) ([]byte, error) | ||
``` | ||
|
||
GetValueInByte はバイトデータにハッシュ化された keyHashed キーを使ってキャッシュを探索しバイトデータで返します\. | ||
|
||
### func \(\*TCache\) [OpenDB](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.OpenDB.go#L8>) | ||
|
||
```go | ||
func (c *TCache) OpenDB() (err error) | ||
``` | ||
|
||
### func \(\*TCache\) [Set](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.Set.go#L11>) | ||
|
||
```go | ||
func (c *TCache) Set(key string, value string) (err error) | ||
``` | ||
|
||
Set は value の値を key に割り当ててキャッシュします\. | ||
|
||
引数 key は、内部で 64 バイトの固定長にハッシュ化されるため、長さに依存しません\. この関数は、主に翻訳前の文と、翻訳後の文のキャッシュに使われます\. 呼び出しごとにキャッシュ DB を open/close するため、大量の連続呼び出しには向きません\. 大量に登録する場合は SetList\(\) 関数を利用してください\. | ||
|
||
### func \(\*TCache\) [hash64](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.hash64.go#L6>) | ||
|
||
```go | ||
func (c *TCache) hash64(content string) []byte | ||
``` | ||
|
||
hash64 は content の内容を 64 バイトのハッシュ値に変換します\. | ||
|
||
------ | ||
|
||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!-- Code generated by gomarkdoc. DO NOT EDIT --> | ||
|
||
# deepleng | ||
|
||
```go | ||
import "github.com/Qithub-BOT/QiiTrans/src/engines/deepleng" | ||
``` | ||
|
||
Package deepleng は DeepL の翻訳 API を使った翻訳エンジンです\. | ||
|
||
このエンジンを利用するには、DeepL PRO の無料/有料アカウントから発行したアクセス・トークン(認証キー/API キー)が必要です。 | ||
|
||
\- アカウント登録後のアクセス・トークン確認先: https://www.deepl.com/pro-account/plan (認証キー) | ||
|
||
## Index | ||
|
||
- [Constants](<#constants>) | ||
- [func GetInfoAPI(p *engine.Properties) (engine.AccountInfo, error)](<#func-getinfoapi>) | ||
- [func GetURLBaseAPI(p *engine.Properties) string](<#func-geturlbaseapi>) | ||
- [func IsAPIKeyFree(apikey string) bool](<#func-isapikeyfree>) | ||
- [func New(cacheID ...string) *engine.Properties](<#func-new>) | ||
- [func Translate(p *engine.Properties, inText string, langFrom string, langTo string) (result string, err error)](<#func-translate>) | ||
|
||
|
||
## Constants | ||
|
||
```go | ||
const NameVarEnvAPIKey = "DEEPL_API_KEY" | ||
``` | ||
|
||
## func [GetInfoAPI](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/engines/deepleng/GetInfoAPI.go#L13>) | ||
|
||
```go | ||
func GetInfoAPI(p *engine.Properties) (engine.AccountInfo, error) | ||
``` | ||
|
||
GetInfoAPI はアクセス・トークンのアカウント情報のうち、engine\.AccountInfo に必要なものだけセットして返します\. | ||
|
||
## func [GetURLBaseAPI](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/engines/deepleng/GetURLBaseAPI.go#L5>) | ||
|
||
```go | ||
func GetURLBaseAPI(p *engine.Properties) string | ||
``` | ||
|
||
## func [IsAPIKeyFree](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/engines/deepleng/IsAPIKeyFree.go#L6>) | ||
|
||
```go | ||
func IsAPIKeyFree(apikey string) bool | ||
``` | ||
|
||
IsAPIKeyFree は apikey が無料枠のアクセストークンか返します\. | ||
|
||
## func [New](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/engines/deepleng/New.go#L8>) | ||
|
||
```go | ||
func New(cacheID ...string) *engine.Properties | ||
``` | ||
|
||
New は翻訳エンジン(DeepL)の新規インスタンスのポインタを返します\. | ||
|
||
## func [Translate](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/engines/deepleng/Translate.go#L15>) | ||
|
||
```go | ||
func Translate(p *engine.Properties, inText string, langFrom string, langTo string) (result string, err error) | ||
``` | ||
|
||
Translate は inText を langFrom から langTo に DeepL の翻訳 API を使って翻訳した結果を返します\. | ||
|
||
この関数は結果をキャッシュしません。別途、呼び出し元でキャッシュを行ってください\. | ||
|
||
------ | ||
|
||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.