Posts

Showing posts with the label golang

Deploying the Go Function to Google Cloud Function

Image
Introduction Previously, I wrote a guide on deploying a NodeJS TypeScript Function to Google Cloud Functions (GCF) and provided some basic information about GCF , which you can check out here. In this article, I'll walk you through a simple way to deploy a Go Function to GCF . Prerequisites Before we dive in, make sure you: Have a Google Cloud account and have enabled Cloud Functions . Have a basic understanding of Go . You can refer to this guide to set up the Go project used in this article. Implement Cloud Function After setting up your Go project , rename the module in the ` go.mod ` file to follow this format: ` example.com/moduleName `. This is required to deploy a Go Function . Next, update the content of the ` main.go ` file as follows: package packageName import ( "encoding/json" "fmt" "net/http" "strings" "time" ) // get method func GoCloudFunction1 ( w http . ResponseWriter , r * http . Request ) { f...

Deploying a Golang Application to Google Kubernetes Engine

Image
Introduction In this article, I will guide you through deploying a Golang Application to Google Kubernetes Engine ( GKE ). Previously, I wrote an article about deploying a NodeJS Application to GKE , which you can refer to for some basic information before continuing. Steps to Follow The process is quite similar to deploying a NodeJS Application and includes the following steps: Create a Golang Application Build a Docker image Push the Docker image Deploy the Docker image to GKE You will notice that when working with Kubernetes , the main difference is in the step where you build the Docker image. Depending on the application you need to deploy, there are different ways to build the Docker image . However, the common point is that once you build the Docker image , you have completed almost half of the process. This is because the subsequent steps involving Kubernetes are entirely the same. Detailed Process 1. Create a Golang Application In this step, you can either use an existin...

Connect Kafka with Golang

Image
Introduction If you need to know the basics of Kafka , such as its key features, components, and advantages, I have an article covering that here . Please review it and follow the steps until you've completed the Kafka installation using Docker to proceed with the following sections. Connecting to Kafka with Golang Similar to the example in the article about connecting Kafka with NodeJS , this source code also includes two parts: initializing a producer to send messages to Kafka and using a consumer to subscribe to messages from a topic . I'll break down the code into smaller parts for better understanding. First, let's define the variable values. package main import ( "fmt" "github.com/confluentinc/confluent-kafka-go/kafka" ) var ( broker = "localhost:9092" groupId = "group-id" topic = "topic-name" ) - Here, the package ` github.com/confluentinc/confluent-kafka-go/kafka ` is used to connect to Kafk...