@@ -31,6 +31,7 @@ func ConnectToHost(ctx context.Context, config ConnectionConfig) (*Client, error
3131 dial : d .DialContext ,
3232 privateKey : config .PrivKey ,
3333 }
34+ fmt .Printf ("local_ip: %s, public_ip: %s\n " , localIP , publicIP )
3435 err := sshClient .Connect (ctx )
3536 if err != nil {
3637 return nil , fmt .Errorf ("failed to connect: %w" , err )
@@ -96,7 +97,11 @@ func (c *Client) runCommand(ctx context.Context, cmd string) (string, string, er
9697 if err != nil {
9798 return "" , "" , fmt .Errorf ("failed to create session, try a new connection: %w" , err )
9899 }
99- defer sess .Close ()
100+ defer func () {
101+ if err := sess .Close (); err != nil {
102+ fmt .Printf ("failed to close session: %v\n " , err )
103+ }
104+ }()
100105
101106 var stdOutBuffer bytes.Buffer
102107 sess .Stdout = & stdOutBuffer
@@ -404,7 +409,11 @@ func GetLocalIP(ctx context.Context) (net.IP, error) {
404409 if err != nil {
405410 return nil , fmt .Errorf ("failed to dial for local IP: %w" , err )
406411 }
407- defer conn .Close ()
412+ defer func () {
413+ if err := conn .Close (); err != nil {
414+ fmt .Printf ("failed to close connection: %v\n " , err )
415+ }
416+ }()
408417
409418 localAddr , ok := conn .LocalAddr ().(* net.UDPAddr )
410419 if ! ok {
@@ -442,7 +451,11 @@ func GetPublicIPStr(ctx context.Context) (string, error) {
442451 if err != nil {
443452 return "" , fmt .Errorf ("failed to get public IP: %w" , err )
444453 }
445- defer resp .Body .Close ()
454+ defer func () {
455+ if err := resp .Body .Close (); err != nil {
456+ fmt .Printf ("failed to close response body: %v\n " , err )
457+ }
458+ }()
446459
447460 ip , err := io .ReadAll (resp .Body )
448461 if err != nil {
0 commit comments