支持手动指定品种和日期进行打分
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -7,21 +7,23 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ListenAddr string
|
||||
DatabaseURL string
|
||||
AuthDBPath string
|
||||
JWTSecret []byte
|
||||
AdminUser string
|
||||
AdminPass string
|
||||
ListenAddr string
|
||||
DatabaseURL string
|
||||
AuthDBPath string
|
||||
JWTSecret []byte
|
||||
AdminUser string
|
||||
AdminPass string
|
||||
TushareAPIURL string
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
cfg := &Config{
|
||||
ListenAddr: getenv("LISTEN_ADDR", ":8080"),
|
||||
DatabaseURL: os.Getenv("DATABASE_URL"),
|
||||
AuthDBPath: getenv("AUTH_DB_PATH", "/app/auth/auth.db"),
|
||||
AdminUser: strings.TrimSpace(os.Getenv("ADMIN_USER")),
|
||||
AdminPass: os.Getenv("ADMIN_PASS"),
|
||||
ListenAddr: getenv("LISTEN_ADDR", ":8080"),
|
||||
DatabaseURL: os.Getenv("DATABASE_URL"),
|
||||
AuthDBPath: getenv("AUTH_DB_PATH", "/app/auth/auth.db"),
|
||||
AdminUser: strings.TrimSpace(os.Getenv("ADMIN_USER")),
|
||||
AdminPass: os.Getenv("ADMIN_PASS"),
|
||||
TushareAPIURL: getenv("TUSHARE_API_URL", "http://tushare:8000"),
|
||||
}
|
||||
if cfg.DatabaseURL == "" {
|
||||
return nil, fmt.Errorf("DATABASE_URL 环境变量未设置")
|
||||
|
||||
@@ -11,9 +11,10 @@ import (
|
||||
|
||||
// Deps 是所有 handler 需要的运行时依赖,在 router 装配时一次性注入。
|
||||
type Deps struct {
|
||||
Auth *store.AuthStore
|
||||
Futures *store.FuturesStore
|
||||
JWT *auth.Manager
|
||||
Auth *store.AuthStore
|
||||
Futures *store.FuturesStore
|
||||
JWT *auth.Manager
|
||||
TushareURL string
|
||||
}
|
||||
|
||||
func writeJSON(w http.ResponseWriter, status int, body any) {
|
||||
|
||||
42
web/backend/internal/handlers/run.go
Normal file
42
web/backend/internal/handlers/run.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type runRequest struct {
|
||||
TsCode string `json:"ts_code,omitempty"`
|
||||
Symbol string `json:"symbol,omitempty"`
|
||||
TradeDate string `json:"trade_date,omitempty"`
|
||||
}
|
||||
|
||||
func (d *Deps) RunPipeline(w http.ResponseWriter, r *http.Request) {
|
||||
var req runRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
writeErr(w, http.StatusBadRequest, "invalid json")
|
||||
return
|
||||
}
|
||||
|
||||
body, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusInternalServerError, "encode request failed")
|
||||
return
|
||||
}
|
||||
|
||||
client := &http.Client{Timeout: 60 * time.Second}
|
||||
resp, err := client.Post(d.TushareURL+"/api/v1/run", "application/json", bytes.NewReader(body))
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusBadGateway, fmt.Sprintf("tushare service unavailable: %v", err))
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
_, _ = io.Copy(w, resp.Body)
|
||||
}
|
||||
@@ -30,6 +30,7 @@ func New(d *handlers.Deps, mgr *auth.Manager, authStore *store.AuthStore, dist f
|
||||
r.Get("/scores/{id}", d.GetScore)
|
||||
r.Get("/contracts", d.ListContracts)
|
||||
r.Get("/candles", d.ListCandles)
|
||||
r.Post("/run", d.RunPipeline)
|
||||
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(mw.RequireAdmin)
|
||||
|
||||
@@ -41,7 +41,7 @@ func main() {
|
||||
}
|
||||
|
||||
mgr := auth.NewManager(cfg.JWTSecret)
|
||||
deps := &handlers.Deps{Auth: authDB, Futures: futures, JWT: mgr}
|
||||
deps := &handlers.Deps{Auth: authDB, Futures: futures, JWT: mgr, TushareURL: cfg.TushareAPIURL}
|
||||
|
||||
dist, err := fs.Sub(distFS, "dist")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user