Issue sending response back to websocket from lamda using Serverless offline websocket with Golang implementation

Hi,
I am trying to use serverless oflline Websockets .
I am using golang as implementation in lamda .

I am able to initiate and connect to websocket

env GOOS=linux go build -ldflags=“-s -w” -o bin/connection handler/aws/connection/main.go
sls offline --useDocker
offline: Starting Offline: staging/us-east-1.
offline: Offline [http for lambda] listening on xhttp://localhost:3002 . **ignore “x” in the address
offline: route ‘$connect’
offline: route ‘$disconnect’
offline: route ‘CreateConnection’
offline: Offline [websocket] listening on ws://localhost:3001
offline: Offline [http for websocket] listening on xhttp://localhost:3001 . **ignore “x” in the address

I am also able to make connection using wscat to the websocket but when I try to send back the response from lambda to websocket , it says connection refused.

My ApiGatewayManagementApi client

func NewAPIGatewaySession() *apigatewaymanagementapi.ApiGatewayManagementApi {
	sess := session.Must(session.NewSession(&aws.Config{
		Region: aws.String(endpoints.UsEast1RegionID),
	}))
	conf := &aws.Config{
		Endpoint: aws.String("http://127.0.0.1:3001"), //the endpoint was given by serverless offline
	}
	return apigatewaymanagementapi.New(sess, conf)
}

The way i am sending the response

case "CreateConnection":

		apigatewaySession := apiGatewayManagement.NewAPIGatewaySession()
		var requestPayload RequestPayload
		json.Unmarshal([]byte(request.Body), &requestPayload)
		fmt.Println(request.Body)
		fmt.Println(requestPayload.Message)
		fmt.Println(requestPayload.ConnectionId)

		connectionInput := &apigatewaymanagementapi.PostToConnectionInput{
			ConnectionId: aws.String(requestPayload.ConnectionId),
			Data:         []byte(requestPayload.Message),
		}
		fmt.Println(apigatewaySession.Endpoint)

		_, err := apigatewaySession.PostToConnection(connectionInput)
		if err != nil {
			fmt.Println(err)
		}
	}

	return events.APIGatewayProxyResponse{
		Body:       string([]byte("body")),
		StatusCode: 200,
		Headers:    map[string]string{"Access-Control-Allow-Origin": "*"},
	}, nil

My wscat command : wscat -c ws://localhost:3001

error

{AccountID: ResourceID: Stage:local RequestID:ckcg43uf9000i9uoce5dw1vgr Identity:{CognitoIdentityPoolID: AccountID: CognitoIdentityID: Caller: APIKey: APIKeyID: AccessKey: SourceIP:127.0.0.1 CognitoAuthenticationType: CognitoAuthenticationProvider: UserArn: UserAgent: User:} ResourcePath: Authorizer: HTTPMethod: APIID:private ConnectedAt:1594379026629 ConnectionID:ckcg43ltz00059uocb09da33i DomainName:localhost Error: EventType:MESSAGE ExtendedRequestID:ckcg43uf9000g9uoc2n2cefod IntegrationLatency: MessageDirection:IN MessageID:ckcg43uf9000h9uocevc120s4 RequestTime:10/Jul/2020:16:33:46 +0530 RequestTimeEpoch:1594379026629 RouteKey:CreateConnection Status:}
{ “action”: “CreateConnection”, “message”: “This is a new message”, “connectionid”: “ckcg4281f00009uoc394h5d8w” }
This is a new message
ckcg4281f00009uoc394h5d8w
xhttp://127.0.0.1:3001 **ignore “x” in the address

RequestError: send request failed
caused by: Post “xhttp://127.0.0.1:3001/@connections/ckcg4281f00009uoc394h5d8w”: dial tcp 127.0.0.1:3001: connect: connection refused **ignore “x” in the address

Adding to that , when I run

> "curl -X POST xhttp://127.0.0.1:3001/@connections/ckcg4281f00009uoc394h5d8w"

from my terminal , it works **ignore “x” in the address

I am a bit new to this so apologies if i am missing out any specific item.