From a4096bf1a7c3c417657b9851e60a330b042a283c Mon Sep 17 00:00:00 2001 From: Yi-Ting Shih Date: Sun, 7 Dec 2025 02:33:44 +0800 Subject: [PATCH] Init: bootstrap --- .gitignore | 1 + Makefile | 28 +++ backend.go | 7 + cmds/root.go | 24 ++ cmds/serve.go | 115 ++++++++++ docker-compose.yml | 73 ++++++ docker/postgres/backend.sql | 4 + docker/uptrace/config.yml | 435 ++++++++++++++++++++++++++++++++++++ docs/docs.go | 40 ++++ docs/swagger.json | 14 ++ docs/swagger.yaml | 10 + go.mod | 68 ++++++ go.sum | 176 +++++++++++++++ go.work | 3 + go.work.sum | 7 + tracing/tracer.go | 47 ++++ 16 files changed, 1052 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 backend.go create mode 100644 cmds/root.go create mode 100644 cmds/serve.go create mode 100644 docker-compose.yml create mode 100644 docker/postgres/backend.sql create mode 100644 docker/uptrace/config.yml create mode 100644 docs/docs.go create mode 100644 docs/swagger.json create mode 100644 docs/swagger.yaml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 go.work create mode 100644 go.work.sum create mode 100644 tracing/tracer.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e34d8c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +backend diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8f7a1d6 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +.PHONY: all swagger docker install test bench + +SWAG ?= go run github.com/swaggo/swag/cmd/swag@v1.16.4 + +GO_ENV += CGO_ENABLED=0 +SOURCE := $(shell find . -type f -name '*.go') +TARGET := backend + +all: swagger docker install + +docker: $(TARGET) + docker compose up -d --force-recreate --build backend + +install: + $(GO_ENV) go install + +test: + go test -v ./tests/units + +bench: + go test -bench=. ./tests/benchmarks + +swagger: + $(SWAG) fmt + $(SWAG) init -o docs -g cmds/serve.go -pdl 1 + +$(TARGET): $(SOURCE) + $(GO_ENV) go build -o $@ diff --git a/backend.go b/backend.go new file mode 100644 index 0000000..1d2791d --- /dev/null +++ b/backend.go @@ -0,0 +1,7 @@ +package main + +import "gitea.konchin.com/go2025/backend/cmds" + +func main() { + cmds.RootCmd.Execute() +} diff --git a/cmds/root.go b/cmds/root.go new file mode 100644 index 0000000..6b9aa12 --- /dev/null +++ b/cmds/root.go @@ -0,0 +1,24 @@ +package cmds + +import ( + "strings" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var RootCmd = &cobra.Command{ + Use: "root", + PersistentPreRun: func(cmd *cobra.Command, args []string) { + viper.AutomaticEnv() + viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) + viper.BindPFlags(cmd.PersistentFlags()) + viper.BindPFlags(cmd.Flags()) + }, +} + +func init() { + cobra.EnableTraverseRunHooks = true + + RootCmd.AddCommand(serveCmd) +} diff --git a/cmds/serve.go b/cmds/serve.go new file mode 100644 index 0000000..150d8e8 --- /dev/null +++ b/cmds/serve.go @@ -0,0 +1,115 @@ +package cmds + +import ( + "database/sql" + "log" + "net/http" + + "gitea.konchin.com/go2025/backend/tracing" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "go.uber.org/zap" + + _ "gitea.konchin.com/go2025/backend/docs" +) + +// @title Golang 2025 Final Project +// @version 0.0.1 +// @termsOfService http://swagger.io/terms +// +// @license.name 0BSD +// @basePath / +var serveCmd = &cobra.Command{ + Use: "serve", + Run: func(cmd *cobra.Command, args []string) { + ctx := cmd.Context() + + // Initialize tracing + appname := "go2025-backend" + tracing.InitTracer(appname) + if viper.GetString("uptrace-dsn") != "" { + tracing.InitUptrace(appname) + defer tracing.DeferUptrace(ctx) + } + + // Initialize DB instance + sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN( + viper.GetString("pg-connection-string")))) + bunDB := bun.NewDB(sqldb, pgdialect.New()) + bunDB.AddQueryHook(bunotel.NewQueryHook(bunotel.WithDBName("backend"))) + + // Initialize MinIO instance + mc, err := minio.New(viper.GetString("minio-host"), &minio.Options{ + Creds: credentials.NewStaticV4( + viper.GetString("minio-accesskey"), + viper.GetString("minio-secretkey"), + "", + ), + Secure: viper.GetBool("minio-usessl"), + }) + if err != nil { + tracing.Logger.Ctx(ctx). + Error("failed to create minio client", + zap.Error(err)) + panic(err) + } + + if err := utils.InitMinIO(ctx, mc); err != nil { + tracing.Logger.Ctx(ctx). + Error("failed to minio init", + zap.Error(err)) + panic(err) + } + + // Initialize custom interfaces + db := implements.NewBunDatabase(bunDB) + s3 := implements.NewMinIOObjectStorage(mc) + + // Initialize backend router + router := bunrouter.New() + backend := router.NewGroup(""). + Use(middlewares.ErrorHandler). + Use(middlewares.BunrouterOtel). + Use(middlewares.AccessLog). + Use(middlewares.CORSHandler) + + if viper.GetBool("swagger") { + backend.GET("/swagger/*any", + bunrouter.HTTPHandlerFunc( + httpSwagger.Handler())) + } + + log.Println(http.ListenAndServe( + ":"+viper.GetString("port"), + otelhttp.NewHandler(router, ""))) + }, +} + +func init() { + serveCmd.Flags(). + String("port", "8080", "Port to listen on") + + serveCmd.Flags(). + Bool("zap-production", true, "Toggle production log format") + serveCmd.Flags(). + Bool("swagger", false, "Toggle swagger") + + serveCmd.Flags(). + String("pg-connection-string", + "postgres://go2025:go2025@pg:5432/go2025?sslmode=disable", + "Postgres connection string") + + backendCmd.Flags(). + String("minio-host", "minio:9000", "MinIO host[:port]") + backendCmd.Flags(). + String("minio-bucket", "go2025", "MinIO bucket") + backendCmd.Flags(). + String("minio-accesskey", "poop", "MinIO accesskey") + backendCmd.Flags(). + String("minio-secretkey", "poop", "MinIO secretkey") + backendCmd.Flags(). + Bool("minio-usessl", false, "MinIO usessl") + + serveCmd.Flags(). + String("uptrace-dsn", "", "Uptrace DSN (disabled by default)") +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e59bfbd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,73 @@ +--- +services: + postgres: + image: postgres:17.2 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: poop + ports: + - 5432:5432 + volumes: + - ./docker/postgres/:/docker-entrypoint-initdb.d/ + - postgres:/var/lib/postgresql/data + restart: unless-stopped + + minio: + image: minio/minio:RELEASE.2025-07-23T15-54-02Z + environment: + MINIO_ROOT_USER: poop + MINIO_ROOT_PASSWORD: poop + command: ["server", "/data", "--console-address", ":9001"] + ports: + - 9000:9000 + - 9001:9001 + volumes: + - minio:/data + restart: unless-stopped + + clickhouse: + image: library/clickhouse:25.7.4 + environment: + CLICKHOUSE_USER: uptrace + CLICKHOUSE_PASSWORD: uptrace + CLICKHOUSE_DB: uptrace + ports: + - 8123:8123 + #- 9000:9000 + volumes: + - clickhouse:/var/lib/clickhouse + restart: unless-stopped + + uptrace: + image: uptrace/uptrace:2.0.1 + ports: + - 14317:14317 + - 14318:14318 + volumes: + - ./docker/uptrace/config.yml:/etc/uptrace/config.yml + depends_on: + - postgres + - clickhouse + restart: unless-stopped + + backend: + build: + context: . + target: backend_runtime + env_file: + - path: ./.env + ports: + - 8080:8080 + volumes: + - './:/data' + depends_on: + - postgres + - minio + - uptrace + restart: unless-stopped + +volumes: + redis: {} + postgres: {} + minio: {} + clickhouse: {} diff --git a/docker/postgres/backend.sql b/docker/postgres/backend.sql new file mode 100644 index 0000000..3eb61c2 --- /dev/null +++ b/docker/postgres/backend.sql @@ -0,0 +1,4 @@ +CREATE USER go2025; +CREATE DATABASE go2025; +ALTER DATABASE go2025 OWNER TO go2025; +ALTER USER go2025 ENCRYPTED PASSWORD 'go2025'; diff --git a/docker/uptrace/config.yml b/docker/uptrace/config.yml new file mode 100644 index 0000000..346573b --- /dev/null +++ b/docker/uptrace/config.yml @@ -0,0 +1,435 @@ +# ============================================================================= +# Uptrace Configuration +# ============================================================================= +# Complete configuration reference: https://uptrace.dev/get/hosted/config +# +# Environment Variable Support: +# - Simple substitution: foo: $FOO +# - With braces: bar: ${BAR} +# - With defaults: baz: ${BAZ:default_value} +# - To escape '$': foo: $$FOO_BAR +# ============================================================================= + +# ----------------------------------------------------------------------------- +# Service Configuration +# ----------------------------------------------------------------------------- +# Core service settings that define the runtime environment and security +service: + env: hosted # Environment: hosted, development, production + secret: poop # Secret key for cryptographic operations (CHANGE THIS!) + +# ----------------------------------------------------------------------------- +# Site Configuration +# ----------------------------------------------------------------------------- +# External-facing URLs and endpoints for client connections +site: + # Primary URL where users access the Uptrace UI and API + # This URL is used for: + # - Generating dashboard links in notifications + # - CORS validation for browser requests + # - Redirect URIs for authentication flows + # IMPORTANT: Must be accessible from all clients and match your reverse proxy setup + url: http://localhost:14318 + + # Dedicated URL for telemetry data ingestion (OTLP endpoints) + # Use this to separate data ingestion from UI traffic for: + # - Load balancing optimization + # - Different security policies + # - CDN/edge deployment scenarios + # If empty, defaults to site.url + ingest_url: http://localhost:14318?grpc=14317 + +# ----------------------------------------------------------------------------- +# Network Listeners +# ----------------------------------------------------------------------------- +# Configure network interfaces and ports for different protocols +listen: + # HTTP server configuration + # Handles: OTLP/HTTP API, REST API, and Vue.js web interface + http: + # Network address and port to bind to + # Format: [host]:port or :port (binds to all interfaces) + # Common values: :80, :8080, localhost:8080 + addr: :14318 + + # gRPC server configuration + # Handles: OTLP/gRPC API for high-performance telemetry ingestion + # Standard OTLP gRPC port is 4317 + grpc: + addr: :14317 + + # TLS/SSL configuration for HTTPS and secure gRPC + # Uncomment and configure for production deployments + #tls: + # cert_file: /etc/uptrace/server.crt + # key_file: /etc/uptrace/server.key + +# ----------------------------------------------------------------------------- +# Authentication & Authorization +# ----------------------------------------------------------------------------- +# User authentication and access control settings +auth: + # Disable built-in username/password authentication + # Useful when using only SSO providers (OAuth, SAML, etc.) + # Note: SSO authentication methods will remain available + #disabled: true + + # Email domain restriction for user registration + # Only users with email addresses matching this regex can register/login + # Examples: + # - '^.+@example\.com$' - only @example.com domain + # - '^.+@(example|acme)\.com$' - multiple domains + # - '^[^@]+@example\.com$' - stricter validation + #email_regexp: '^.+@example\.com$' + +# ----------------------------------------------------------------------------- +# Bootstrap Data +# ----------------------------------------------------------------------------- +# Initial data created during first startup - defines default users, organizations, and projects +# This data is only created once and can be modified through the UI afterward +seed_data: + update: true # Whether to update existing resources by key + delete: true # Whether to delete disappeared resources by key + + # Default users created on first startup + users: + - key: user1 # Internal reference key (used in relationships below) + name: Admin # Display name in UI + email: admin@uptrace.local # Login email (must be unique) + password: admin # Plain text password (CHANGE THIS IMMEDIATELY!) + email_confirmed: true + + # API tokens for user authentication + # These tokens can be used for API access and programmatic operations + user_tokens: + - key: user_token1 # Internal reference key + user_key: user1 # References user.key above + token: poop # API token value (CHANGE THIS!) + + # Organizations for multi-tenant deployments + # Organizations group users and projects together + orgs: + - key: org1 # Internal reference key + name: CSIT # Organization display name + + # Organization membership and roles + # Defines which users belong to which organizations + org_users: + - key: org_user1 # Internal reference key + org_key: org1 # References org.key above + user_key: user1 # References user.key above + role: owner # Role: owner, admin, or member + + # Projects contain telemetry data and are isolated from each other + # Each project has its own spans, logs, metrics, and dashboards + projects: + - key: self + name: Uptrace + org_key: org1 + - key: project1 # Internal reference key + name: Go2025 # Project display name + org_key: org1 # References org.key above + + # Project-specific tokens for telemetry data ingestion + # These tokens are used in OTLP DSN strings for sending data + project_tokens: + - key: project_token2 + project_key: self + token: poop_token2 + - key: project_token1 # Internal reference key + project_key: project1 # References project.key above + token: poop # Token value for DSN (CHANGE THIS!) + + # Project user permissions + # Controls who can access and modify project data + project_users: + - key: project_user1 # Internal reference key + project_key: project1 # References project.key above + org_user_key: org_user1 # References org_user.key above + perm_level: admin # Permission level: admin, editor, or viewer + +# ----------------------------------------------------------------------------- +# ClickHouse Database Configuration +# ----------------------------------------------------------------------------- +# Primary storage for high-volume telemetry data (spans, logs, metrics) +# ClickHouse is optimized for analytical queries and time-series data +ch_cluster: + # Cluster name for ClickHouse operations + # Used internally for distributed queries and table management + cluster: uptrace1 + + # Enable ClickHouse replicated tables for high availability + # Requires cluster configuration with multiple replicas + # Provides automatic failover and data redundancy + replicated: false + + # Enable ClickHouse distributed tables for horizontal scaling + # Requires cluster configuration across multiple shards + # Only available in Premium Edition + distributed: false + + # Database shards configuration + # Each shard can have multiple replicas for redundancy + shards: + - replicas: + - addr: clickhouse:9000 # ClickHouse server address + database: uptrace # Database name (must exist) + user: uptrace # Database user with write permissions + password: uptrace # Database password + + # Connection timeout settings + dial_timeout: 3s # Time to wait for connection establishment + write_timeout: 5s # Time to wait for write operations + max_retries: 3 # Number of retry attempts for failed operations + + # Query execution timeout + # Prevents long-running queries from consuming resources + max_execution_time: 15s + + # TLS configuration for secure database connections + # Uncomment for production deployments with SSL/TLS + #tls: + # insecure_skip_verify: true # WARNING: Only use for self-signed certificates + +# ----------------------------------------------------------------------------- +# PostgreSQL Database Configuration +# ----------------------------------------------------------------------------- +# Metadata storage for application data (users, projects, dashboards, alerts, etc.) +# PostgreSQL provides ACID compliance for critical application state +pg: + addr: postgres:5432 # PostgreSQL server address + user: uptrace # Database user with full permissions + password: uptrace # Database password + database: uptrace # Database name (must exist) + + # TLS configuration for secure database connections + # Recommended for production deployments + #tls: + # insecure_skip_verify: true # WARNING: Only use for self-signed certificates + +# ----------------------------------------------------------------------------- +# ClickHouse Schema Configuration +# ----------------------------------------------------------------------------- +# Advanced schema settings for performance optimization +# WARNING: Changes require 'ch reset' command and will delete all data +ch_schema: + # Data compression algorithm for storage efficiency + # Options: + # - LZ4: Fast compression/decompression, moderate compression ratio + # - ZSTD(1): Better compression ratio, slightly slower + # - Default: ClickHouse default compression + compression: ZSTD(1) + + # Storage policies for different data types + # Allows using different storage tiers (SSD, HDD, S3) for different data + spans_index: { storage_policy: default } # Span search indexes + spans_data: { storage_policy: default } # Raw span data + span_links: { storage_policy: default } # Span relationship data + logs_index: { storage_policy: default } # Log search indexes + logs_data: { storage_policy: default } # Raw log data + events_index: { storage_policy: default } # Event search indexes + events_data: { storage_policy: default } # Raw event data + metrics: { storage_policy: default } # Metrics time-series data + +# ----------------------------------------------------------------------------- +# Redis Cache Configuration +# ----------------------------------------------------------------------------- +# In-memory cache for improved query performance and session storage +# Reduces database load and improves response times +redis_cache: + # Redis server addresses + # For cluster setup, add multiple addresses + addrs: + 1: redis:6379 + + # Redis authentication credentials + username: "" # Redis username (Redis 6.0+) + password: "" # Redis password + db: 15 # Redis database number (0-15) + + # TLS configuration for secure Redis connections + # Recommended for production deployments + #tls: + # insecure_skip_verify: true # WARNING: Only use for self-signed certificates + +# ----------------------------------------------------------------------------- +# SSL/TLS Certificate Management +# ----------------------------------------------------------------------------- +# Automatic certificate issuance and renewal via Let's Encrypt ACME protocol +certmagic: + enabled: false # Enable automatic certificate management + staging_ca: false # Use Let's Encrypt staging environment for testing + http_challenge_addr: :80 # Address for HTTP-01 challenge validation + +# ----------------------------------------------------------------------------- +# Email Configuration +# ----------------------------------------------------------------------------- +# SMTP configuration for alert notifications and user management emails +# Required for: password resets, alert notifications, user invitations +# Documentation: https://uptrace.dev/features/alerting +mailer: + smtp: + enabled: false # Enable email notifications + host: localhost # SMTP server hostname + port: 1025 # SMTP server port (25, 465, 587, 1025) + username: mailhog # SMTP authentication username + password: mailhog # SMTP authentication password + from: no-reply@uptrace.local # Sender email address (must be authorized) + + # TLS configuration + # Most production SMTP servers require TLS + #tls: { insecure: true } # Uncomment to disable opportunistic TLS + +# ----------------------------------------------------------------------------- +# Telemetry Data Processing Configuration +# ----------------------------------------------------------------------------- +# Performance tuning for different types of telemetry data ingestion + +# Spans (distributed tracing data) +# Contains trace information showing request flow across services +spans: + # Number of parallel processing threads + # Default: GOMAXPROCS (number of CPU cores) + # Increase for high-volume tracing workloads + #max_threads: 10 + + # Batch size for database insertions + # Larger batches improve throughput but increase memory usage + # Tune based on your ingestion rate and memory constraints + #max_insert_size: 10000 + + # In-memory buffer capacity for incoming spans + # Spans are dropped when buffer is full (check metrics for drops) + # Default scales with max_threads + #max_buffered_records: 100e3 + +# Span links (relationships between spans) +# Used for connecting spans across trace boundaries +span_links: + # Uncomment to disable span link processing + # This saves resources if you don't use span links + #disabled: true + + #max_threads: 10 # Processing parallelism + #max_insert_size: 10000 # Batch size for insertions + #max_buffered_records: 100e3 # Buffer capacity + +# Application logs +# Structured and unstructured log data from applications +logs: + #max_threads: 10 # Processing parallelism + #max_insert_size: 10000 # Batch size for insertions + #max_buffered_records: 100e3 # Buffer capacity + +# Custom events +# Application-specific events and business metrics +events: + #max_threads: 10 # Processing parallelism + #max_insert_size: 10000 # Batch size for insertions + #max_buffered_records: 100e3 # Buffer capacity + +# Metrics and time series data +# Numerical measurements over time (counters, gauges, histograms) +metrics: + #max_threads: 10 # Processing parallelism + #max_insert_size: 10000 # Batch size for insertions + #max_buffered_records: 100e3 # Buffer capacity + + # Memory limit for cumulative to delta conversion + # Affects processing of cumulative counters from OpenTelemetry + #max_cumulative_timeseries: 1e6 + +# ----------------------------------------------------------------------------- +# Query & Performance Limits +# ----------------------------------------------------------------------------- +# Resource limits to prevent expensive queries from affecting system performance + +# Trace query resource limits +trace: + # Maximum number of spans to return in a single query + # Prevents UI timeouts and excessive memory usage + # Users can adjust time ranges to stay within limits + #query_limit: 200_000 + + # Maximum memory usage per query (in bytes) + # Prevents OOM errors from complex queries + # Adjust based on available system memory + #max_memory_usage_bytes: 200_000_000 + +# ----------------------------------------------------------------------------- +# Feature Modules +# ----------------------------------------------------------------------------- +# Optional features that can be enabled/disabled for performance or security + +# Monitoring and alerting system +# Provides proactive monitoring with notifications +alerting: + # Uncomment to disable the entire alerting system + # This saves resources if you don't use monitoring alerts + #disabled: true + +# Service dependency graph generation +# Automatically builds service topology from trace data +service_graph: + # Uncomment to disable service graph processing + # This saves CPU and memory if you don't use the service map + #disabled: true + +# JavaScript error sourcemap processing +# Provides better error stack traces for frontend applications +# Requires internet access to download source maps from URLs +sourcemaps: + # Uncomment to disable sourcemap processing + # Disable in air-gapped environments or if not using JS error tracking + #disabled: true + +# ----------------------------------------------------------------------------- +# External Services +# ----------------------------------------------------------------------------- +# Integration with external services and self-monitoring + +# Internal telemetry collection +# Uptrace monitors itself and sends telemetry to the configured DSN +self_monitoring: + # Uncomment to disable self-monitoring + # This prevents Uptrace from generating its own telemetry data + #disabled: true + + # DSN for internal telemetry + # Format: http://project_token@host?grpc=port + # This can point to a project in this Uptrace instance or to the Uptrace Cloud + dsn: http://poop_token2@uptrace:14318?grpc=14317 + + #tls: + # insecure_skip_verify: true + +# Telegram bot for notifications +# Enables sending alert notifications to Telegram channels/users +# Setup guide: https://sendpulse.com/knowledge-base/chatbot/telegram/create-telegram-chatbot +telegram: + # Telegram bot token obtained from @BotFather + # Required for sending notifications to Telegram + bot_token: '' + +# ----------------------------------------------------------------------------- +# System Configuration +# ----------------------------------------------------------------------------- +# Global system settings and licensing + +# Application logging configuration +# Controls Uptrace's own log output (not application logs) +logging: + # Log level affects verbosity and performance + # DEBUG: Very verbose, use only for troubleshooting + # INFO: Standard operational information + # WARN: Warning messages and errors + # ERROR: Only error messages + level: INFO + +# Premium features license +# Enables advanced features like distributed tables, SSO, etc. +# Details: https://uptrace.dev/get/hosted#premium-edition +license: + # Premium license key from Uptrace + # Required for enterprise features + key: '' diff --git a/docs/docs.go b/docs/docs.go new file mode 100644 index 0000000..38188f4 --- /dev/null +++ b/docs/docs.go @@ -0,0 +1,40 @@ +// Package docs Code generated by swaggo/swag. DO NOT EDIT +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "termsOfService": "http://swagger.io/terms", + "contact": {}, + "license": { + "name": "0BSD" + }, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": {} +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "0.0.1", + Host: "", + BasePath: "/", + Schemes: []string{}, + Title: "Golang 2025 Final Project", + Description: "", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..14e1fdf --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,14 @@ +{ + "swagger": "2.0", + "info": { + "title": "Golang 2025 Final Project", + "termsOfService": "http://swagger.io/terms", + "contact": {}, + "license": { + "name": "0BSD" + }, + "version": "0.0.1" + }, + "basePath": "/", + "paths": {} +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..a1c3528 --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,10 @@ +basePath: / +info: + contact: {} + license: + name: 0BSD + termsOfService: http://swagger.io/terms + title: Golang 2025 Final Project + version: 0.0.1 +paths: {} +swagger: "2.0" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5607f7d --- /dev/null +++ b/go.mod @@ -0,0 +1,68 @@ +module gitea.konchin.com/go2025/backend + +go 1.25.4 + +require ( + github.com/spf13/cobra v1.10.2 + github.com/spf13/viper v1.21.0 + github.com/swaggo/swag v1.16.6 + github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.2 + github.com/uptrace/uptrace-go v1.38.0 + go.opentelemetry.io/otel v1.38.0 + go.opentelemetry.io/otel/trace v1.38.0 + go.uber.org/zap v1.27.1 +) + +require ( + github.com/KyleBanks/depth v1.2.1 // indirect + github.com/PuerkitoBio/purell v1.1.1 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/cenkalti/backoff/v5 v5.0.3 // indirect + github.com/fsnotify/fsnotify v1.9.0 // indirect + github.com/go-logr/logr v1.4.3 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.19.6 // indirect + github.com/go-openapi/spec v0.20.4 // indirect + github.com/go-openapi/swag v0.19.15 // indirect + github.com/go-viper/mapstructure/v2 v2.4.0 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/mailru/easyjson v0.7.6 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/sagikazarmark/locafero v0.11.0 // indirect + github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect + github.com/spf13/afero v1.15.0 // indirect + github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2 // indirect + go.opentelemetry.io/auto/sdk v1.2.1 // indirect + go.opentelemetry.io/contrib/instrumentation/runtime v0.63.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.14.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.38.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 // indirect + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.38.0 // indirect + go.opentelemetry.io/otel/log v0.14.0 // indirect + go.opentelemetry.io/otel/metric v1.38.0 // indirect + go.opentelemetry.io/otel/sdk v1.38.0 // indirect + go.opentelemetry.io/otel/sdk/log v0.14.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.38.0 // indirect + go.opentelemetry.io/proto/otlp v1.8.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect + golang.org/x/mod v0.27.0 // indirect + golang.org/x/net v0.44.0 // indirect + golang.org/x/sync v0.17.0 // indirect + golang.org/x/sys v0.36.0 // indirect + golang.org/x/text v0.29.0 // indirect + golang.org/x/tools v0.36.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20250908214217-97024824d090 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 // indirect + google.golang.org/grpc v1.75.1 // indirect + google.golang.org/protobuf v1.36.9 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b15dcd9 --- /dev/null +++ b/go.sum @@ -0,0 +1,176 @@ +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM= +github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= +github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= +github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= +github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= +github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 h1:8Tjv8EJ+pM1xP8mK6egEbD1OgnVTyacbefKhmbLhIhU= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2/go.mod h1:pkJQ2tZHJ0aFOVEEot6oZmaVEZcRme73eIFmhiVuRWs= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc= +github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= +github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= +github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= +github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/swaggo/swag v1.16.6 h1:qBNcx53ZaX+M5dxVyTrgQ0PJ/ACK+NzhwcbieTt+9yI= +github.com/swaggo/swag v1.16.6/go.mod h1:ngP2etMK5a0P3QBizic5MEwpRmluJZPHjXcMoj4Xesg= +github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2 h1:3/aHKUq7qaFMWxyQV0W2ryNgg8x8rVeKVA20KJUkfS0= +github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.2/go.mod h1:Zit4b8AQXaXvA68+nzmbyDzqiyFRISyw1JiD5JqUBjw= +github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.2 h1:cj/Z6FKTTYBnstI0Lni9PA+k2foounKIPUmj1LBwNiQ= +github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.2/go.mod h1:LDaXk90gKEC2nC7JH3Lpnhfu+2V7o/TsqomJJmqA39o= +github.com/uptrace/uptrace-go v1.38.0 h1:QdJfyQkaz7HNPbqM9OkaQ2L9jfdf0DpfZJv9em7YIgE= +github.com/uptrace/uptrace-go v1.38.0/go.mod h1:SdE9nA+/y+SOIzatuIK2tZeYhoWgrAzAr08kJEquZyM= +go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= +go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= +go.opentelemetry.io/contrib/instrumentation/runtime v0.63.0 h1:PeBoRj6af6xMI7qCupwFvTbbnd49V7n5YpG6pg8iDYQ= +go.opentelemetry.io/contrib/instrumentation/runtime v0.63.0/go.mod h1:ingqBCtMCe8I4vpz/UVzCW6sxoqgZB37nao91mLQ3Bw= +go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8= +go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.14.0 h1:QQqYw3lkrzwVsoEX0w//EhH/TCnpRdEenKBOOEIMjWc= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.14.0/go.mod h1:gSVQcr17jk2ig4jqJ2DX30IdWH251JcNAecvrqTxH1s= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.38.0 h1:Oe2z/BCg5q7k4iXC3cqJxKYg0ieRiOqF0cecFYdPTwk= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.38.0/go.mod h1:ZQM5lAJpOsKnYagGg/zV2krVqTtaVdYdDkhMoX6Oalg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 h1:GqRJVj7UmLjCVyVJ3ZFLdPRmhDUp2zFmQe3RHIOsw24= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0/go.mod h1:ri3aaHSmCTVYu2AWv44YMauwAQc0aqI9gHKIcSbI1pU= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 h1:aTL7F04bJHUlztTsNGJ2l+6he8c+y/b//eR0jjjemT4= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0/go.mod h1:kldtb7jDTeol0l3ewcmd8SDvx3EmIE7lyvqbasU3QC4= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.38.0 h1:kJxSDN4SgWWTjG/hPp3O7LCGLcHXFlvS2/FFOrwL+SE= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.38.0/go.mod h1:mgIOzS7iZeKJdeB8/NYHrJ48fdGc71Llo5bJ1J4DWUE= +go.opentelemetry.io/otel/log v0.14.0 h1:2rzJ+pOAZ8qmZ3DDHg73NEKzSZkhkGIua9gXtxNGgrM= +go.opentelemetry.io/otel/log v0.14.0/go.mod h1:5jRG92fEAgx0SU/vFPxmJvhIuDU9E1SUnEQrMlJpOno= +go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA= +go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI= +go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E= +go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg= +go.opentelemetry.io/otel/sdk/log v0.14.0 h1:JU/U3O7N6fsAXj0+CXz21Czg532dW2V4gG1HE/e8Zrg= +go.opentelemetry.io/otel/sdk/log v0.14.0/go.mod h1:imQvII+0ZylXfKU7/wtOND8Hn4OpT3YUoIgqJVksUkM= +go.opentelemetry.io/otel/sdk/log/logtest v0.14.0 h1:Ijbtz+JKXl8T2MngiwqBlPaHqc4YCaP/i13Qrow6gAM= +go.opentelemetry.io/otel/sdk/log/logtest v0.14.0/go.mod h1:dCU8aEL6q+L9cYTqcVOk8rM9Tp8WdnHOPLiBgp0SGOA= +go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM= +go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA= +go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE= +go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs= +go.opentelemetry.io/proto/otlp v1.8.0 h1:fRAZQDcAFHySxpJ1TwlA1cJ4tvcrw7nXl9xWWC8N5CE= +go.opentelemetry.io/proto/otlp v1.8.0/go.mod h1:tIeYOeNBU4cvmPqpaji1P+KbB4Oloai8wN4rWzRrFF0= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc= +go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ= +golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc= +golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= +golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I= +golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= +golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg= +golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s= +gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= +gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= +google.golang.org/genproto/googleapis/api v0.0.0-20250908214217-97024824d090 h1:d8Nakh1G+ur7+P3GcMjpRDEkoLUcLW2iU92XVqR+XMQ= +google.golang.org/genproto/googleapis/api v0.0.0-20250908214217-97024824d090/go.mod h1:U8EXRNSd8sUYyDfs/It7KVWodQr+Hf9xtxyxWudSwEw= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 h1:/OQuEa4YWtDt7uQWHd3q3sUMb+QOLQUg1xa8CEsRv5w= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090/go.mod h1:GmFNa4BdJZ2a8G+wCe9Bg3wwThLrJun751XstdJt5Og= +google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI= +google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ= +google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw= +google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go.work b/go.work new file mode 100644 index 0000000..64f7a09 --- /dev/null +++ b/go.work @@ -0,0 +1,3 @@ +go 1.25.4 + +use . diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 0000000..da0b2fc --- /dev/null +++ b/go.work.sum @@ -0,0 +1,7 @@ +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY= +golang.org/x/telemetry v0.0.0-20250710130107-8d8967aff50b/go.mod h1:4ZwOYna0/zsOKwuR5X/m0QFOJpSZvAxFfkQT+Erd9D4= +golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/tracing/tracer.go b/tracing/tracer.go new file mode 100644 index 0000000..b58ed5f --- /dev/null +++ b/tracing/tracer.go @@ -0,0 +1,47 @@ +package tracing + +import ( + "context" + + "github.com/spf13/viper" + "github.com/uptrace/opentelemetry-go-extra/otelzap" + "github.com/uptrace/uptrace-go/uptrace" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/trace" + "go.uber.org/zap" +) + +var ( + Tracer trace.Tracer + Logger *otelzap.Logger + + version string = "v0.0.1" +) + +func InitTracer(appname string) { + Tracer = otel.Tracer(appname) + + var l *zap.Logger + var err error + if viper.GetBool("zap-production") { + l, err = zap.NewProduction() + } else { + l, err = zap.NewDevelopment() + } + if err != nil { + panic(err) + } + Logger = otelzap.New(l) +} + +func InitUptrace(appname string) { + uptrace.ConfigureOpentelemetry( + uptrace.WithDSN(viper.GetString("uptrace-dsn")), + uptrace.WithServiceName(appname), + uptrace.WithServiceVersion(version), + ) +} + +func DeferUptrace(ctx context.Context) { + uptrace.Shutdown(ctx) +}