Compare commits
2 Commits
0b5b26d5b0
...
e8fcd550c1
| Author | SHA1 | Date | |
|---|---|---|---|
| e8fcd550c1 | |||
| 5b7ec80473 |
@ -509,15 +509,15 @@ func resolveIssuedAtInBucket(db *sql.DB, stationID, provider string, bucketHour
|
|||||||
func loadForecastSamples(db *sql.DB, stationID, provider string, issued time.Time) ([]forecastSample, error) {
|
func loadForecastSamples(db *sql.DB, stationID, provider string, issued time.Time) ([]forecastSample, error) {
|
||||||
const q = `
|
const q = `
|
||||||
SELECT forecast_time,
|
SELECT forecast_time,
|
||||||
rain_mm_x1000,
|
COALESCE(rain_mm_x1000, 0),
|
||||||
temp_c_x100,
|
COALESCE(temp_c_x100, 0),
|
||||||
humidity_pct,
|
COALESCE(humidity_pct, 0),
|
||||||
wind_speed_ms_x1000,
|
COALESCE(wind_speed_ms_x1000, 0),
|
||||||
wind_gust_ms_x1000,
|
COALESCE(wind_gust_ms_x1000, 0),
|
||||||
wind_dir_deg,
|
COALESCE(wind_dir_deg, 0),
|
||||||
precip_prob_pct,
|
COALESCE(precip_prob_pct, 0),
|
||||||
pressure_hpa_x100,
|
COALESCE(pressure_hpa_x100, 0),
|
||||||
uv_index
|
COALESCE(uv_index, 0)
|
||||||
FROM forecast_hourly
|
FROM forecast_hourly
|
||||||
WHERE station_id=$1 AND provider=$2 AND issued_at=$3
|
WHERE station_id=$1 AND provider=$2 AND issued_at=$3
|
||||||
ORDER BY forecast_time ASC`
|
ORDER BY forecast_time ASC`
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"weatherstation/internal/config"
|
"weatherstation/internal/config"
|
||||||
@ -22,27 +23,51 @@ func StartGinServer() error {
|
|||||||
// 创建Gin引擎
|
// 创建Gin引擎
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
||||||
// 加载HTML模板
|
// 解析资源路径,兼容在仓库根目录或 bin/ 目录启动
|
||||||
r.LoadHTMLGlob("templates/*")
|
tplGlob := filepath.Join("templates", "*")
|
||||||
|
if _, err := os.Stat("templates"); os.IsNotExist(err) {
|
||||||
|
if _, err2 := os.Stat("../templates"); err2 == nil {
|
||||||
|
tplGlob = filepath.Join("..", "templates", "*")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.LoadHTMLGlob(tplGlob)
|
||||||
|
|
||||||
// 静态文件服务
|
staticDir := "./static"
|
||||||
r.Static("/static", "./static")
|
if _, err := os.Stat(staticDir); os.IsNotExist(err) {
|
||||||
|
if _, err2 := os.Stat("../static"); err2 == nil {
|
||||||
|
staticDir = "../static"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.Static("/static", staticDir)
|
||||||
|
|
||||||
// 前端SPA(Angular)静态资源与路由回退
|
// 前端SPA(Angular)静态资源与路由回退
|
||||||
// 构建产物目录:./core/frontend/dist/ui
|
// 构建产物目录:./core/frontend/dist/ui(兼容 ../core/frontend/dist/ui)
|
||||||
r.GET("/ui/*filepath", func(c *gin.Context) {
|
r.GET("/ui/*filepath", func(c *gin.Context) {
|
||||||
// 物理文件优先,否则回退到 index.html(支持前端路由)
|
// 物理文件优先,否则回退到 index.html(支持前端路由)
|
||||||
requested := c.Param("filepath")
|
requested := c.Param("filepath")
|
||||||
if requested == "" || requested == "/" {
|
if requested == "" || requested == "/" {
|
||||||
c.File("./core/frontend/dist/ui/index.html")
|
base := "./core/frontend/dist/ui/index.html"
|
||||||
|
if _, err := os.Stat(base); os.IsNotExist(err) {
|
||||||
|
alt := "../core/frontend/dist/ui/index.html"
|
||||||
|
if _, err2 := os.Stat(alt); err2 == nil {
|
||||||
|
base = alt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.File(base)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
full := ".//core/frontend/dist/ui" + requested
|
baseDir := "./core/frontend/dist/ui"
|
||||||
|
if _, err := os.Stat(baseDir); os.IsNotExist(err) {
|
||||||
|
if _, err2 := os.Stat("../core/frontend/dist/ui"); err2 == nil {
|
||||||
|
baseDir = "../core/frontend/dist/ui"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
full := baseDir + requested
|
||||||
if _, err := os.Stat(full); err == nil {
|
if _, err := os.Stat(full); err == nil {
|
||||||
c.File(full)
|
c.File(full)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.File("./core/frontend/dist/ui/index.html")
|
c.File(filepath.Join(baseDir, "index.html"))
|
||||||
})
|
})
|
||||||
|
|
||||||
// 路由设置
|
// 路由设置
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user