diff --git a/cmd/answer/main.go b/cmd/answer/main.go index e9308442..da836a5d 100644 --- a/cmd/answer/main.go +++ b/cmd/answer/main.go @@ -3,10 +3,12 @@ package main import ( "os" "path/filepath" + "time" "github.com/answerdev/answer/internal/base/conf" "github.com/answerdev/answer/internal/base/constant" "github.com/answerdev/answer/internal/cli" + "github.com/answerdev/answer/internal/schema" "github.com/gin-gonic/gin" "github.com/segmentfault/pacman" "github.com/segmentfault/pacman/contrib/conf/viper" @@ -51,6 +53,7 @@ func runApp() { panic(err) } constant.Version = Version + schema.AppStartTime = time.Now() defer cleanup() if err := app.Run(); err != nil { diff --git a/internal/schema/dashboard_schema.go b/internal/schema/dashboard_schema.go index bba29da1..2f5b3622 100644 --- a/internal/schema/dashboard_schema.go +++ b/internal/schema/dashboard_schema.go @@ -1,5 +1,9 @@ package schema +import "time" + +var AppStartTime time.Time + type DashboardInfo struct { QuestionCount int64 `json:"question_count"` AnswerCount int64 `json:"answer_count"` diff --git a/internal/service/dashboard/dashboard_service.go b/internal/service/dashboard/dashboard_service.go index fda3d646..aa876507 100644 --- a/internal/service/dashboard/dashboard_service.go +++ b/internal/service/dashboard/dashboard_service.go @@ -3,8 +3,10 @@ package dashboard import ( "context" "encoding/json" + "fmt" "io/ioutil" "net/http" + "time" "github.com/answerdev/answer/internal/base/constant" "github.com/answerdev/answer/internal/base/reason" @@ -124,7 +126,8 @@ func (ds *DashboardService) Statistical(ctx context.Context) (*schema.DashboardI } dashboardInfo.HTTPS = true dashboardInfo.OccupyingStorageSpace = "1MB" - dashboardInfo.AppStartTime = "102" + startTime := time.Now().Unix() - schema.AppStartTime.Unix() + dashboardInfo.AppStartTime = fmt.Sprintf("%d", startTime) dashboardInfo.TimeZone = siteInfoInterface.TimeZone dashboardInfo.VersionInfo.Version = constant.Version dashboardInfo.VersionInfo.RemoteVersion = ds.RemoteVersion(ctx)