Last active
December 22, 2021 14:40
-
-
Save Jimeux/310e2f10b324405f7b99fb4b4425b766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// APIClient is a simple wrapper around APIGatewayManagementAPI. | |
type APIClient struct { | |
client awsiface.APIGatewayManagementAPI | |
} | |
func NewAPIGatewayClient(client awsiface.APIGatewayManagementAPI) *APIClient { | |
return &APIClient{client: client} | |
} | |
// NewAPIClientFromConfig create a APIClient instance from a given aws.Config instance. | |
// stage and domain are used to construct the required endpoint resolver. | |
func NewAPIClientFromConfig(cfg aws.Config, stage, domainName string) *APIClient { | |
var endpoint url.URL | |
endpoint.Scheme = "https" | |
endpoint.Path = stage | |
endpoint.Host = domainName | |
endpointResolver := apigatewaymanagementapi.EndpointResolverFromURL(endpoint.String()) | |
return NewAPIGatewayClient(apigatewaymanagementapi.NewFromConfig( | |
cfg, apigatewaymanagementapi.WithEndpointResolver(endpointResolver))) | |
} | |
// Publish posts data to the connection identified by connID. | |
func (c *APIClient) Publish(ctx context.Context, connID string, data []byte) error { | |
_, err := c.client.PostToConnection(ctx, &apigatewaymanagementapi.PostToConnectionInput{ | |
Data: data, | |
ConnectionId: aws.String(connID), | |
}) | |
return err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment