{"id":29460421,"url":"https://github.com/kittychen913/golangrestapi","last_synced_at":"2025-07-14T02:04:15.943Z","repository":{"id":282696494,"uuid":"947134020","full_name":"KittyChen913/GolangRestAPI","owner":"KittyChen913","description":"A sample project demonstrating how to build a RESTful API using Go, integrated with MS SQL and the ELK Stack (Filebeat, Elasticsearch, Kibana) for centralized log management.","archived":false,"fork":false,"pushed_at":"2025-07-11T18:14:41.000Z","size":182,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-11T19:12:29.435Z","etag":null,"topics":["docker-compose","elasticsearch","filebeat","go","kibana","mssql-database"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KittyChen913.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-12T07:56:20.000Z","updated_at":"2025-07-11T18:14:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"69122c5c-fcba-453f-bc61-60f199ec38a5","html_url":"https://github.com/KittyChen913/GolangRestAPI","commit_stats":null,"previous_names":["kittychen913/golangrestapi"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KittyChen913/GolangRestAPI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KittyChen913%2FGolangRestAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KittyChen913%2FGolangRestAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KittyChen913%2FGolangRestAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KittyChen913%2FGolangRestAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KittyChen913","download_url":"https://codeload.github.com/KittyChen913/GolangRestAPI/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KittyChen913%2FGolangRestAPI/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265233505,"owners_count":23731800,"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","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":["docker-compose","elasticsearch","filebeat","go","kibana","mssql-database"],"created_at":"2025-07-14T02:02:07.371Z","updated_at":"2025-07-14T02:04:15.934Z","avatar_url":"https://github.com/KittyChen913.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang REST API + ELK 日誌系統\n\n這是一個展示如何使用 Go 語言建立 RESTful API，整合 Microsoft SQL Server 資料庫以及 ELK Stack (Filebeat, Elasticsearch, Kibana) 進行集中式日誌管理的範例專案。\n\n所有服務都透過 Docker Compose 管理，方便快速啟動環境。\n\n## 系統架構\n\n應用程式由以下服務組成：\n\n*   **`api-service`**: 核心的 REST API，使用 Go 語言編寫，Log 處理採用具備高效能、支援結構化輸出的 [zap](https://github.com/uber-go/zap) 日誌框架。\n*   **`mssql-db`**: Microsoft SQL Server 2022 資料庫。\n*   **`filebeat`**: 一個輕量級的日誌收集器，收集日誌並轉發到 Elasticsearch。\n*   **`elasticsearch`**: 一個搜尋與分析引擎，用於儲存和索引日誌，此專案用於接收 filebeat 傳過來的日誌內容。\n*   **`kibana`**: 一個資料視覺化工具，用於查詢和檢視儲存在 Elasticsearch 中的日誌。\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"images/GolangRestAPI%20Architecture%20Diagram.png\" alt=\"架構圖\" width=\"75%\"\u003e\n\u003c/p\u003e\n\n## 環境需求\n\n-   Docker\n-   Docker Compose (通常會跟 Docker 一起安裝)\n\n## 快速開始\n\n### 1. 啟動所有服務\n\n```sh\ndocker-compose up --build\n```\n\n### 2. 服務說明\n\n服務啟動後，您可以透過以下位址存取：\n\n-   **API 服務**: [http://localhost:8080](http://localhost:8080)\n-   **Swagger 文件**: [http://localhost:8080/swagger/index.html](http://localhost:8080/swagger/index.html)\n-   **elasticsearch**: [http://localhost:9200](http://localhost:9200)\n    -   可訪問 [http://localhost:9200/_cat/indices?v](http://localhost:9200/_cat/indices?v) 查看目前有哪些索引\n    -   API 服務被訪問後，filebeat 會自動傳遞 `filebeat-datastream-*` index 過來\n-   **Kibana (日誌儀表板)**: [http://localhost:5601](http://localhost:5601)\n    -   開啟後，點擊左側選單的 \"Discover\"，您應該能看到由 `api-service` 產生的日誌。\n    -   點選左側選單的 \"Stack Management\" \u003e \"Index Management\"，勾選 \"Include hidden indices\" 即可看到 `.ds-filebeat-datastream-9.0.3-*`，不用自己手動 Create Index\n-   **資料庫連線**:\n    -   **工具**: SQL Server Management Studio\n    -   **主機**: `localhost`\n    -   **Port**: `1433`\n    -   **使用者**: `SA`\n    -   **密碼**: `StrongPassword!123`\n\n## 組態設定\n\n`docker-compose.yml`定義所有服務的啟動方式、相依性、資料卷。\n\n### 環境變數\n\n*   **`api-service`**:\n    *   `DemoDb`: 連接到 MS SQL 資料庫的連線字串。\n*   **`mssql-db`**:\n    *   `SA_PASSWORD`: `SA` 使用者的密碼。\n\n### 資料庫初始化\n\n當 `mssql-db` 服務首次啟動時，會自動執行 `initDb/init.sql` 指令碼，這裡會執行建立資料表 (`CREATE TABLE`) 的 SQL 命令。\n\n### 日誌收集\n\n日誌收集的設定位於 `filebeat/filebeat.yml`，filebeat 會監控 `log-data` 磁碟區中的日誌檔案，該磁碟區與 `api-service` 共享。\n\n## 目錄結構\n\n```\n├── api-service/          # Golang API\n│   ├── customerrors      # 自定義錯誤\n│   ├── db/               # 資料庫連線與操作\n│   ├── docs/             # Swagger 文件\n│   ├── logger/           # 日誌工具\n│   ├── middlewares/      # Gin 中介層\n│   ├── models/           # 資料模型\n│   ├── routes/           # API 路由\n│   ├── utils/            # 工具\n│   ├── Dockerfile        # Docker 構建檔案\n│   └── main.go\n├── filebeat/filebeat.yml # Filebeat 設定\n├── initDb/init.sql       # SQL Server 初始化腳本\n├── docker-compose.yml    # Docker Compose 配置\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkittychen913%2Fgolangrestapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkittychen913%2Fgolangrestapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkittychen913%2Fgolangrestapi/lists"}