{"id":38799,"date":"2026-07-08T12:32:02","date_gmt":"2026-07-08T15:32:02","guid":{"rendered":"https:\/\/www.locaweb.com.br\/ajuda\/?post_type=ht_kb&#038;p=38799"},"modified":"2026-07-08T12:32:02","modified_gmt":"2026-07-08T15:32:02","slug":"guia-de-implementacao-microsservicos-em-go","status":"publish","type":"ht_kb","link":"https:\/\/www.locaweb.com.br\/ajuda\/wiki\/guia-de-implementacao-microsservicos-em-go\/","title":{"rendered":"Guia de Implementa\u00e7\u00e3o: Microsservi\u00e7os em Go (Golang) de Alta Performance no Locaweb Cloud"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">[Informa\u00e7\u00e3o!]<\/span><span style=\"font-weight: 400;\">     \t\t<div class=\"hts-messages hts-messages--info  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">Informa\u00e7\u00e3o!<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tEste guia detalha a estrutura\u00e7\u00e3o de redes no CloudStack e a implanta\u00e7\u00e3o de microsservi\u00e7os em Go com PostgreSQL no Locaweb Cloud, abrangendo desde automa\u00e7\u00e3o CI\/CD at\u00e9 o gerenciamento por systemd.    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A arquitetura de microsservi\u00e7os foca em efici\u00eancia. O Go (Golang) \u00e9 ideal por criar bin\u00e1rios leves e nativos, dispensando interpretadores ou m\u00e1quinas virtuais pesadas.<\/span><\/p>\n<h2><b>1. Pr\u00e9-requisitos<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Para que a sua aplica\u00e7\u00e3o funcione em alta performance e sem gargalos t\u00e9cnicos, valide os seguintes requisitos antes de iniciar:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Conta ativa no <\/span><a href=\"https:\/\/painel-cloud.locaweb.com.br\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">painel<\/span><\/a><span style=\"font-weight: 400;\"> do Locaweb Cloud.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Uma m\u00e1quina virtual (VM) ativa (recomendamos o Ubuntu 22.04 LTS).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Chave privada SSH (<\/span><span style=\"font-weight: 400;\">.key<\/span><span style=\"font-weight: 400;\"> ou <\/span><span style=\"font-weight: 400;\">.pem<\/span><span style=\"font-weight: 400;\">) salva localmente com permiss\u00e3o restrita (<\/span><span style=\"font-weight: 400;\">chmod 400<\/span><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ambiente local com Go instalado (caso utilize o m\u00e9todo de deploy manual).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Reposit\u00f3rio Git com o c\u00f3digo-fonte (caso utilize o m\u00e9todo com Docker e GitHub Actions).<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">    \t\t<div class=\"hts-messages hts-messages--info  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">Informa\u00e7\u00e3o!<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t<span style=\"font-weight: 400;\">Est\u00e1 com d\u00favidas sobre como come\u00e7ar no Locaweb Cloud? Acesse nosso <\/span><a href=\"https:\/\/www.locaweb.com.br\/ajuda\/wiki\/por-onde-comecar-no-locaweb-cloud\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">tutorial de apoio<\/span><\/a><span style=\"font-weight: 400;\">.\u00a0<\/span>    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><b>2. Configura\u00e7\u00e3o de Infraestrutura (painel)<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Prepare toda a arquitetura de rede no painel do Locaweb Cloud antes de abrir o terminal de comandos. Por padr\u00e3o, sua inst\u00e2ncia nasce protegida e isolada de qualquer tr\u00e1fego externo.<\/span><\/p>\n<h3><b>Passo 1: Configurar o Encaminhamento de Portas (Port Forwarding)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">O encaminhamento de portas direciona o tr\u00e1fego recebido no seu IP p\u00fablico fixo diretamente para as portas privadas da sua VM:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Protocolo<\/b><\/td>\n<td><b>Porta P\u00fablica<\/b><\/td>\n<td><b>Porta Privada<\/b><\/td>\n<td><b>VM de Destino<\/b><\/td>\n<td><b>Finalidade<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TCP<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8080<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8080<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Sua VM Go<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u00e1fego p\u00fablico do microsservi\u00e7o<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">TCP<\/span><\/td>\n<td><span style=\"font-weight: 400;\">22<\/span><\/td>\n<td><span style=\"font-weight: 400;\">22<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Sua VM Go<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Acesso SSH Administrativo<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">[Aviso!]<\/span><span style=\"font-weight: 400;\"> Jamais exponha a porta padr\u00e3o (5432) do seu <\/span><b>banco de dados<\/b><span style=\"font-weight: 400;\"> PostgreSQL em regras de port forwarding p\u00fablico. O banco deve operar de forma invis\u00edvel na rede interna para eliminar os riscos de uma opera\u00e7\u00e3o fragmentada ou vulner\u00e1vel.<\/span><\/p>\n<h3><b>Passo 2: Configurar as Regras de Firewall de Entrada<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Na aba <\/span><b>Firewall<\/b><span style=\"font-weight: 400;\"> do seu IP p\u00fablico, libere explicitamente a entrada de tr\u00e1fego para validar o tr\u00e1fego de rede:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>CIDR de Origem<\/b><\/td>\n<td><b>Protocolo<\/b><\/td>\n<td><b>Porta Inicial<\/b><\/td>\n<td><b>Porta Final<\/b><\/td>\n<td><b>Finalidade<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">0.0.0.0\/0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">TCP<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8080<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8080<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Acesso p\u00fablico ao microsservi\u00e7o<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">&lt;SEU_IP_DE_ADMIN&gt;\/32<\/span><\/td>\n<td><span style=\"font-weight: 400;\">TCP<\/span><\/td>\n<td><span style=\"font-weight: 400;\">22<\/span><\/td>\n<td><span style=\"font-weight: 400;\">22<\/span><\/td>\n<td><span style=\"font-weight: 400;\">SSH restrito \u00e0 sua rede de TI<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">    \t\t<div class=\"hts-messages hts-messages--alert  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">Importante!<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t<span style=\"font-weight: 400;\">Na regra de SSH, substitua <\/span><span style=\"font-weight: 400;\">\/32<\/span><span style=\"font-weight: 400;\"> pelo IP p\u00fablico fixo da sua rede de administra\u00e7\u00e3o, reduzindo drasticamente a superf\u00edcie de ataques por for\u00e7a bruta na porta 22.<\/span>    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t<\/span><\/p>\n<h2><b>3. Configura\u00e7\u00e3o de Sistema (Terminal)<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Com as portas configuradas, conecte-se \u00e0 inst\u00e2ncia via SSH pelo terminal local e atualize os \u00edndices de pacotes do sistema operacional para garantir a estabilidade do ecossistema:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre><span style=\"font-weight: 400;\"># Conecta-se \u00e0 VM utilizando sua chave privada<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ssh -i ~\/.ssh\/sua-chave.key ubuntu@&lt;SEU_IP_PUBLICO&gt;<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\"># Atualiza a lista de pacotes locais do Ubuntu<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo apt-get update<\/span><\/pre>\n<h2><b>4. Banco de dados: PostgreSQL<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Para centralizar os dados de forma segura, o <\/span><b>banco de dados<\/b><span style=\"font-weight: 400;\"> rodar\u00e1 localmente na mesma VM da aplica\u00e7\u00e3o, respondendo apenas ao endere\u00e7o de loopback (<\/span><span style=\"font-weight: 400;\">localhost<\/span><span style=\"font-weight: 400;\">), o que impede acessos vindos da internet.<\/span><\/p>\n<h3><b>Passo 1: Instala\u00e7\u00e3o do servi\u00e7o<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Instale o PostgreSQL e seus utilit\u00e1rios complementares atrav\u00e9s dos reposit\u00f3rios oficiais:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre><span style=\"font-weight: 400;\">sudo apt-get install -y postgresql postgresql-contrib<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\"># Habilita e inicializa o servi\u00e7o junto ao systemd<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo systemctl enable --now postgresql<\/span><\/pre>\n<h3><b>Passo 2: Cria\u00e7\u00e3o do usu\u00e1rio e da base de dados<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Acesse o console interativo SQL e configure o ambiente do microsservi\u00e7o:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<\/p>\n<p><\/span><\/p>\n<pre><span style=\"font-weight: 400;\">sudo -u postgres psql<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">SQL<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">-- Comandos executados dentro do prompt postgres=#<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CREATE DATABASE microsservico_db;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CREATE USER appgo WITH ENCRYPTED PASSWORD 'TroqueEstaSenha_2026!';<\/span>\r\n\r\n<span style=\"font-weight: 400;\">GRANT ALL PRIVILEGES ON DATABASE microsservico_db TO appgo;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\\c microsservico_db<\/span>\r\n\r\n<span style=\"font-weight: 400;\">GRANT ALL ON SCHEMA public TO appgo;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\\q<\/span><\/pre>\n<h3><b>Passo 3: Ajuste de isolamento de rede<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Abra o arquivo principal de configura\u00e7\u00e3o para garantir que o servi\u00e7o escute apenas o tr\u00e1fego em <\/span><span style=\"font-weight: 400;\">localhost<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">sudo nano \/etc\/postgresql\/14\/main\/postgresql.conf<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Ini, TOML<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">listen_addresses = 'localhost'<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Em seguida, valide o arquivo <\/span><span style=\"font-weight: 400;\">pg_hba.conf<\/span><span style=\"font-weight: 400;\"> para exigir autentica\u00e7\u00e3o por senha criptografada robusta:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">sudo nano \/etc\/postgresql\/14\/main\/pg_hba.conf<\/span><\/pre>\n<pre><span style=\"font-weight: 400;\"># Mantenha a linha de conex\u00f5es locais com o m\u00e9todo scram-sha-256<\/span>\r\n\r\n<span style=\"font-weight: 400;\">host\u00a0 \u00a0 all\u00a0 \u00a0 all\u00a0 \u00a0 127.0.0.1\/32\u00a0 \u00a0 scram-sha-256<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Aplique as altera\u00e7\u00f5es reiniciando o servi\u00e7o:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">sudo systemctl restart postgresql<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Sua aplica\u00e7\u00e3o Go se conectar\u00e1 ao banco atrav\u00e9s da seguinte string de conex\u00e3o em ambiente local:<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre><span style=\"font-weight: 400;\">DATABASE_URL=postgres:\/\/appgo:TroqueEstaSenha_2026!@localhost:543\r\n2\/microsservico_db?sslmode=disable<\/span><\/pre>\n<h2><b>5. Deploy do microsservi\u00e7o<\/b><\/h2>\n<h3><b>M\u00e9todo 1 (Recomendado): Docker Multi-stage e GitHub Actions<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">A conteineriza\u00e7\u00e3o e a automa\u00e7\u00e3o via CI\/CD eliminam erros de configura\u00e7\u00e3o e otimizam seu <\/span><i><span style=\"font-weight: 400;\">time-to-market<\/span><\/i><span style=\"font-weight: 400;\">. Instale o Docker utilizando o reposit\u00f3rio oficial assinado da plataforma:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">sudo apt-get install -y ca-certificates curl gnupg<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo install -m 0755 -d \/etc\/apt\/keyrings<\/span>\r\n\r\n<span style=\"font-weight: 400;\">curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | \r\nsudo gpg --dearmor -o \/etc\/apt\/keyrings\/docker.gpg<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo chmod a+r \/etc\/apt\/keyrings\/docker.gpg<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\">echo \"deb [arch=$(dpkg --print-architecture) signed-by=\/etc\/apt\r\n\/keyrings\/docker.gpg] https:\/\/download.docker.com\/linux\/ubuntu \r\n$(. \/etc\/os-release &amp;&amp; echo \"$VERSION_CODENAME\") stable\" | sudo tee \r\n\/etc\/apt\/sources.list.d\/docker.list &gt; \/dev\/null<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\">sudo apt-get update &amp;&amp; sudo apt-get install -y \r\ndocker-ce docker-ce-cli containerd.io docker-buildx-plugin \r\ndocker-compose-plugin<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo systemctl enable --now docker &amp;&amp; sudo usermod -aG docker $USER<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">    \t\t<div class=\"hts-messages hts-messages--alert  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">Importante!<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t<\/span><span style=\"font-weight: 400;\">Encerre a sess\u00e3o do terminal digitando <\/span><span style=\"font-weight: 400;\">exit<\/span><span style=\"font-weight: 400;\"> e reconecte via SSH para que o sistema valide as permiss\u00f5es do grupo Docker sem a necessidade de usar <\/span><span style=\"font-weight: 400;\">sudo<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Crie um arquivo chamado <\/span><span style=\"font-weight: 400;\">Dockerfile<\/span><span style=\"font-weight: 400;\"> na raiz do seu projeto local. Utilizaremos o build multi-stage para compilar o bin\u00e1rio em um est\u00e1gio e rod\u00e1-lo em uma imagem Alpine minimalista no segundo est\u00e1gio, reduzindo o tamanho final do cont\u00eainer:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Dockerfile<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\"># Est\u00e1gio 1: Compila\u00e7\u00e3o do bin\u00e1rio est\u00e1tico Go<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM golang:1.22-alpine AS builder<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WORKDIR \/app<\/span>\r\n\r\n<span style=\"font-weight: 400;\">COPY go.mod go.sum .\/<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RUN go mod download<\/span>\r\n\r\n<span style=\"font-weight: 400;\">COPY . .<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o microsservico .<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\"># Est\u00e1gio 2: Imagem final enxuta para execu\u00e7\u00e3o<\/span>\r\n\r\n<span style=\"font-weight: 400;\">FROM alpine:3.20<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WORKDIR \/app<\/span>\r\n\r\n<span style=\"font-weight: 400;\">COPY --from=builder \/app\/microsservico .<\/span>\r\n\r\n<span style=\"font-weight: 400;\">EXPOSE 8080<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CMD [\".\/microsservico\"]<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Na pasta <\/span><span style=\"font-weight: 400;\">\/opt\/microsservico<\/span><span style=\"font-weight: 400;\"> da sua VM, configure o arquivo <\/span><span style=\"font-weight: 400;\">docker-compose.yml<\/span><span style=\"font-weight: 400;\"> utilizando o gateway nativo para alcan\u00e7ar o PostgreSQL do host de forma segura:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">YAML<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">services:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0app:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0build: .<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0restart: always<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0ports:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0- \"8080:8080\"<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0environment:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0DATABASE_URL: \"postgres:\/\/appgo:TroqueEstaSenha_2026\r\n!@host.docker.internal:5432\/microsservico_db?sslmode=disable\"<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0extra_hosts:<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0- \"host.docker.internal:host-gateway\"<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Para automatizar o fluxo, salve o workflow <\/span><span style=\"font-weight: 400;\">.github\/workflows\/deploy.yml<\/span><span style=\"font-weight: 400;\"> no seu reposit\u00f3rio Git, configurando as vari\u00e1veis secretas (<\/span><span style=\"font-weight: 400;\">SSH_HOST<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">SSH_USER<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">SSH_KEY<\/span><span style=\"font-weight: 400;\">) para reconstruir o cont\u00eainer de forma 100% self-service a cada push na branch main.<\/span><\/p>\n<h3><b>M\u00e9todo 2: Deploy manual com bin\u00e1rio compilado<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Se preferir rodar a aplica\u00e7\u00e3o diretamente no Linux sem cont\u00eaineres, execute a compila\u00e7\u00e3o cruzada na sua m\u00e1quina de desenvolvimento local para gerar o bin\u00e1rio est\u00e1tico do sistema:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\"># Executado na sua m\u00e1quina local de desenvolvimento<\/span>\r\n\r\n<span style=\"font-weight: 400;\">CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o meumicrosservico \r\nmain.go<\/span>\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\"># Transfere o bin\u00e1rio compilado de forma criptografada para o servidor<\/span>\r\n\r\n<span style=\"font-weight: 400;\">scp -i ~\/.ssh\/sua-chave.key meumicrosservico ubuntu@&lt;SEU_IP_PUBLICO&gt;:\r\n\/tmp\/meumicrosservico<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">No terminal da VM, mova o arquivo e crie um usu\u00e1rio de sistema sem privil\u00e9gios para executar os processos com seguran\u00e7a:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">sudo mv \/tmp\/meumicrosservico \/usr\/local\/bin\/meumicrosservico<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo useradd -r -s \/bin\/false appgo<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo chown appgo:appgo \/usr\/local\/bin\/meumicrosservico<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo chmod +x \/usr\/local\/bin\/meumicrosservico<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Crie o arquivo de configura\u00e7\u00e3o da unidade de servi\u00e7o no systemd para garantir a resili\u00eancia em segundo plano:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">sudo nano \/etc\/systemd\/system\/meumicrosservico.service<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Ini, TOML<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">[Unit]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Description=Microsservico em Go de Baixa Latencia<\/span>\r\n\r\n<span style=\"font-weight: 400;\">After=network.target postgresql.service<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\">[Service]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Type=simple<\/span>\r\n\r\n<span style=\"font-weight: 400;\">User=appgo<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Group=appgo<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Restart=on-failure<\/span>\r\n\r\n<span style=\"font-weight: 400;\">RestartSec=5<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Environment=DATABASE_URL=postgres:\/\/appgo:TroqueEstaSenha_2026!\r\n@localhost:5432\/microsservico_db?sslmode=disable<\/span>\r\n\r\n<span style=\"font-weight: 400;\">ExecStart=\/usr\/local\/bin\/meumicrosservico<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WorkingDirectory=\/usr\/local\/bin<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\">[Install]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">WantedBy=multi-user.target<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Bash<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\"># Recarrega o daemon, habilita o boot autom\u00e1tico e inicializa \r\no microsservi\u00e7o<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo systemctl daemon-reload<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo systemctl enable meumicrosservico<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo systemctl start meumicrosservisons<\/span><\/pre>\n<h2><b>7. Valida\u00e7\u00e3o\u00a0<\/b><\/h2>\n<h3><b>Testes de resposta interna<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Na VM da aplica\u00e7\u00e3o, valide se a API e as tabelas do PostgreSQL est\u00e3o se comunicando de forma \u00e1gil localmente:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\"># Para deploys manuais:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">sudo systemctl status meumicrosservico<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\"># Para deploys via Docker:<\/span>\r\n\r\n<span style=\"font-weight: 400;\">docker ps<\/span>\r\n\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\"># Realiza uma requisi\u00e7\u00e3o de cabe\u00e7alho local (Deve retornar HTTP 200 OK)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">curl -I http:\/\/localhost:8080<\/span><\/pre>\n<h3><b>Teste de acesso externo e isolamento<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Do terminal da sua m\u00e1quina local de trabalho, execute os testes finais de rede p\u00fablica para certificar-se da integridade do ecossistema:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bash<\/span><\/p>\n<pre><span style=\"font-weight: 400;\"># Testa o tr\u00e1fego p\u00fablico entregue com baix\u00edssima lat\u00eancia nacional<\/span>\r\n\r\n<span style=\"font-weight: 400;\">curl -I http:\/\/&lt;SEU_IP_PUBLICO&gt;:8080<\/span>\r\n\r\n\r\n\r\n<span style=\"font-weight: 400;\"># Deve resultar em falha de conex\u00e3o (Timeout), \r\nprovando o isolamento do banco<\/span>\r\n\r\n<span style=\"font-weight: 400;\">nc -zv &lt;SEU_IP_PUBLICO&gt; 5432<\/span>\r\n\r\n<\/pre>\n<h2><b>8. Solu\u00e7\u00e3o de problemas (Troubleshooting)<\/b><\/h2>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Conex\u00e3o SSH administrativa recusada por timeout:<\/b><span style=\"font-weight: 400;\"> Acesse o painel CloudStack e verifique na aba de <\/span><b>IPs P\u00fablicos<\/b><span style=\"font-weight: 400;\"> se a regra de <\/span><i><span style=\"font-weight: 400;\">Port Forwarding<\/span><\/i><span style=\"font-weight: 400;\"> da porta 22 est\u00e1 apontando para a sua VM e se o seu IP administrativo est\u00e1 correto no <\/span><b>Firewall<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Erros de &#8220;connection refused&#8221; nos logs do microsservi\u00e7o:<\/b><span style=\"font-weight: 400;\"> Certifique-se de que a vari\u00e1vel <\/span><span style=\"font-weight: 400;\">DATABASE_URL<\/span><span style=\"font-weight: 400;\"> est\u00e1 preenchida corretamente e que o arquivo <\/span><span style=\"font-weight: 400;\">pg_hba.conf<\/span><span style=\"font-weight: 400;\"> do PostgreSQL possui a regra de libera\u00e7\u00e3o ativa.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Comandos do Docker gerando erros de permiss\u00e3o negada:<\/b><span style=\"font-weight: 400;\"> Indica que o seu terminal ainda est\u00e1 rodando com as credenciais antigas de login. Digite <\/span><span style=\"font-weight: 400;\">exit<\/span><span style=\"font-weight: 400;\"> para derrubar a sess\u00e3o SSH e realize uma nova conex\u00e3o ao servidor.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u00a0    \t\t<div class=\"hts-messages hts-messages--info  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">Pronto!<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t<\/span><span style=\"font-weight: 400;\">O deploy do seu microsservi\u00e7o em Go foi conclu\u00eddo com sucesso. Sua aplica\u00e7\u00e3o est\u00e1 integrada, segura e rodando com a menor lat\u00eancia poss\u00edvel no Locaweb Cloud<\/span><span style=\"font-weight: 400;\">    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t<\/span><\/p>\n<p><span style=\"font-weight: 400;\">    \t\t<div class=\"hts-messages hts-messages--info  hts-messages--withtitle hts-messages--withicon \"   >\r\n    \t\t\t<span class=\"hts-messages__title\">Conhe\u00e7a!<\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t<\/span><span style=\"font-weight: 400;\">Seu microsservi\u00e7o j\u00e1 processa requisi\u00e7\u00f5es de forma ultra veloz, mas que tal proteger o tr\u00e1fego dos usu\u00e1rios com criptografia de ponta a ponta? Conhe\u00e7a os planos de <\/span><a href=\"https:\/\/www.locaweb.com.br\/ssl-locaweb\/\" target=\"_blank\" rel=\"noopener\"><b>Certificado SSL Locaweb<\/b><\/a><span style=\"font-weight: 400;\"> e ative o protocolo HTTPS na sua URL de produ\u00e7\u00e3o atrav\u00e9s de um proxy reverso com o Nginx para blindar as suas conex\u00f5es!<\/span><span style=\"font-weight: 400;\">    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Informa\u00e7\u00e3o!] A arquitetura de microsservi\u00e7os foca em efici\u00eancia. O Go (Golang) \u00e9 ideal por criar bin\u00e1rios leves e nativos, dispensando interpretadores ou m\u00e1quinas virtuais pesadas. 1. Pr\u00e9-requisitos Para que a sua aplica\u00e7\u00e3o funcione em alta performance e sem gargalos t\u00e9cnicos, valide os seguintes requisitos antes de iniciar: Conta ativa no&#8230;<\/p>\n","protected":false},"author":55,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[666],"ht-kb-tag":[],"class_list":["post-38799","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-locaweb-cloud"],"_links":{"self":[{"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb\/38799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/comments?post=38799"}],"version-history":[{"count":1,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb\/38799\/revisions"}],"predecessor-version":[{"id":38801,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb\/38799\/revisions\/38801"}],"wp:attachment":[{"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/media?parent=38799"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb-category?post=38799"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.locaweb.com.br\/ajuda\/wp-json\/wp\/v2\/ht-kb-tag?post=38799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}