feat: add total player count and total playtime logic
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 1m27s

- Implemented TotalPlayerCountLogic to retrieve the total number of unique players within a specified time range.
- Implemented TotalPlayTimeLogic to calculate the total playtime of players within a specified time range.
- Created ServiceContext to manage database connections and initialize necessary tables.
- Added types for total player count and total playtime requests and responses.
- Set up the main server file to start the application with the necessary configurations.
- Updated go.mod and go.sum for new dependencies.
This commit is contained in:
2025-10-12 11:20:34 +08:00
parent 18f1f6f38c
commit ecf835068a
37 changed files with 89 additions and 89 deletions

View File

@@ -5,19 +5,19 @@ FROM golang:1.24.4-alpine AS builder
RUN apk add --no-cache git
# Set working directory
WORKDIR /app
WORKDIR /build
# Copy go mod files from src directory
COPY src/go.mod src/go.sum ./
# Copy go mod files from root directory
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code from src directory
COPY src/ .
# Copy the entire app directory to maintain the module structure
COPY app/ ./app/
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o serverstatistics serverstatistics.go
# Build the application from the app directory
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o serverstatistics ./app/serverstatistics.go
# Production stage
FROM alpine:latest
@@ -28,13 +28,13 @@ RUN apk --no-cache add ca-certificates
WORKDIR /root/
# Copy binary from builder
COPY --from=builder /app/serverstatistics .
COPY --from=builder /build/serverstatistics .
# Copy config file
COPY --from=builder /app/etc/serverstatistics.yaml ./etc/
COPY app/etc/serverstatistics.yaml ./etc/
# Expose port
EXPOSE 8888
# Run the application
CMD ["./serverstatistics", "-f", "etc/serverstatistics.yaml"]
CMD ["./serverstatistics", "-f", "etc/serverstatistics.yaml"]

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Ping the server to check if it's alive

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get recent chat messages within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get recent players who joined within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get recent player joins within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get recent players who played within a specified time range

View File

@@ -6,7 +6,7 @@ package handler
import (
"net/http"
"src/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"github.com/zeromicro/go-zero/rest"
)

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get the list of monitored game servers

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get top players by kill count within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get top players by playtime within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get total chat message count within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get total connect count within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get total damage count within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get total kill count within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get total player count within a specified time range

View File

@@ -3,10 +3,10 @@ package handler
import (
"net/http"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/logic"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"src/internal/logic"
"src/internal/svc"
"src/internal/types"
)
// Get total playtime within a specified time range

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -4,8 +4,8 @@ import (
"context"
"fmt"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -4,8 +4,8 @@ import (
"context"
"fmt"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -4,8 +4,8 @@ import (
"context"
"fmt"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
"src/internal/svc"
"src/internal/types"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -4,7 +4,7 @@ import (
"database/sql"
"log"
"src/internal/config"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/config"
_ "github.com/lib/pq" // PostgreSQL driver
)

View File

@@ -4,9 +4,9 @@ import (
"flag"
"fmt"
"src/internal/config"
"src/internal/handler"
"src/internal/svc"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/config"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/handler"
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"

View File

@@ -1,10 +1,10 @@
module src
module git.cialloo.com/CiallooWeb/ServerStatistics
go 1.24.4
require (
github.com/lib/pq v1.10.9
github.com/zeromicro/go-zero v1.9.1
github.com/zeromicro/go-zero v1.9.2
)
require (

View File

@@ -76,8 +76,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
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/zeromicro/go-zero v1.9.1 h1:GZCl4jun/ZgZHnSvX3SSNDHf+tEGmEQ8x2Z23xjHa9g=
github.com/zeromicro/go-zero v1.9.1/go.mod h1:bHOl7Xr7EV/iHZWEqsUNJwFc/9WgAMrPpPagYvOaMtY=
github.com/zeromicro/go-zero v1.9.2 h1:ZXOXBIcazZ1pWAMiHyVnDQ3Sxwy7DYPzjE89Qtj9vqM=
github.com/zeromicro/go-zero v1.9.2/go.mod h1:k8YBMEFZKjTd4q/qO5RCW+zDgUlNyAs5vue3P4/Kmn0=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=