-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ff 1471 #40
Open
eversonbueno
wants to merge
7
commits into
production
Choose a base branch
from
FF-1471
base: production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ff 1471 #40
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
14c9964
[FF-1471] Adicionado localstak no template
aeaaf03
Descomentado codigo docker
8288bd7
[FF-1471] Adicionado localstak no template sem a vendor
e3d6d65
[FF-1471] Deletado pasta vendor
1a54978
creating directory to examples
d89b2df
[FF-1471] Ajustes solicitos pelo Anderson
a5cd76a
Ajuste na localização dos arquivos dentro das pastas.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
# This env file is only required for development and testing environment | ||
SERVICE_NAME="Core APIs Go Service Template" | ||
PORT=8080 | ||
APPLICATION_ENV="development" | ||
APPLICATION_ENV="development" | ||
|
||
LOG_LEVEL=debug | ||
|
||
# Configs LocalStack | ||
REGION_NAME=us-east-1 | ||
SQS_ENDPOINT=http://0.0.0.0:4566 | ||
SQS_HOST=http://0.0.0.0:4566/000000000000/test-queue | ||
SQS_NAME=test-queue |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,7 @@ go.work | |
.env | ||
|
||
# Temporary files | ||
tmp/* | ||
tmp/* | ||
|
||
#Vendor | ||
/vendor/* |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package handler | ||
|
||
import ( | ||
"errors" | ||
"go-service-template/internal/configuration" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sqs" | ||
) | ||
|
||
var sqsInstance *sqs.SQS | ||
var sessionAws *session.Session | ||
var once sync.Once | ||
var config, _ = configuration.Load() | ||
|
||
func loadSession() { | ||
if config.IsDevelopmentEnvironment() { | ||
cfg := aws.Config{ | ||
Region: aws.String(config.RegionName), | ||
Endpoint: aws.String( config.SqsHost), | ||
} | ||
|
||
once.Do(func() { | ||
sessionAws := session.Must(session.NewSession(&cfg)) | ||
sqsInstance = sqs.New(sessionAws) | ||
}) | ||
} else { | ||
|
||
once.Do(func() { | ||
sessionAws, _ = session.NewSessionWithOptions(session.Options{ | ||
SharedConfigState: session.SharedConfigEnable, | ||
}) | ||
sqsInstance = sqs.New(sessionAws) | ||
}) | ||
} | ||
} | ||
|
||
func JobHandlerGetMessages(queueURL string) (*sqs.ReceiveMessageOutput, error) { | ||
loadSession() | ||
|
||
receive := sqs.ReceiveMessageInput{ | ||
MessageAttributeNames: []*string{ | ||
aws.String(sqs.QueueAttributeNameAll), | ||
}, | ||
AttributeNames: []*string{ | ||
aws.String(sqs.MessageSystemAttributeNameSentTimestamp), | ||
aws.String(sqs.MessageSystemAttributeNameApproximateReceiveCount), | ||
}, | ||
QueueUrl: aws.String(queueURL), | ||
MaxNumberOfMessages: aws.Int64(7), | ||
VisibilityTimeout: aws.Int64(30), | ||
WaitTimeSeconds: aws.Int64(2), | ||
} | ||
|
||
result, err := sqsInstance.ReceiveMessage(&receive) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
return result, err | ||
} | ||
|
||
func JobHandlerSendMessage(queueURL string, message string, attributes map[string]*sqs.MessageAttributeValue) error { | ||
if strings.Index(queueURL, ".fifo") > 0 { | ||
return errors.New("error: This Queue is a FIFO") | ||
} | ||
|
||
loadSession() | ||
|
||
_, err := sqsInstance.SendMessage(&sqs.SendMessageInput{ | ||
MessageBody: aws.String(message), | ||
QueueUrl: aws.String(queueURL), | ||
MessageAttributes: attributes, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func JobHandlerDeleteMessage(queueURL string, msg string) error { | ||
loadSession() | ||
|
||
_, err := sqsInstance.DeleteMessage(&sqs.DeleteMessageInput{ | ||
QueueUrl: aws.String(queueURL), | ||
ReceiptHandle: aws.String(msg), | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func GetAttributesMessage(msg sqs.Message) map[string]*sqs.MessageAttributeValue { | ||
|
||
var MessageAttributes map[string]*sqs.MessageAttributeValue | ||
|
||
if msg.MessageAttributes["Fail"] != nil { | ||
count := *msg.MessageAttributes["Fail"] | ||
countInt, _ := strconv.Atoi(*count.StringValue) | ||
totalCount := strconv.Itoa(countInt + 1) | ||
msg.MessageAttributes["Fail"].SetStringValue(totalCount) | ||
|
||
return msg.MessageAttributes | ||
} | ||
|
||
MessageAttributes = map[string]*sqs.MessageAttributeValue{ | ||
"Fail": &sqs.MessageAttributeValue{ | ||
DataType: aws.String("Number"), | ||
StringValue: aws.String("1"), | ||
}, | ||
} | ||
return MessageAttributes | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
version: "3.7" | ||
|
||
services: | ||
base-build: | ||
build: | ||
context: ../. | ||
dockerfile: ./docker/Dockerfile | ||
target: development | ||
args: | ||
- SERVICE_PATH= | ||
volumes: | ||
- ../.:/app | ||
#version: "3.7" | ||
# | ||
#services: | ||
# base-build: | ||
# build: | ||
# context: ../. | ||
# dockerfile: ./docker/Dockerfile | ||
# target: development | ||
# args: | ||
# - SERVICE_PATH= | ||
# volumes: | ||
# - ../.:/app | ||
# |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This env file is only required for development and testing environment | ||
SERVICE_NAME="Core APIs Go Service Template" | ||
PORT=8080 | ||
APPLICATION_ENV="development" | ||
|
||
LOG_LEVEL=debug | ||
|
||
# Configs LocalStack | ||
REGION_NAME=us-east-1 | ||
SQS_ENDPOINT=http://0.0.0.0:4566 | ||
SQS_HOST=http://0.0.0.0:4566/000000000000/test-queue | ||
SQS_NAME=test-queue |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"version": "v1", | ||
"source": "TemplateServiceGO", | ||
"command": "localstack-test", | ||
"occurred_at": "2022-12-26 17:28:52", | ||
"payload": { | ||
"test": "mensagem para testar localstack" | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precisa incluir umas instruções a mais:
Veja esse arquivo: https://github.com/madeiramadeirabr/template-serverless-lambda-python/blob/production/examples/lambda_sqs/docker-compose.yml#L41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/madeiramadeirabr/template-serverless-lambda-python/blob/production/examples/lambda_cron/docker-compose.yml#L49 Versão mais atualizada