@@ -427,6 +427,12 @@ func (s *Server) startLiq(w http.ResponseWriter, r *http.Request) {
427427 ctx := r .Context ()
428428 slug := chi .URLParam (r , "slug" )
429429
430+ station , err := s .db .Q ().Station (ctx , slug )
431+ if err != nil {
432+ http .Error (w , err .Error (), http .StatusInternalServerError )
433+ return
434+ }
435+
430436 cli , err := client .NewClientWithOpts (client .FromEnv , client .WithAPIVersionNegotiation ())
431437 if err != nil {
432438 http .Error (w , err .Error (), http .StatusInternalServerError )
@@ -507,12 +513,22 @@ func (s *Server) startLiq(w http.ResponseWriter, r *http.Request) {
507513
508514 resp , err := cli .ContainerInspect (ctx , response .ID )
509515 if err != nil {
510- panic (err )
516+ http .Error (w , err .Error (), http .StatusInternalServerError )
517+ return
511518 }
512519 for containerPort , bindings := range resp .NetworkSettings .Ports {
513520 fmt .Println ("containerPort" , containerPort )
514- for _ , binding := range bindings {
515- fmt .Printf ("Container port %s is bound to host port %s\n " , containerPort , binding .HostPort )
521+ if containerPort .Port () == "1234" {
522+ var hostPort string
523+ if len (bindings ) == 1 {
524+ hostPort = bindings [0 ].HostPort
525+ }
526+ err := s .db .Q ().SetStationHostPort (ctx , hostPort , station .StationID )
527+ if err != nil {
528+ http .Error (w , err .Error (), http .StatusInternalServerError )
529+ return
530+ }
531+ fmt .Printf ("station %s host port=%s\n " , station .Slug , hostPort )
516532 }
517533 }
518534
0 commit comments