biucingcli 0.9.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- biucingcli/__init__.py +5 -0
- biucingcli/cli.py +849 -0
- biucingcli/template_data/android/template/.editorconfig +9 -0
- biucingcli/template_data/android/template/.gitignore +26 -0
- biucingcli/template_data/android/template/.mise.toml +3 -0
- biucingcli/template_data/android/template/Brewfile +6 -0
- biucingcli/template_data/android/template/Makefile +103 -0
- biucingcli/template_data/android/template/README.md +163 -0
- biucingcli/template_data/android/template/app/build.gradle.kts +178 -0
- biucingcli/template_data/android/template/app/proguard-rules.pro +1 -0
- biucingcli/template_data/android/template/app/src/androidTest/java/app/HomeRouteUiTest.kt +21 -0
- biucingcli/template_data/android/template/app/src/main/AndroidManifest.xml +18 -0
- biucingcli/template_data/android/template/app/src/main/java/app/MainActivity.kt +36 -0
- biucingcli/template_data/android/template/app/src/main/res/values/strings.xml +4 -0
- biucingcli/template_data/android/template/app/src/main/res/values/themes.xml +8 -0
- biucingcli/template_data/android/template/app/src/test/java/app/AppSmokeTest.kt +19 -0
- biucingcli/template_data/android/template/build.gradle.kts +27 -0
- biucingcli/template_data/android/template/core/designsystem/build.gradle.kts +33 -0
- biucingcli/template_data/android/template/core/designsystem/src/main/java/designsystem/Components.kt +75 -0
- biucingcli/template_data/android/template/core/designsystem/src/main/java/designsystem/DesignTokens.kt +23 -0
- biucingcli/template_data/android/template/core/designsystem/src/main/java/designsystem/Theme.kt +110 -0
- biucingcli/template_data/android/template/core/model/build.gradle.kts +26 -0
- biucingcli/template_data/android/template/core/model/src/main/java/model/Greeting.kt +6 -0
- biucingcli/template_data/android/template/core/model/src/test/java/model/GreetingTest.kt +16 -0
- biucingcli/template_data/android/template/core/network/build.gradle.kts +26 -0
- biucingcli/template_data/android/template/core/network/src/main/java/network/AppEnvironment.kt +17 -0
- biucingcli/template_data/android/template/core/testing/build.gradle.kts +27 -0
- biucingcli/template_data/android/template/core/testing/src/main/java/testing/FakeAppEnvironmentProvider.kt +13 -0
- biucingcli/template_data/android/template/docs/release-delivery.md +68 -0
- biucingcli/template_data/android/template/docs/release-signing.properties.example +20 -0
- biucingcli/template_data/android/template/fastlane/.env.example +22 -0
- biucingcli/template_data/android/template/fastlane/Appfile +1 -0
- biucingcli/template_data/android/template/fastlane/Fastfile +121 -0
- biucingcli/template_data/android/template/feature/home/build.gradle.kts +35 -0
- biucingcli/template_data/android/template/feature/home/src/main/java/home/HomeRoute.kt +38 -0
- biucingcli/template_data/android/template/feature/settings/build.gradle.kts +34 -0
- biucingcli/template_data/android/template/feature/settings/src/main/java/settings/SettingsRoute.kt +35 -0
- biucingcli/template_data/android/template/gradle/libs.versions.toml +35 -0
- biucingcli/template_data/android/template/gradle/verification-metadata.xml +3462 -0
- biucingcli/template_data/android/template/gradle/wrapper/gradle-wrapper.jar +0 -0
- biucingcli/template_data/android/template/gradle/wrapper/gradle-wrapper.jar.sha256 +1 -0
- biucingcli/template_data/android/template/gradle/wrapper/gradle-wrapper.properties +10 -0
- biucingcli/template_data/android/template/gradle.properties +4 -0
- biucingcli/template_data/android/template/gradlew +252 -0
- biucingcli/template_data/android/template/gradlew.bat +94 -0
- biucingcli/template_data/android/template/scripts/artifact-info +11 -0
- biucingcli/template_data/android/template/scripts/bootstrap +17 -0
- biucingcli/template_data/android/template/scripts/doctor +133 -0
- biucingcli/template_data/android/template/scripts/setup-android-sdk +23 -0
- biucingcli/template_data/android/template/scripts/sync-gradle-wrapper +19 -0
- biucingcli/template_data/android/template/scripts/verify-gradle-supply-chain +61 -0
- biucingcli/template_data/android/template/scripts/verify-release-artifact +104 -0
- biucingcli/template_data/android/template/settings.gradle.kts +25 -0
- biucingcli/template_data/android/template.json +146 -0
- biucingcli/template_data/apple/template/.gitignore +28 -0
- biucingcli/template_data/apple/template/.mise.toml +4 -0
- biucingcli/template_data/apple/template/.swiftformat +10 -0
- biucingcli/template_data/apple/template/.swiftlint.yml +33 -0
- biucingcli/template_data/apple/template/App/Config/ProjectDescriptionHelpers/Module.swift +6 -0
- biucingcli/template_data/apple/template/App/Config/XCConfig/Base.xcconfig +4 -0
- biucingcli/template_data/apple/template/App/Project.swift +66 -0
- biucingcli/template_data/apple/template/App/Targets/App/Resources/.gitkeep +1 -0
- biucingcli/template_data/apple/template/App/Targets/App/Sources/AppEntry.swift +9 -0
- biucingcli/template_data/apple/template/App/Targets/App/Sources/HomeView.swift +18 -0
- biucingcli/template_data/apple/template/App/Targets/App/Sources/HomeViewModel.swift +38 -0
- biucingcli/template_data/apple/template/App/Targets/AppTests/Sources/AppTests.swift +59 -0
- biucingcli/template_data/apple/template/Brewfile +8 -0
- biucingcli/template_data/apple/template/Makefile +128 -0
- biucingcli/template_data/apple/template/Packages/AppServices/Package.swift +20 -0
- biucingcli/template_data/apple/template/Packages/AppServices/Sources/AppServices/StarterMetadata.swift +52 -0
- biucingcli/template_data/apple/template/Packages/DesignSystem/Package.swift +20 -0
- biucingcli/template_data/apple/template/Packages/DesignSystem/Sources/DesignSystem/Theme.swift +8 -0
- biucingcli/template_data/apple/template/README.md +133 -0
- biucingcli/template_data/apple/template/Tuist.swift +8 -0
- biucingcli/template_data/apple/template/Workspace.swift +11 -0
- biucingcli/template_data/apple/template/docs/release-delivery.md +55 -0
- biucingcli/template_data/apple/template/fastlane/.env.example +20 -0
- biucingcli/template_data/apple/template/fastlane/Appfile +3 -0
- biucingcli/template_data/apple/template/fastlane/Fastfile +126 -0
- biucingcli/template_data/apple/template/fastlane/Matchfile +7 -0
- biucingcli/template_data/apple/template/scripts/bootstrap +9 -0
- biucingcli/template_data/apple/template/scripts/doctor +163 -0
- biucingcli/template_data/apple/template/scripts/setup-xcode +6 -0
- biucingcli/template_data/apple/template/scripts/test-destination +42 -0
- biucingcli/template_data/apple/template/scripts/verify-release-identity +88 -0
- biucingcli/template_data/apple/template.json +110 -0
- biucingcli/template_data/frontend/template/.dockerignore +8 -0
- biucingcli/template_data/frontend/template/.env.example +1 -0
- biucingcli/template_data/frontend/template/.gitignore +7 -0
- biucingcli/template_data/frontend/template/.npmrc +1 -0
- biucingcli/template_data/frontend/template/.prettierignore +2 -0
- biucingcli/template_data/frontend/template/.prettierrc.json +4 -0
- biucingcli/template_data/frontend/template/Dockerfile +25 -0
- biucingcli/template_data/frontend/template/Dockerfile.dev +35 -0
- biucingcli/template_data/frontend/template/Dockerfile.dev.full +40 -0
- biucingcli/template_data/frontend/template/Makefile +137 -0
- biucingcli/template_data/frontend/template/README.md +146 -0
- biucingcli/template_data/frontend/template/compose.dev.yaml +29 -0
- biucingcli/template_data/frontend/template/eslint.config.js +27 -0
- biucingcli/template_data/frontend/template/index.html +12 -0
- biucingcli/template_data/frontend/template/nginx.conf +11 -0
- biucingcli/template_data/frontend/template/package.json +50 -0
- biucingcli/template_data/frontend/template/playwright.production.config.ts +21 -0
- biucingcli/template_data/frontend/template/playwright.smoke.config.ts +19 -0
- biucingcli/template_data/frontend/template/pnpm-lock.yaml +4054 -0
- biucingcli/template_data/frontend/template/public/.gitkeep +1 -0
- biucingcli/template_data/frontend/template/scripts/browser-smoke-production +55 -0
- biucingcli/template_data/frontend/template/scripts/doctor +46 -0
- biucingcli/template_data/frontend/template/src/App.test.tsx +18 -0
- biucingcli/template_data/frontend/template/src/App.tsx +5 -0
- biucingcli/template_data/frontend/template/src/components/MetricCard.tsx +14 -0
- biucingcli/template_data/frontend/template/src/components/TaskPanel.tsx +32 -0
- biucingcli/template_data/frontend/template/src/config/env.ts +3 -0
- biucingcli/template_data/frontend/template/src/hooks/useProjectOverview.ts +24 -0
- biucingcli/template_data/frontend/template/src/index.css +208 -0
- biucingcli/template_data/frontend/template/src/main.tsx +11 -0
- biucingcli/template_data/frontend/template/src/pages/HomePage.tsx +60 -0
- biucingcli/template_data/frontend/template/src/router/AppRouter.tsx +14 -0
- biucingcli/template_data/frontend/template/src/services/api/client.ts +33 -0
- biucingcli/template_data/frontend/template/src/services/projectOverview.ts +39 -0
- biucingcli/template_data/frontend/template/src/test/setup.ts +1 -0
- biucingcli/template_data/frontend/template/src/types/projectOverview.ts +22 -0
- biucingcli/template_data/frontend/template/src/vite-env.d.ts +9 -0
- biucingcli/template_data/frontend/template/tests/browser-smoke.spec.ts +16 -0
- biucingcli/template_data/frontend/template/tests/production-browser-smoke.spec.ts +22 -0
- biucingcli/template_data/frontend/template/tsconfig.json +21 -0
- biucingcli/template_data/frontend/template/vite.config.ts +12 -0
- biucingcli/template_data/frontend/template.json +81 -0
- biucingcli/template_data/harmonyos/template/.gitignore +21 -0
- biucingcli/template_data/harmonyos/template/.mise.toml +2 -0
- biucingcli/template_data/harmonyos/template/AppScope/app.json5 +10 -0
- biucingcli/template_data/harmonyos/template/AppScope/resources/base/element/string.json +8 -0
- biucingcli/template_data/harmonyos/template/AppScope/resources/base/media/background.svg +3 -0
- biucingcli/template_data/harmonyos/template/AppScope/resources/base/media/foreground.svg +4 -0
- biucingcli/template_data/harmonyos/template/AppScope/resources/base/media/layered_image.json +6 -0
- biucingcli/template_data/harmonyos/template/Makefile +106 -0
- biucingcli/template_data/harmonyos/template/README.md +152 -0
- biucingcli/template_data/harmonyos/template/build-profile.json5 +36 -0
- biucingcli/template_data/harmonyos/template/code-linter.json5 +12 -0
- biucingcli/template_data/harmonyos/template/docs/release-signing.local.properties.example +14 -0
- biucingcli/template_data/harmonyos/template/entry/build-profile.json5 +9 -0
- biucingcli/template_data/harmonyos/template/entry/hvigorfile.ts +6 -0
- biucingcli/template_data/harmonyos/template/entry/oh-package.json5 +9 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/ets/core/config/AppConfig.ets +10 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/ets/core/designsystem/Tokens.ets +28 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/ets/entryability/EntryAbility.ets +29 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/ets/pages/Index.ets +47 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/ets/pages/Settings.ets +96 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/module.json5 +34 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/resources/base/element/color.json +24 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/resources/base/element/string.json +12 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/resources/base/media/app_icon.svg +5 -0
- biucingcli/template_data/harmonyos/template/entry/src/main/resources/base/profile/main_pages.json +6 -0
- biucingcli/template_data/harmonyos/template/entry/src/test/List.test.ets +11 -0
- biucingcli/template_data/harmonyos/template/hvigor/hvigor-config.json5 +8 -0
- biucingcli/template_data/harmonyos/template/hvigorfile.ts +6 -0
- biucingcli/template_data/harmonyos/template/oh-package-lock.json5 +19 -0
- biucingcli/template_data/harmonyos/template/oh-package.json5 +13 -0
- biucingcli/template_data/harmonyos/template/scripts/artifact-info +31 -0
- biucingcli/template_data/harmonyos/template/scripts/bootstrap +38 -0
- biucingcli/template_data/harmonyos/template/scripts/doctor +147 -0
- biucingcli/template_data/harmonyos/template/scripts/lint +105 -0
- biucingcli/template_data/harmonyos/template/scripts/release-build +199 -0
- biucingcli/template_data/harmonyos/template/scripts/release-preflight +109 -0
- biucingcli/template_data/harmonyos/template/scripts/test +28 -0
- biucingcli/template_data/harmonyos/template/scripts/verify-release-artifact +173 -0
- biucingcli/template_data/harmonyos/template/scripts/verify-supply-chain +70 -0
- biucingcli/template_data/harmonyos/template.json +134 -0
- biucingcli/template_data/microservice/template/.air.toml +11 -0
- biucingcli/template_data/microservice/template/.dockerignore +5 -0
- biucingcli/template_data/microservice/template/.gitignore +4 -0
- biucingcli/template_data/microservice/template/.mise.toml +3 -0
- biucingcli/template_data/microservice/template/Brewfile +7 -0
- biucingcli/template_data/microservice/template/Dockerfile +44 -0
- biucingcli/template_data/microservice/template/Dockerfile.dev +50 -0
- biucingcli/template_data/microservice/template/Makefile +145 -0
- biucingcli/template_data/microservice/template/README.md +191 -0
- biucingcli/template_data/microservice/template/api/buf.gen.yaml +11 -0
- biucingcli/template_data/microservice/template/api/buf.yaml +11 -0
- biucingcli/template_data/microservice/template/api/proto/service/v1/service.proto +18 -0
- biucingcli/template_data/microservice/template/cmd/server/main.go +81 -0
- biucingcli/template_data/microservice/template/compose.dev.yaml +49 -0
- biucingcli/template_data/microservice/template/configs/config.yaml +18 -0
- biucingcli/template_data/microservice/template/deploy/compose.yaml +35 -0
- biucingcli/template_data/microservice/template/deploy/otel-collector.yaml +15 -0
- biucingcli/template_data/microservice/template/go.mod +53 -0
- biucingcli/template_data/microservice/template/go.sum +138 -0
- biucingcli/template_data/microservice/template/internal/config/config.go +112 -0
- biucingcli/template_data/microservice/template/internal/config/config_test.go +92 -0
- biucingcli/template_data/microservice/template/internal/handler/health.go +25 -0
- biucingcli/template_data/microservice/template/internal/handler/ping.go +25 -0
- biucingcli/template_data/microservice/template/internal/model/health.go +8 -0
- biucingcli/template_data/microservice/template/internal/model/ping.go +7 -0
- biucingcli/template_data/microservice/template/internal/repository/.gitkeep +1 -0
- biucingcli/template_data/microservice/template/internal/router/router.go +26 -0
- biucingcli/template_data/microservice/template/internal/runtime/server.go +116 -0
- biucingcli/template_data/microservice/template/internal/runtime/server_test.go +161 -0
- biucingcli/template_data/microservice/template/internal/service/health.go +26 -0
- biucingcli/template_data/microservice/template/internal/service/ping.go +23 -0
- biucingcli/template_data/microservice/template/internal/telemetry/telemetry.go +56 -0
- biucingcli/template_data/microservice/template/internal/transport/grpc.go +51 -0
- biucingcli/template_data/microservice/template/internal/transport/ping.go +28 -0
- biucingcli/template_data/microservice/template/scripts/bootstrap +29 -0
- biucingcli/template_data/microservice/template/scripts/doctor +115 -0
- biucingcli/template_data/microservice/template/tests/server_test.go +153 -0
- biucingcli/template_data/microservice/template.json +114 -0
- biucingcli/template_data/web-service/template/.air.toml +11 -0
- biucingcli/template_data/web-service/template/.dockerignore +5 -0
- biucingcli/template_data/web-service/template/.gitignore +5 -0
- biucingcli/template_data/web-service/template/.mise.toml +2 -0
- biucingcli/template_data/web-service/template/Brewfile +5 -0
- biucingcli/template_data/web-service/template/Dockerfile +41 -0
- biucingcli/template_data/web-service/template/Dockerfile.dev +45 -0
- biucingcli/template_data/web-service/template/Makefile +113 -0
- biucingcli/template_data/web-service/template/README.md +164 -0
- biucingcli/template_data/web-service/template/cmd/server/main.go +50 -0
- biucingcli/template_data/web-service/template/compose.dev.yaml +28 -0
- biucingcli/template_data/web-service/template/compose.yaml +14 -0
- biucingcli/template_data/web-service/template/configs/config.yaml +10 -0
- biucingcli/template_data/web-service/template/go.mod +36 -0
- biucingcli/template_data/web-service/template/go.sum +89 -0
- biucingcli/template_data/web-service/template/internal/config/config.go +84 -0
- biucingcli/template_data/web-service/template/internal/config/config_test.go +88 -0
- biucingcli/template_data/web-service/template/internal/handler/health.go +25 -0
- biucingcli/template_data/web-service/template/internal/handler/ping.go +25 -0
- biucingcli/template_data/web-service/template/internal/handler/user.go +40 -0
- biucingcli/template_data/web-service/template/internal/model/health.go +6 -0
- biucingcli/template_data/web-service/template/internal/model/ping.go +7 -0
- biucingcli/template_data/web-service/template/internal/model/user.go +7 -0
- biucingcli/template_data/web-service/template/internal/repository/.gitkeep +1 -0
- biucingcli/template_data/web-service/template/internal/repository/user.go +37 -0
- biucingcli/template_data/web-service/template/internal/router/router.go +28 -0
- biucingcli/template_data/web-service/template/internal/runtime/server.go +76 -0
- biucingcli/template_data/web-service/template/internal/runtime/server_test.go +139 -0
- biucingcli/template_data/web-service/template/internal/service/health.go +22 -0
- biucingcli/template_data/web-service/template/internal/service/ping.go +23 -0
- biucingcli/template_data/web-service/template/internal/service/user.go +27 -0
- biucingcli/template_data/web-service/template/scripts/bootstrap +23 -0
- biucingcli/template_data/web-service/template/scripts/doctor +83 -0
- biucingcli/template_data/web-service/template/tests/server_test.go +160 -0
- biucingcli/template_data/web-service/template.json +88 -0
- biucingcli/template_data/worker/template/.dockerignore +3 -0
- biucingcli/template_data/worker/template/.gitignore +2 -0
- biucingcli/template_data/worker/template/.mise.toml +2 -0
- biucingcli/template_data/worker/template/Brewfile +1 -0
- biucingcli/template_data/worker/template/Dockerfile +19 -0
- biucingcli/template_data/worker/template/Dockerfile.dev +9 -0
- biucingcli/template_data/worker/template/Makefile +105 -0
- biucingcli/template_data/worker/template/README.md +164 -0
- biucingcli/template_data/worker/template/cmd/worker/main.go +41 -0
- biucingcli/template_data/worker/template/compose.dev.yaml +29 -0
- biucingcli/template_data/worker/template/configs/config.json +11 -0
- biucingcli/template_data/worker/template/go.mod +3 -0
- biucingcli/template_data/worker/template/go.sum +1 -0
- biucingcli/template_data/worker/template/internal/config/config.go +108 -0
- biucingcli/template_data/worker/template/internal/config/config_test.go +86 -0
- biucingcli/template_data/worker/template/internal/runtime/runner.go +199 -0
- biucingcli/template_data/worker/template/internal/runtime/runner_test.go +215 -0
- biucingcli/template_data/worker/template/internal/task/heartbeat.go +19 -0
- biucingcli/template_data/worker/template/scripts/bootstrap +6 -0
- biucingcli/template_data/worker/template/scripts/doctor +41 -0
- biucingcli/template_data/worker/template/tests/worker_test.go +44 -0
- biucingcli/template_data/worker/template.json +100 -0
- biucingcli/templates.py +902 -0
- biucingcli-0.9.1.dist-info/METADATA +204 -0
- biucingcli-0.9.1.dist-info/RECORD +269 -0
- biucingcli-0.9.1.dist-info/WHEEL +5 -0
- biucingcli-0.9.1.dist-info/entry_points.txt +2 -0
- biucingcli-0.9.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"log"
|
|
6
|
+
"net"
|
|
7
|
+
"os"
|
|
8
|
+
"os/signal"
|
|
9
|
+
"syscall"
|
|
10
|
+
"time"
|
|
11
|
+
|
|
12
|
+
"{{MODULE_NAME}}/internal/config"
|
|
13
|
+
"{{MODULE_NAME}}/internal/router"
|
|
14
|
+
serverruntime "{{MODULE_NAME}}/internal/runtime"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
func main() {
|
|
18
|
+
if len(os.Args) == 3 && os.Args[1] == "healthcheck" {
|
|
19
|
+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
20
|
+
defer cancel()
|
|
21
|
+
if err := serverruntime.CheckHealth(ctx, os.Args[2]); err != nil {
|
|
22
|
+
log.Fatal(err)
|
|
23
|
+
}
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
cfg, err := config.Load()
|
|
28
|
+
if err != nil {
|
|
29
|
+
log.Fatal(err)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
listener, err := net.Listen("tcp", ":"+cfg.Service.Port)
|
|
33
|
+
if err != nil {
|
|
34
|
+
log.Fatal(err)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
38
|
+
defer stop()
|
|
39
|
+
|
|
40
|
+
server := serverruntime.NewHTTPServer(cfg, router.New(cfg))
|
|
41
|
+
log.Printf("starting %s on :%s", cfg.Service.Name, cfg.Service.Port)
|
|
42
|
+
if err := serverruntime.Serve(
|
|
43
|
+
ctx,
|
|
44
|
+
server,
|
|
45
|
+
listener,
|
|
46
|
+
time.Duration(cfg.Server.ShutdownTimeoutSeconds)*time.Second,
|
|
47
|
+
); err != nil {
|
|
48
|
+
log.Fatal(err)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
services:
|
|
2
|
+
app-dev:
|
|
3
|
+
build:
|
|
4
|
+
context: .
|
|
5
|
+
dockerfile: Dockerfile.dev
|
|
6
|
+
args:
|
|
7
|
+
GOPROXY: ${GOPROXY:-https://proxy.golang.org,direct}
|
|
8
|
+
GOSUMDB: ${GOSUMDB:-sum.golang.org}
|
|
9
|
+
working_dir: /workspace
|
|
10
|
+
command: air -c .air.toml
|
|
11
|
+
environment:
|
|
12
|
+
CONFIG_FILE: /workspace/configs/config.yaml
|
|
13
|
+
GOCACHE: /workspace/.cache/go-build
|
|
14
|
+
GOMODCACHE: /workspace/.cache/go-mod
|
|
15
|
+
GOLANGCI_LINT_CACHE: /workspace/.cache/golangci-lint
|
|
16
|
+
ports:
|
|
17
|
+
- "${HOST_PORT:-{{HTTP_PORT}}}:{{HTTP_PORT}}"
|
|
18
|
+
stop_grace_period: 15s
|
|
19
|
+
volumes:
|
|
20
|
+
- .:/workspace
|
|
21
|
+
- web-service-go-build:/workspace/.cache/go-build
|
|
22
|
+
- web-service-go-mod:/workspace/.cache/go-mod
|
|
23
|
+
- web-service-golangci-lint:/workspace/.cache/golangci-lint
|
|
24
|
+
|
|
25
|
+
volumes:
|
|
26
|
+
web-service-go-build:
|
|
27
|
+
web-service-go-mod:
|
|
28
|
+
web-service-golangci-lint:
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
services:
|
|
2
|
+
{{SERVICE_NAME}}:
|
|
3
|
+
build:
|
|
4
|
+
context: .
|
|
5
|
+
dockerfile: Dockerfile
|
|
6
|
+
args:
|
|
7
|
+
BUILDER_IMAGE: ${BUILDER_IMAGE:-golang:1.26-alpine}
|
|
8
|
+
RUNTIME_IMAGE: ${RUNTIME_IMAGE:-alpine:3.20}
|
|
9
|
+
image: ${IMAGE:-{{SERVICE_NAME}}}:${TAG:-latest}
|
|
10
|
+
ports:
|
|
11
|
+
- "${HOST_PORT:-{{HTTP_PORT}}}:{{HTTP_PORT}}"
|
|
12
|
+
environment:
|
|
13
|
+
CONFIG_FILE: /app/configs/config.yaml
|
|
14
|
+
stop_grace_period: 15s
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module {{MODULE_NAME}}
|
|
2
|
+
|
|
3
|
+
go 1.26.0
|
|
4
|
+
|
|
5
|
+
require (
|
|
6
|
+
github.com/gin-gonic/gin v1.10.0
|
|
7
|
+
gopkg.in/yaml.v3 v3.0.1
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
require (
|
|
11
|
+
github.com/bytedance/sonic v1.11.6 // indirect
|
|
12
|
+
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
|
13
|
+
github.com/cloudwego/base64x v0.1.4 // indirect
|
|
14
|
+
github.com/cloudwego/iasm v0.2.0 // indirect
|
|
15
|
+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
|
16
|
+
github.com/gin-contrib/sse v0.1.0 // indirect
|
|
17
|
+
github.com/go-playground/locales v0.14.1 // indirect
|
|
18
|
+
github.com/go-playground/universal-translator v0.18.1 // indirect
|
|
19
|
+
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
|
20
|
+
github.com/goccy/go-json v0.10.2 // indirect
|
|
21
|
+
github.com/json-iterator/go v1.1.12 // indirect
|
|
22
|
+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
|
23
|
+
github.com/leodido/go-urn v1.4.0 // indirect
|
|
24
|
+
github.com/mattn/go-isatty v0.0.20 // indirect
|
|
25
|
+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
|
26
|
+
github.com/modern-go/reflect2 v1.0.2 // indirect
|
|
27
|
+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
|
28
|
+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
|
29
|
+
github.com/ugorji/go/codec v1.2.12 // indirect
|
|
30
|
+
golang.org/x/arch v0.8.0 // indirect
|
|
31
|
+
golang.org/x/crypto v0.23.0 // indirect
|
|
32
|
+
golang.org/x/net v0.25.0 // indirect
|
|
33
|
+
golang.org/x/sys v0.20.0 // indirect
|
|
34
|
+
golang.org/x/text v0.15.0 // indirect
|
|
35
|
+
google.golang.org/protobuf v1.34.1 // indirect
|
|
36
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
|
|
2
|
+
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
|
|
3
|
+
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
|
|
4
|
+
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
|
5
|
+
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
|
|
6
|
+
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
|
7
|
+
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
|
|
8
|
+
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
|
9
|
+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
10
|
+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
11
|
+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
12
|
+
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
|
13
|
+
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
|
14
|
+
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
|
15
|
+
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
|
16
|
+
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
|
17
|
+
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
|
18
|
+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
|
19
|
+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
|
20
|
+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
|
21
|
+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
|
22
|
+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
|
23
|
+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
|
24
|
+
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
|
|
25
|
+
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
|
26
|
+
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
|
27
|
+
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
|
28
|
+
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
|
29
|
+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
30
|
+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
|
31
|
+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
|
32
|
+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
|
33
|
+
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
|
34
|
+
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
|
35
|
+
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
|
36
|
+
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
|
37
|
+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
|
38
|
+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
|
39
|
+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
|
40
|
+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
|
41
|
+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
42
|
+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
|
43
|
+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
44
|
+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
|
45
|
+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
|
46
|
+
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
|
47
|
+
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
|
48
|
+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
49
|
+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
50
|
+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
51
|
+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
|
52
|
+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
53
|
+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
|
54
|
+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
55
|
+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
56
|
+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
57
|
+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
|
58
|
+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
|
59
|
+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
|
60
|
+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
|
61
|
+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
|
62
|
+
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
|
63
|
+
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
|
64
|
+
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
|
65
|
+
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
|
66
|
+
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
|
67
|
+
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
|
|
68
|
+
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
|
69
|
+
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
|
70
|
+
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
|
71
|
+
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
|
72
|
+
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
|
73
|
+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
74
|
+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
75
|
+
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
|
76
|
+
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
77
|
+
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
|
78
|
+
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
|
79
|
+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
|
80
|
+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
81
|
+
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
|
82
|
+
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
|
83
|
+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
84
|
+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
85
|
+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
86
|
+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
87
|
+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
88
|
+
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
|
89
|
+
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
package config
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"errors"
|
|
5
|
+
"os"
|
|
6
|
+
|
|
7
|
+
"gopkg.in/yaml.v3"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
const defaultConfigFile = "configs/config.yaml"
|
|
11
|
+
|
|
12
|
+
type Config struct {
|
|
13
|
+
Service ServiceConfig `yaml:"service"`
|
|
14
|
+
Server ServerConfig `yaml:"server"`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type ServiceConfig struct {
|
|
18
|
+
Name string `yaml:"name"`
|
|
19
|
+
Port string `yaml:"port"`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type ServerConfig struct {
|
|
23
|
+
ReadTimeoutSeconds int `yaml:"read_timeout_seconds"`
|
|
24
|
+
ReadHeaderTimeoutSeconds int `yaml:"read_header_timeout_seconds"`
|
|
25
|
+
WriteTimeoutSeconds int `yaml:"write_timeout_seconds"`
|
|
26
|
+
IdleTimeoutSeconds int `yaml:"idle_timeout_seconds"`
|
|
27
|
+
ShutdownTimeoutSeconds int `yaml:"shutdown_timeout_seconds"`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func Load() (Config, error) {
|
|
31
|
+
configFile := os.Getenv("CONFIG_FILE")
|
|
32
|
+
if configFile == "" {
|
|
33
|
+
configFile = defaultConfigFile
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
data, err := os.ReadFile(configFile)
|
|
37
|
+
if err != nil {
|
|
38
|
+
return Config{}, err
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var cfg Config
|
|
42
|
+
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
43
|
+
return Config{}, err
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if cfg.Service.Name == "" {
|
|
47
|
+
return Config{}, errors.New("service.name is required")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if cfg.Service.Port == "" {
|
|
51
|
+
cfg.Service.Port = "{{HTTP_PORT}}"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if err := cfg.Server.applyDefaults(); err != nil {
|
|
55
|
+
return Config{}, err
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return cfg, nil
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func (cfg *ServerConfig) applyDefaults() error {
|
|
62
|
+
values := []struct {
|
|
63
|
+
name string
|
|
64
|
+
value *int
|
|
65
|
+
defaultValue int
|
|
66
|
+
}{
|
|
67
|
+
{"server.read_timeout_seconds", &cfg.ReadTimeoutSeconds, 5},
|
|
68
|
+
{"server.read_header_timeout_seconds", &cfg.ReadHeaderTimeoutSeconds, 5},
|
|
69
|
+
{"server.write_timeout_seconds", &cfg.WriteTimeoutSeconds, 15},
|
|
70
|
+
{"server.idle_timeout_seconds", &cfg.IdleTimeoutSeconds, 60},
|
|
71
|
+
{"server.shutdown_timeout_seconds", &cfg.ShutdownTimeoutSeconds, 10},
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for _, item := range values {
|
|
75
|
+
if *item.value < 0 {
|
|
76
|
+
return errors.New(item.name + " must be greater than zero")
|
|
77
|
+
}
|
|
78
|
+
if *item.value == 0 {
|
|
79
|
+
*item.value = item.defaultValue
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return nil
|
|
84
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
package config
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"os"
|
|
5
|
+
"path/filepath"
|
|
6
|
+
"testing"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func TestLoadDefaultConfig(t *testing.T) {
|
|
10
|
+
tempDir := t.TempDir()
|
|
11
|
+
configDir := filepath.Join(tempDir, "configs")
|
|
12
|
+
if err := os.MkdirAll(configDir, 0o755); err != nil {
|
|
13
|
+
t.Fatal(err)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
configFile := filepath.Join(configDir, "config.yaml")
|
|
17
|
+
configData := []byte("service:\n name: test-service\n port: 8080\n")
|
|
18
|
+
if err := os.WriteFile(configFile, configData, 0o644); err != nil {
|
|
19
|
+
t.Fatal(err)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
currentDir, err := os.Getwd()
|
|
23
|
+
if err != nil {
|
|
24
|
+
t.Fatal(err)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if err := os.Chdir(tempDir); err != nil {
|
|
28
|
+
t.Fatal(err)
|
|
29
|
+
}
|
|
30
|
+
t.Cleanup(func() {
|
|
31
|
+
if chdirErr := os.Chdir(currentDir); chdirErr != nil {
|
|
32
|
+
t.Fatalf("restore working directory: %v", chdirErr)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
cfg, err := Load()
|
|
37
|
+
if err != nil {
|
|
38
|
+
t.Fatal(err)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if cfg.Service.Name != "test-service" {
|
|
42
|
+
t.Fatalf("expected service name %q, got %q", "test-service", cfg.Service.Name)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if cfg.Service.Port != "8080" {
|
|
46
|
+
t.Fatalf("expected service port %q, got %q", "8080", cfg.Service.Port)
|
|
47
|
+
}
|
|
48
|
+
if cfg.Server.ShutdownTimeoutSeconds != 10 {
|
|
49
|
+
t.Fatalf("expected default shutdown timeout %d, got %d", 10, cfg.Server.ShutdownTimeoutSeconds)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
func TestLoadRejectsNegativeTimeout(t *testing.T) {
|
|
54
|
+
configFile := filepath.Join(t.TempDir(), "invalid.yaml")
|
|
55
|
+
configData := []byte("service:\n name: invalid-service\nserver:\n shutdown_timeout_seconds: -1\n")
|
|
56
|
+
if err := os.WriteFile(configFile, configData, 0o644); err != nil {
|
|
57
|
+
t.Fatal(err)
|
|
58
|
+
}
|
|
59
|
+
t.Setenv("CONFIG_FILE", configFile)
|
|
60
|
+
|
|
61
|
+
if _, err := Load(); err == nil {
|
|
62
|
+
t.Fatal("expected a negative timeout to fail validation")
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func TestLoadUsesConfigFileOverride(t *testing.T) {
|
|
67
|
+
tempDir := t.TempDir()
|
|
68
|
+
configFile := filepath.Join(tempDir, "override.yaml")
|
|
69
|
+
configData := []byte("service:\n name: override-service\n port: 9090\n")
|
|
70
|
+
if err := os.WriteFile(configFile, configData, 0o644); err != nil {
|
|
71
|
+
t.Fatal(err)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
t.Setenv("CONFIG_FILE", configFile)
|
|
75
|
+
|
|
76
|
+
cfg, err := Load()
|
|
77
|
+
if err != nil {
|
|
78
|
+
t.Fatal(err)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if cfg.Service.Name != "override-service" {
|
|
82
|
+
t.Fatalf("expected service name %q, got %q", "override-service", cfg.Service.Name)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if cfg.Service.Port != "9090" {
|
|
86
|
+
t.Fatalf("expected service port %q, got %q", "9090", cfg.Service.Port)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package handler
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"net/http"
|
|
5
|
+
|
|
6
|
+
"{{MODULE_NAME}}/internal/service"
|
|
7
|
+
|
|
8
|
+
"github.com/gin-gonic/gin"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
type HealthHandler struct {
|
|
12
|
+
service service.HealthService
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
func NewHealthHandler(service service.HealthService) HealthHandler {
|
|
16
|
+
return HealthHandler{service: service}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func (handler HealthHandler) RegisterRoutes(engine *gin.Engine) {
|
|
20
|
+
engine.GET("/healthz", handler.GetHealth)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func (handler HealthHandler) GetHealth(ctx *gin.Context) {
|
|
24
|
+
ctx.JSON(http.StatusOK, handler.service.Status())
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package handler
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"net/http"
|
|
5
|
+
|
|
6
|
+
"{{MODULE_NAME}}/internal/service"
|
|
7
|
+
|
|
8
|
+
"github.com/gin-gonic/gin"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
type PingHandler struct {
|
|
12
|
+
service service.PingService
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
func NewPingHandler(service service.PingService) PingHandler {
|
|
16
|
+
return PingHandler{service: service}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func (handler PingHandler) RegisterRoutes(group *gin.RouterGroup) {
|
|
20
|
+
group.GET("/ping", handler.Ping)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func (handler PingHandler) Ping(ctx *gin.Context) {
|
|
24
|
+
ctx.JSON(http.StatusOK, handler.service.Ping())
|
|
25
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package handler
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"net/http"
|
|
5
|
+
|
|
6
|
+
"{{MODULE_NAME}}/internal/service"
|
|
7
|
+
|
|
8
|
+
"github.com/gin-gonic/gin"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
type UserHandler struct {
|
|
12
|
+
service service.UserService
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
func NewUserHandler(service service.UserService) UserHandler {
|
|
16
|
+
return UserHandler{service: service}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func (handler UserHandler) RegisterRoutes(group *gin.RouterGroup) {
|
|
20
|
+
group.GET("/users", handler.ListUsers)
|
|
21
|
+
group.GET("/users/:id", handler.GetUser)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func (handler UserHandler) ListUsers(ctx *gin.Context) {
|
|
25
|
+
ctx.JSON(http.StatusOK, gin.H{
|
|
26
|
+
"items": handler.service.ListUsers(),
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func (handler UserHandler) GetUser(ctx *gin.Context) {
|
|
31
|
+
user, found := handler.service.GetUser(ctx.Param("id"))
|
|
32
|
+
if !found {
|
|
33
|
+
ctx.JSON(http.StatusNotFound, gin.H{
|
|
34
|
+
"error": "user not found",
|
|
35
|
+
})
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
ctx.JSON(http.StatusOK, user)
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
package repository
|
|
2
|
+
|
|
3
|
+
import "{{MODULE_NAME}}/internal/model"
|
|
4
|
+
|
|
5
|
+
type UserRepository interface {
|
|
6
|
+
List() []model.User
|
|
7
|
+
GetByID(id string) (model.User, bool)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type inMemoryUserRepository struct {
|
|
11
|
+
users []model.User
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func NewUserRepository() UserRepository {
|
|
15
|
+
return inMemoryUserRepository{
|
|
16
|
+
users: []model.User{
|
|
17
|
+
{ID: "u_001", Name: "Ada Lovelace", Email: "ada@example.com"},
|
|
18
|
+
{ID: "u_002", Name: "Alan Turing", Email: "alan@example.com"},
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func (repository inMemoryUserRepository) List() []model.User {
|
|
24
|
+
users := make([]model.User, len(repository.users))
|
|
25
|
+
copy(users, repository.users)
|
|
26
|
+
return users
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func (repository inMemoryUserRepository) GetByID(id string) (model.User, bool) {
|
|
30
|
+
for _, user := range repository.users {
|
|
31
|
+
if user.ID == id {
|
|
32
|
+
return user, true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return model.User{}, false
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package router
|
|
2
|
+
|
|
3
|
+
import "{{MODULE_NAME}}/internal/config"
|
|
4
|
+
import "{{MODULE_NAME}}/internal/handler"
|
|
5
|
+
import "{{MODULE_NAME}}/internal/repository"
|
|
6
|
+
import "{{MODULE_NAME}}/internal/service"
|
|
7
|
+
|
|
8
|
+
import "github.com/gin-gonic/gin"
|
|
9
|
+
|
|
10
|
+
func New(cfg config.Config) *gin.Engine {
|
|
11
|
+
engine := gin.Default()
|
|
12
|
+
|
|
13
|
+
healthService := service.NewHealthService(cfg.Service.Name)
|
|
14
|
+
healthHandler := handler.NewHealthHandler(healthService)
|
|
15
|
+
healthHandler.RegisterRoutes(engine)
|
|
16
|
+
|
|
17
|
+
apiGroup := engine.Group("/api/v1")
|
|
18
|
+
pingService := service.NewPingService(cfg.Service.Name)
|
|
19
|
+
pingHandler := handler.NewPingHandler(pingService)
|
|
20
|
+
pingHandler.RegisterRoutes(apiGroup)
|
|
21
|
+
|
|
22
|
+
userRepository := repository.NewUserRepository()
|
|
23
|
+
userService := service.NewUserService(userRepository)
|
|
24
|
+
userHandler := handler.NewUserHandler(userService)
|
|
25
|
+
userHandler.RegisterRoutes(apiGroup)
|
|
26
|
+
|
|
27
|
+
return engine
|
|
28
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
package runtime
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"errors"
|
|
6
|
+
"net"
|
|
7
|
+
"net/http"
|
|
8
|
+
"time"
|
|
9
|
+
|
|
10
|
+
"{{MODULE_NAME}}/internal/config"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
func NewHTTPServer(cfg config.Config, handler http.Handler) *http.Server {
|
|
14
|
+
return &http.Server{
|
|
15
|
+
Addr: ":" + cfg.Service.Port,
|
|
16
|
+
Handler: handler,
|
|
17
|
+
ReadTimeout: time.Duration(cfg.Server.ReadTimeoutSeconds) * time.Second,
|
|
18
|
+
ReadHeaderTimeout: time.Duration(cfg.Server.ReadHeaderTimeoutSeconds) * time.Second,
|
|
19
|
+
WriteTimeout: time.Duration(cfg.Server.WriteTimeoutSeconds) * time.Second,
|
|
20
|
+
IdleTimeout: time.Duration(cfg.Server.IdleTimeoutSeconds) * time.Second,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func CheckHealth(ctx context.Context, url string) error {
|
|
25
|
+
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
|
26
|
+
if err != nil {
|
|
27
|
+
return err
|
|
28
|
+
}
|
|
29
|
+
response, err := http.DefaultClient.Do(request)
|
|
30
|
+
if err != nil {
|
|
31
|
+
return err
|
|
32
|
+
}
|
|
33
|
+
defer response.Body.Close()
|
|
34
|
+
if response.StatusCode != http.StatusOK {
|
|
35
|
+
return errors.New("health endpoint returned " + response.Status)
|
|
36
|
+
}
|
|
37
|
+
return nil
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func Serve(
|
|
41
|
+
ctx context.Context,
|
|
42
|
+
server *http.Server,
|
|
43
|
+
listener net.Listener,
|
|
44
|
+
shutdownTimeout time.Duration,
|
|
45
|
+
) error {
|
|
46
|
+
serveErr := make(chan error, 1)
|
|
47
|
+
go func() {
|
|
48
|
+
serveErr <- server.Serve(listener)
|
|
49
|
+
}()
|
|
50
|
+
|
|
51
|
+
select {
|
|
52
|
+
case err := <-serveErr:
|
|
53
|
+
if errors.Is(err, http.ErrServerClosed) {
|
|
54
|
+
return nil
|
|
55
|
+
}
|
|
56
|
+
return err
|
|
57
|
+
case <-ctx.Done():
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
shutdownCtx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
|
|
61
|
+
defer cancel()
|
|
62
|
+
|
|
63
|
+
if err := server.Shutdown(shutdownCtx); err != nil {
|
|
64
|
+
closeErr := server.Close()
|
|
65
|
+
if closeErr != nil && !errors.Is(closeErr, http.ErrServerClosed) {
|
|
66
|
+
return errors.Join(err, closeErr)
|
|
67
|
+
}
|
|
68
|
+
return err
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
err := <-serveErr
|
|
72
|
+
if errors.Is(err, http.ErrServerClosed) {
|
|
73
|
+
return nil
|
|
74
|
+
}
|
|
75
|
+
return err
|
|
76
|
+
}
|