fix startTime

This commit is contained in:
aichy126 2022-11-08 11:33:48 +08:00
parent a29eca4a4d
commit 607573d386
3 changed files with 11 additions and 1 deletions

View File

@ -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 {

View File

@ -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"`

View File

@ -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)