This commit is contained in:
@@ -2,7 +2,7 @@ name: lanhu
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:17
|
image: postgres:17.7
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: ${DB_USERNAME}
|
POSTGRES_USER: ${DB_USERNAME}
|
||||||
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||||
|
|||||||
6
pkg/env/env.go
vendored
6
pkg/env/env.go
vendored
@@ -36,6 +36,9 @@ var (
|
|||||||
RedisPort = "6379"
|
RedisPort = "6379"
|
||||||
RedisPassword = ""
|
RedisPassword = ""
|
||||||
|
|
||||||
|
OtelHost string
|
||||||
|
OtelPort string
|
||||||
|
|
||||||
BaiyinCloudUrl string
|
BaiyinCloudUrl string
|
||||||
BaiyinTokenUrl string
|
BaiyinTokenUrl string
|
||||||
|
|
||||||
@@ -115,6 +118,9 @@ func Init() {
|
|||||||
errs = append(errs, parse(&RedisPort, "REDIS_PORT", true, nil))
|
errs = append(errs, parse(&RedisPort, "REDIS_PORT", true, nil))
|
||||||
errs = append(errs, parse(&RedisPassword, "REDIS_PASS", true, nil))
|
errs = append(errs, parse(&RedisPassword, "REDIS_PASS", true, nil))
|
||||||
|
|
||||||
|
errs = append(errs, parse(&OtelHost, "OTEL_HOST", true, nil))
|
||||||
|
errs = append(errs, parse(&OtelPort, "OTEL_PORT", true, nil))
|
||||||
|
|
||||||
errs = append(errs, parse(&BaiyinCloudUrl, "BAIYIN_CLOUD_URL", false, nil))
|
errs = append(errs, parse(&BaiyinCloudUrl, "BAIYIN_CLOUD_URL", false, nil))
|
||||||
errs = append(errs, parse(&BaiyinTokenUrl, "BAIYIN_TOKEN_URL", false, nil))
|
errs = append(errs, parse(&BaiyinTokenUrl, "BAIYIN_TOKEN_URL", false, nil))
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package globals
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"platform/pkg/env"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
|
||||||
@@ -16,8 +17,13 @@ import (
|
|||||||
var tp *trace.TracerProvider
|
var tp *trace.TracerProvider
|
||||||
|
|
||||||
func initOtel(ctx context.Context) error {
|
func initOtel(ctx context.Context) error {
|
||||||
|
if env.OtelHost == "" || env.OtelPort == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
addr := env.OtelHost + ":" + env.OtelPort
|
||||||
exporter, err := otlptracegrpc.New(ctx,
|
exporter, err := otlptracegrpc.New(ctx,
|
||||||
otlptracegrpc.WithEndpoint("localhost:4317"),
|
otlptracegrpc.WithEndpoint(addr),
|
||||||
otlptracegrpc.WithInsecure(),
|
otlptracegrpc.WithInsecure(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -353,21 +353,10 @@ func StatisticResourceUsage(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 统计套餐提取数量
|
// 统计套餐提取数量
|
||||||
do := q.LogsUserUsage.Where(q.LogsUserUsage.UserID.Eq(authCtx.User.ID))
|
do := q.LogsUserUsage.Where(
|
||||||
if req.ResourceNo != nil && *req.ResourceNo != "" {
|
q.LogsUserUsage.UserID.Eq(authCtx.User.ID),
|
||||||
var resourceID int32
|
)
|
||||||
err := q.Resource.
|
|
||||||
Where(
|
|
||||||
q.Resource.UserID.Eq(authCtx.User.ID),
|
|
||||||
q.Resource.ResourceNo.Eq(*req.ResourceNo),
|
|
||||||
).
|
|
||||||
Select(q.Resource.ID).
|
|
||||||
Scan(&resourceID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
do.Where(q.LogsUserUsage.ResourceID.Eq(resourceID))
|
|
||||||
}
|
|
||||||
if req.TimeAfter != nil {
|
if req.TimeAfter != nil {
|
||||||
do.Where(q.LogsUserUsage.Time.Gte(*req.TimeAfter))
|
do.Where(q.LogsUserUsage.Time.Gte(*req.TimeAfter))
|
||||||
}
|
}
|
||||||
@@ -383,7 +372,7 @@ func StatisticResourceUsage(c *fiber.Ctx) error {
|
|||||||
).
|
).
|
||||||
Where(do).
|
Where(do).
|
||||||
Group(
|
Group(
|
||||||
field.NewUnsafeFieldRaw("date_trunc('day', time)"),
|
field.NewField("", "date"),
|
||||||
).
|
).
|
||||||
Order(
|
Order(
|
||||||
field.NewField("", "date").Desc(),
|
field.NewField("", "date").Desc(),
|
||||||
@@ -397,9 +386,8 @@ func StatisticResourceUsage(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StatisticResourceUsageReq struct {
|
type StatisticResourceUsageReq struct {
|
||||||
ResourceNo *string `json:"resource_no"`
|
TimeAfter *time.Time `json:"time_start"`
|
||||||
TimeAfter *time.Time `json:"time_after"`
|
TimeBefore *time.Time `json:"time_end"`
|
||||||
TimeBefore *time.Time `json:"time_before"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatisticResourceUsageResp []struct {
|
type StatisticResourceUsageResp []struct {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"platform/pkg/env"
|
||||||
auth2 "platform/web/auth"
|
auth2 "platform/web/auth"
|
||||||
"platform/web/handlers"
|
"platform/web/handlers"
|
||||||
|
|
||||||
@@ -86,7 +87,9 @@ func ApplyRouters(app *fiber.App) {
|
|||||||
callbacks.Get("/identify", handlers.IdentifyCallbackNew)
|
callbacks.Get("/identify", handlers.IdentifyCallbackNew)
|
||||||
|
|
||||||
// 临时
|
// 临时
|
||||||
|
if env.RunMode == env.RunModeDev {
|
||||||
debug := app.Group("/debug")
|
debug := app.Group("/debug")
|
||||||
debug.Get("/sms/:phone", handlers.DebugGetSmsCode)
|
debug.Get("/sms/:phone", handlers.DebugGetSmsCode)
|
||||||
debug.Get("/proxy/register", handlers.DebugRegisterProxyBaiYin)
|
debug.Get("/proxy/register", handlers.DebugRegisterProxyBaiYin)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user