{"id":31922021,"url":"https://github.com/dev-shimada/gostubby","last_synced_at":"2025-10-13T22:56:25.388Z","repository":{"id":287814751,"uuid":"965875524","full_name":"dev-shimada/GoStubby","owner":"dev-shimada","description":"A flexible and powerful mock server.","archived":false,"fork":false,"pushed_at":"2025-06-19T03:35:33.000Z","size":117,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-19T04:29:57.653Z","etag":null,"topics":["go","mocking","rest","stubbing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dev-shimada.png","metadata":{"files":{"readme":"README.ja.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"docs/security/ssl-tls.ja.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-14T03:47:24.000Z","updated_at":"2025-06-19T03:35:07.000Z","dependencies_parsed_at":"2025-05-23T12:32:48.269Z","dependency_job_id":"5c4b1f5c-c39e-4c83-95d4-37a715d0a755","html_url":"https://github.com/dev-shimada/GoStubby","commit_stats":null,"previous_names":["dev-shimada/gostubby"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/dev-shimada/GoStubby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-shimada%2FGoStubby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-shimada%2FGoStubby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-shimada%2FGoStubby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-shimada%2FGoStubby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dev-shimada","download_url":"https://codeload.github.com/dev-shimada/GoStubby/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-shimada%2FGoStubby/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017081,"owners_count":26085984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","mocking","rest","stubbing"],"created_at":"2025-10-13T22:56:06.775Z","updated_at":"2025-10-13T22:56:25.381Z","avatar_url":"https://github.com/dev-shimada.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoStubby\n[![Go Report Card](https://goreportcard.com/badge/github.com/dev-shimada/GoStubby)](https://goreportcard.com/report/github.com/dev-shimada/GoStubby)\n[![Coverage Status](https://coveralls.io/repos/github/dev-shimada/GoStubby/badge.svg?branch=main)](https://coveralls.io/github/dev-shimada/GoStubby?branch=main)\n[![CI](https://github.com/dev-shimada/GoStubby/actions/workflows/CI.yaml/badge.svg)](https://github.com/dev-shimada/GoStubby/actions/workflows/CI.yaml)\n[![build](https://github.com/dev-shimada/GoStubby/actions/workflows/build-docker-image.yaml/badge.svg)](https://github.com/dev-shimada/GoStubby/actions/workflows/build-docker-image.yaml)\n[![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/dev-shimada/GoStubby/blob/master/LICENSE)\n\n柔軟で強力なGoによるモックサーバーの実装です。高度なリクエストマッチング機能とテンプレート化されたレスポンスを使用してモックエンドポイントを定義することができます。\n\n## 特徴\n\n- **柔軟なリクエストマッチング**:\n  - テンプレートを使用したURLパスマッチング（例：`/users/{id}`）\n  - 正規表現パターンマッチング\n  - クエリパラメータのバリデーション\n  - リクエストボディのバリデーション\n  - 複数のマッチングパターン：`equalTo`、`matches`、`doesNotMatch`、`contains`、`doesNotContain`\n\n- **強力なレスポンス処理**:\n  - リクエストパラメータにアクセス可能なテンプレートベースのレスポンスボディ\n  - ファイルベースのレスポンスボディ\n  - カスタムHTTPステータスコード\n  - カスタムレスポンスヘッダー\n\n## インストール\n\n```bash\ngo get github.com/dev-shimada/gostubby\n```\n\n## 使用方法\n\n1. `./configs/config.json`に設定ファイルを作成：\n\n```json\n[\n  {\n    \"request\": {\n      \"urlPathTemplate\": \"/users/{id}\",\n      \"method\": \"GET\",\n      \"pathParameters\": {\n        \"id\": {\n          \"matches\": \"^[0-9]+$\"\n        }\n      }\n    },\n    \"response\": {\n      \"status\": 200,\n      \"body\": \"{\\\"id\\\": \\\"{{.Path.id}}\\\", \\\"name\\\": \\\"User {{.Path.id}}\\\"}\"\n    }\n  }\n]\n```\n\n2. サーバーを起動：\n\n```bash\n# デフォルトポート（8080）とデフォルト設定ディレクトリで起動\ngo run main.go\n\n# 短いオプション（-p）でポートを指定\ngo run main.go -p 3000\n\n# 長いオプション（--port）でポートを指定\ngo run main.go --port 3000\n\n# 短いオプション（-c）で設定ファイルのパスを指定\ngo run main.go -c ./path/to/config.json\n\n# 長いオプション（--config）で設定ディレクトリを指定\ngo run main.go --config ./path/to/configs\n```\n\nサーバーは以下のコマンドラインオプションをサポートしています：\n\nHTTP設定：\n- ポート番号: `-p` または `--port`（デフォルト: 8080）\n\nHTTPS設定：\n- HTTPSポート番号: `-s` または `--https-port`（デフォルト: 8443）\n- SSL/TLS証明書: `-t` または `--cert`（SSL/TLS証明書ファイルへのパス）\n- SSL/TLS秘密鍵: `-k` または `--key`（SSL/TLS秘密鍵ファイルへのパス）\n\n一般設定：\n- 設定ファイル: `-c` または `--config`（デフォルト: \"./configs\"）\n\n設定ファイルは、単一のJSONファイルまたは複数のJSONファイルを含むディレクトリのいずれかを指定できます。ディレクトリを指定した場合、そのディレクトリ内のすべてのJSONファイルが読み込まれます。\n\n### SSL/TLSサポート\n\nSSL/TLS証明書を提供することで、サーバーをHTTPSモードで実行できます。HTTPとHTTPSを同時に有効にして実行することも可能です。\n\nHTTPSを有効にするには：\n1. SSL/TLS証明書と秘密鍵ファイルを用意\n2. 証明書と鍵ファイルのパスを指定してサーバーを起動：\n\n```bash\n# HTTPとHTTPSの両方で実行\ngo run main.go --cert ./certs/server.crt --key ./certs/server.key\n\n# HTTPとHTTPSのポートをカスタマイズ\ngo run main.go --port 8080 --https-port 8443 --cert ./certs/server.crt --key ./certs/server.key\n```\n\n開発やテスト用に自己署名証明書を生成する場合：\n```bash\n# 秘密鍵と自己署名証明書の生成\nopenssl req -x509 -nodes -days 365 -newkey rsa:2048 \\\n  -keyout ./certs/server.key -out ./certs/server.crt\n```\n\n注意：セキュリティのため、TLS 1.2以上のバージョンを強制しています。\n\n## 設定フォーマット\n\n### リクエストマッチング\n\n```json\n{\n  \"request\": {\n    \"urlPathTemplate\": \"/example/{param}\",  // パスパラメータを含むURLテンプレート\n    \"method\": \"GET\",                        // HTTPメソッド\n    \"pathParameters\": {                     // パスパラメータのバリデーションルール\n      \"param\": {\n        \"equalTo\": \"value\",                 // 完全一致\n        \"matches\": \"^[0-9]+$\",             // 正規表現パターンマッチ\n        \"doesNotMatch\": \"[a-z]+\",          // 否定的な正規表現パターンマッチ\n        \"contains\": \"substring\",            // 文字列を含む\n        \"doesNotContain\": \"substring\"       // 文字列を含まない\n      }\n    },\n    \"queryParameters\": {                    // クエリパラメータのバリデーション\n      \"param\": {\n        // パスパラメータと同じマッチングルール\n      }\n    },\n    \"body\": {                              // リクエストボディのバリデーション\n      // パラメータと同じマッチングルール\n    }\n  }\n}\n```\n\n### レスポンス設定\n\n```json\n{\n  \"response\": {\n    \"status\": 200,                         // HTTPステータスコード\n    \"body\": \"Response content\",            // 直接のレスポンス内容\n    \"bodyFileName\": \"response.json\",       // または、ファイルベースのレスポンス\n    \"headers\": {                           // カスタムレスポンスヘッダー\n      \"Content-Type\": \"application/json\"\n    }\n  }\n}\n```\n\n### テンプレート変数\n\nレスポンスボディ内で以下のテンプレート変数を使用できます：\n- パスパラメータ：`{{.Path.paramName}}`\n- クエリパラメータ：`{{.Query.paramName}}`\n\n## 設定例\n\n1. パスパラメータを持つ基本的なエンドポイント：\n```json\n{\n  \"request\": {\n    \"urlPathTemplate\": \"/users/{id}\",\n    \"method\": \"GET\",\n    \"pathParameters\": {\n      \"id\": {\n        \"matches\": \"^[0-9]+$\"\n      }\n    }\n  },\n  \"response\": {\n    \"status\": 200,\n    \"body\": \"{\\\"id\\\": \\\"{{.Path.id}}\\\", \\\"name\\\": \\\"User {{.Path.id}}\\\"}\"\n  }\n}\n```\n\n2. ファイルベースのレスポンスを持つエンドポイント：\n```json\n{\n  \"request\": {\n    \"urlPathTemplate\": \"/data/{type}\",\n    \"method\": \"GET\"\n  },\n  \"response\": {\n    \"status\": 200,\n    \"bodyFileName\": \"responses/data.json\"\n  }\n}\n```\n\n## ライセンス\n\nこのプロジェクトはMITライセンスの下で公開されています - 詳細は[LICENSE](LICENSE)ファイルを参照してください。\n\n*他の言語で読む: [English](README.md)*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-shimada%2Fgostubby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdev-shimada%2Fgostubby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-shimada%2Fgostubby/lists"}