package main import ( "context" "lingniu/vehicle-data-platform/apps/api/internal/gzev" "log" "net/http" "os" "os/signal" "syscall" "time" ) func main() { path := os.Getenv("GZEV_SESSION_FILE") if path == "" { path = "/var/lib/lingniu-gzev/session.json" } account := os.Getenv("GZEV_ACCOUNT") if account == "" { account = "guangdonglingniu" } handler, err := gzev.NewUploadHandler(path, account) if err != nil { log.Fatal("cannot initialize upload handler") } handler.PublicOrigin = "https://vehicle.d.lnoneos.com" handler.RecoveryPath = path + ".recovery.json" addr := os.Getenv("GZEV_UPLOAD_ADDR") if addr == "" { addr = "127.0.0.1:20312" } server := &http.Server{Addr: addr, Handler: handler, ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 15 * time.Second, WriteTimeout: 40 * time.Second, IdleTimeout: 30 * time.Second, MaxHeaderBytes: 8192} ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer cancel() go func() { <-ctx.Done() stop, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() server.Shutdown(stop) }() if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { log.Fatal("upload service stopped unexpectedly") } }