feat(platform): connect mysql production store
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"lingniu/vehicle-data-platform/apps/api/internal/config"
|
||||
"lingniu/vehicle-data-platform/apps/api/internal/platform"
|
||||
@@ -9,7 +12,18 @@ import (
|
||||
)
|
||||
|
||||
func NewServer(cfg config.Config) http.Handler {
|
||||
store := platform.NewMockStore()
|
||||
var store platform.Store = platform.NewMockStore()
|
||||
if cfg.MySQLDSN != "" {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
db, err := platform.OpenMySQL(ctx, cfg.MySQLDSN)
|
||||
if err != nil {
|
||||
log.Printf("production mysql store disabled: %v", err)
|
||||
} else {
|
||||
store = platform.NewProductionStore(db, cfg.TDengineDatabase)
|
||||
log.Printf("production mysql store enabled")
|
||||
}
|
||||
}
|
||||
api := platform.NewHandler(platform.NewService(store))
|
||||
return static.Handler(cfg.StaticDir, api)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user