Jump to content

Search the Community

Showing results for tags 'golang'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • General Discussion
    • Artificial Intelligence
    • DevOpsForum News
  • DevOps & SRE
    • DevOps & SRE General Discussion
    • Databases, Data Engineering & Data Science
    • Development & Programming
    • CI/CD, GitOps, Orchestration & Scheduling
    • Docker, Containers, Microservices, Serverless & Virtualization
    • Infrastructure-as-Code
    • Kubernetes & Container Orchestration
    • Linux
    • Logging, Monitoring & Observability
    • Security, Governance, Risk & Compliance
  • Cloud Providers
    • Amazon Web Services
    • Google Cloud Platform
    • Microsoft Azure

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


LinkedIn Profile URL


About Me


Cloud Platforms


Cloud Experience


Development Experience


Current Role


Skills


Certifications


Favourite Tools


Interests

Found 7 results

  1. Golang (Go) is a programming language provided by Google to help developers create scalable and secure systems. Its simplicity makes any developer want to learn the language and use it quickly. While Go is a go-to programming language for many developers, you must first install it on Ubuntu 24.04 before you begin using it for your development. We’ve covered three installation methods that anyone can use. Read on! Three Methods of Installing Go on Ubuntu 24.04 The Go programming language has numerous applications, and as a Ubuntu user, you have three methods for installing Go. You can source it from the snap store or install it from the Ubuntu repository using APT. Still, you can download the Go tarball, extract it, and add its path to make it accessible on your system. All these methods are discussed below. Method 1: Install Go on Ubuntu 24.04 Via APT The first step in this method is to update the Ubuntu 24.04 repository. The Go version installed with this method is stable but not always the latest available version. Let’s first update the system. $ sudo apt update Next, use APT to install the Go package. $ sudo apt install golang-go Once the installation process is completed, view the installed Golang version. $ go version Method 2: Install Go Via Snap Even on Ubuntu 24.04 (Noble Numbat), you can access the Snap Store and install Snap packages. Go is available as a Snap package, and installing it via this approach will install even its dependencies. Here, you only need to execute the below command. $ sudo snap install go --classic Similarly, we can check the installed Go version. $ go version Notice how the two methods install the same Go version, which is the latest version when writing this post. Method 3: Install Go Via Its Official Repository The official way of installing Go on any Linux distribution is by sourcing its binary package. However, this is a long method as more steps are involved, but if you want the latest version or a specific Go version, this method is the best. The first step is to update the system. $ sudo apt update Next, visit the Go download page and find the version you want to install. Ensure you select the appropriate architecture for compatibility. We’ve chosen version 1.22.2 for this example. Once you’ve selected it, download the tarball using any utility. We’ve used wget for our example. $ wget https://go.dev/dl/go1.22.2.linux-amd64.tar.gz Allow the download to complete. The next step involves extracting the archive file. We’ve extracted it to the /usr/local/ directory using the tar command below. $ sudo tar -C /usr/local -xzf go1.20.1.linux-amd64.tar.gz $ ls /usr/local/go We’ve also run the ls command to confirm that the file was successfully unzipped and the new uncompressed Go folder containing all the required files exist. So far, we have the Go folder on our system, but we must add its binary to the path environment variable before we start using Go system-wide. Using a text editor, we will edit our bashrc to add the Go binary. Let’s open the file using the nano text editor. $ nano ~/.bashrc Next, paste the below line inside the file. export PATH=$PATH:/usr/local/go/bin Save the changes and exit the file. Also, source the file for the changes to apply. $ source ~/.bashrc Lastly, check the installed version. $ go version Test the Go Language Now that we’ve installed the Go programming language, we can use it for our development. Let’s create a simple ‘hello’ program to test that Go works correctly. Save it with a .go extension. Save the file and run it using the below syntax. $ go run program_name That’s it! The output confirms that Go is successfully installed on Ubuntu 24.04. Conclusion Go is a recent programming language developed by Google. Ubuntu supports Go and there are three ways you can install it. You can install it via APT or snap. Moreover, you can install it by downloading its official repository and adding its binary to your environment variable. Have fun using Go on Ubuntu 24.04. View the full article
  2. File operation is probably one of the most common operation when it comes to program, except for dealing with bugs. In Go, you will encounter such instances where you need to read a file line by line especially when dealing with text files. In this tutorial, we will walk you through all the methods and techniques on how we can read a file line by line. We start with the basic file reading techniques and progress to the more advanced features such as bufio and scanner libraries. We will also cover an example to help cement our understanding. Sample File Before we dive into the step of reading a file line by line, let us set up a basic file that we will use for demonstration purposes. In our case, we use a basic Terraform configuration as shown in the following output: # Define the AWS provider configuration provider "aws" { region = "us-east-1" } # Create a VPC resource "aws_vpc" "example_vpc" { cidr_block = "10.0.0.0/16" enable_dns_support = true enable_dns_hostnames = true } # Create two subnets in different availability zones resource "aws_subnet" "example_subnet1" { vpc_id = aws_vpc.example_vpc.id cidr_block = "10.0.1.0/24" availability_zone = "us-east-1a" map_public_ip_on_launch = true } resource "aws_subnet" "example_subnet2" { vpc_id = aws_vpc.example_vpc.id cidr_block = "10.0.2.0/24" availability_zone = "us-east-1b" map_public_ip_on_launch = true } # Create a security group for the EC2 instance resource "aws_security_group" "example_sg" { name = "example-sg" description = "Security group for EC2 instance" ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } # ---- more --------------------- The example file represents a Terraform configuration to set up an EC2 with a load balancer. Open the File in Golang Before we can read a file line by line, we need to open the file. Luckily, Go provides us with a simple and intuitive method of opening the files using the OS package. An example code is as follows: package main import ( "fmt" "os" ) func main() { fp := "./aws.tf" // Open the file for reading file, err := os.Open(fp) if err != nil { fmt.Println("Error:", err) return } defer file.Close() // File is now open and ready for reading } In the given example, we start by importing the packages that we require. In our case, we just need the fmt and OS packages. Next, we specify the path to the file that we want to open and save it to the “fp” variable. In our case, we want to open the “aws.tf” file. Finally, we use the os.Open() function to open the file and check any error that might occur when attempting to open the file. Read the File Line by Line in Golang Now that we have the target file open and ready to read, we can proceed and discuss the methods and techniques of reading the file line by line. Using the Bufio Package One of the most powerful packages in the Go ecosystem is the “bufio” package. This package implements the buffered I/O operations. It wraps the “io.Reader” and “io.Writer” object, creating another object that implements the interface but with buffer support. Method 1: Using Bufio.Scanner We can use the scanner type from this package to read a file line by line as demonstrated in the following example code: package main import ( "bufio" "fmt" "os" ) func main() { fp := "./aws.tf" file, err := os.Open(fp) if err != nil { fmt.Println("Error:", err) return } defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() { line := scanner.Text() fmt.Println(line) } if err := scanner.Err(); err != nil { fmt.Println("Error:", err) } } To use the scanner type, we start by creating a Scanner using the bufio.NewScanner(file) method where the file refers to the file that we opened for reading. We then use a “for” loop to iterate over the lines of the file using the scanner.Scan() method. Finally, we extract the text of each line using the scanner.Text() method and print it to the console. Method 2: Using Bufio.NewReader Another method that we can use is the NewReader() method from the “bufio” package. This allows us to read the lines of the file using the ReadString() function. An example is as follows: package main import ( "bufio" "fmt" "os" ) func main() { fp := "./aws.tf" file, err := os.Open(fp) if err != nil { fmt.Println("Error:", err) return } defer file.Close() reader := bufio.NewReader(file) for { line, err := reader.ReadString('\n') if err != nil { break } fmt.Print(line) } } In this approach, we create a “bufio.Reader” using the bufio.NewReader(file). We then use a “for” loop to read the lines using the reader.ReadString(‘\n’). The loop continues to read the file until an error occurs. For example, when we reach the end of the file. Using the Io Package Another package that comes in handy when dealing with I/O operations in Go is the “io” package. This package provides basic interfaces for I/O primitives. The primary task of the package is to wrap the existing implementations such as primitives from the OS package into shared public interfaces that abstract the functionality. Method 1: Using ReadString In the “io” package, we can use the ReadString() function to read a file line by line as shown in the following example: package main import ( "fmt" "io" "os" ) func main() { fp := "./aws.tf" file, err := os.Open(fp) if err != nil { fmt.Println("Error:", err) return } defer file.Close() buf := make([]byte, 1024) for { n, err := file.Read(buf) if err != nil { if err == io.EOF { break } fmt.Println("Error:", err) return } data := buf[:n] fmt.Print(string(data)) } } In this implementation, we start by opening a file for reading as we did in the previous examples. We then create a buffer called “buf” to read a chunk of data from the file. Lastly, we use a “for” loop with the file.Read() function to read the data into the buffer. We also check for “io.EOF” to determine when we reached the end of the file and terminate the loop. Method 2: Using ReadLine We also have access to the “ReadLine” function from the “io” package which can come in handy when we need to read a file line by line. An example is as follows: package main import ( "fmt" "io" "os" ) func splitLines(data []byte) [][]byte { var lines [][]byte for _, b := range data { if b == '\n' { lines = append(lines, []byte{}) } else { if len(lines) == 0 { lines = append(lines, []byte{}) } lines[len(lines)-1] = append(lines[len(lines)-1], b) } } return lines } func main() { fp := "./aws.tf" file, err := os.Open(fp) if err != nil { fmt.Println("Error:", err) return } defer file.Close() reader := io.Reader(file) buf := make([]byte, 1024) for { n, err := reader.Read(buf) if err != nil { if err == io.EOF { break } fmt.Println("Error:", err) return } data := buf[:n] lines := splitLines(data) for _, line := range lines { fmt.Println(string(line)) } } } In this case, we create a buffer and read the chunks of data from the file using the reader.Read() function. We then define a splitLines() function whose purpose is to split the data into lines by detecting when a new character is in the buff. Finally, we print the contents of the file. Conclusion In this tutorial, we learned a lot about file operations in Go. We learned how to use the “bufio” package, the Scanner type, and the NewReader. We also learned how to use the methods such as the “ReadString” and “ReadLine” functions to read a file line by line. View the full article
  3. A new low-level Go binding for the Terraform protocol for integrations to be built on top of; https://github.com/hashicorp/terraform-plugin-go
  4. Using the AWS Toolkit for VS Code, customers can now create, locally debug, and deploy Lambda functions written in Java and Go. Java users will be able to step-through debug Lambdas built with Maven and Gradle in Java 8, Java 8.al2, and Java 11, while Go users will be able to do the same with Lambdas built in Golang 1.14+. View the full article
  5. This article will focus on the popular monitoring tool Prometheus, and how to use PromQL. Prometheus uses Golang and allows simultaneous monitoring of many services and systems. View the full article
  6. Do you love Go? Do you maintain a project written in Go? Are you using Go in production? Are you a performance freak? If you answered “yes” to any of these questions, join our conference on all things Golang: cool libraries, frameworks and tools new paradigms, techniques and tricks adopting Golang for the first time in your team Golang and CI unorthodox ways of using Go anything else Go https://www.papercall.io/conf42-golang-2021
  7. until
    #GoVirCon ~ see you online! What Every Gopher Needs to Know! Call for Papers/Programming GopherCon's Call for Papers opened at the beginning of December and closed January 10th. We're excited to share that we received over 160 submissions! We're happy to announce our program has been officially decided and can be found on the Agenda page. We hope you are as pleased with this year's line-up as we are! The Call for Papers for 2021 will open December 1, 2020. We will post a link on Twitter. Pre-Conference Workshops A Pre-Conference Workshop Ticket is only valid on Monday, November 9th or Tuesday, November 10th, with the exception of the two-day pre-conference workshops that will be offered over the course of both days. The purchase of a Pre-Conference Workshop Ticket does not include access to the full conference, Wednesday, November 11th - Friday, November 13th, or vice versa. If you wish to attend the full conference, please purchase a Community Ticket or one of the two Promo Tickets listed below in addition to your Pre-Conference Workshop Ticket(s). Furthermore, based on the feedback of some of our experienced teachers, we have determined that 12:00 p.m. - 4:00 p.m. EST is the best time to offer a Pre-Conference workshop to ensure the largest "live" audience. However, if you are located in a "challenging" time zone or you would like to attend more than one workshop, we will be recording the presentations and emailing them to ticket holders. Which Ticket Should You Choose? If you have the means and you are able to support the conference, please consider the One-Time 20% Promo or One-Time 20% Promo, plus Perpetual 10% Promo outlined below. Otherwise, the Community Ticket is a separate purchase from any Pre-Conference Workshop Tickets. Scholarships GopherCon awards a limited number of Diversity Fund Scholarships each year to golang users in need. Though we are looking for diversity in both areas of gender and race, we absolutely consider need as well. The scholarship submission process opened at the beginning of December and closed January 8th. We are pleased to announce that we received over 170 applications this year and awarded 47 scholarships! All applicants have been notified of our decision. https://www.gophercon.com/
  • Forum Statistics

    43.1k
    Total Topics
    42.4k
    Total Posts
×
×
  • Create New...