Go Programming Articles

Found 852 articles

Difference Between Golang and PHP

Sabid Ansari
Sabid Ansari
Updated on 15-Mar-2026 3K+ Views

Both Golang and PHP are popular programming languages used for web development. Although both languages are suitable for building web applications, they have significant differences in terms of their syntax, performance, and popularity. In this article, we will discuss the key differences between Golang and PHP in detail and compare them in a tabular form. Golang vs PHP Here are the main differences between Golang and PHP − Category Golang PHP Syntax Golang has a strict syntax with mandatory semicolons and braces PHP has a flexible syntax with optional semicolons and braces ...

Read More

How to Use Go With MongoDB?

Sabid Ansari
Sabid Ansari
Updated on 15-Mar-2026 585 Views

MongoDB is a popular NoSQL database that is widely used in modern web applications. Go, on the other hand, is a fast and efficient programming language that is becoming increasingly popular for building web applications. In this article, we will discuss how to use Go with MongoDB, including how to connect to a MongoDB database and how to perform basic CRUD operations. Installing the MongoDB Driver for Go Before we can start using Go with MongoDB, we need to install the MongoDB driver for Go. The easiest way to do this is by using the following command ? ...

Read More

Difference between Goroutine and Thread in Golang.

Mahesh Parahar
Mahesh Parahar
Updated on 14-Mar-2026 977 Views

Goroutines and threads are both mechanisms for concurrent execution, but they work at different levels. Goroutines are lightweight, user-space concurrency primitives managed by the Go runtime, while threads are OS-level constructs managed by the operating system kernel. Goroutine A goroutine is a function or method that executes independently and concurrently with other goroutines. Every concurrent activity in Go is typically implemented as a goroutine. Goroutines start with just a few kilobytes of stack space (which grows dynamically) and are multiplexed onto a small number of OS threads by the Go runtime scheduler. Example The following program launches two goroutines that ...

Read More

Golang Program to Read the Contents of a File

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 1K+ Views

pre.prettyprint{width:99%!important;} a.demo{top:12px!important; float:right!important;}To read the contents of a file, we can take following steps −We can create a file called test.txt.Clean-up using defer statement.Write the contents of string.Call ReadFile() method to read the file.ReadFile reads the file named by filename and returns the contents.Print the content of the file.Examplepackage main import (    "fmt"    "io/ioutil"    "log"    "os" ) func CreateFile() {    file, err := os.Create("test.txt")    if err != nil {       log.Fatalf("failed creating file: %s", err)    }    defer file.Close()    _, err = file.WriteString("Welcome to Tutorials Point")    if err != ...

Read More

Golang Program to Find the Area of a Rectangle Using Classes

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 588 Views

To find the area of a rectangle using classes, we can take following StepsDefine a struct with rectangle properties such as breadth and length.Define a method to calculate the area of the rectangle.In the main method, instantiate an object of rectangle.Call the struct method, i.e., Area, to calculate the area of the rectangle.Print the area of the rectangle.Examplepackage main import (    "fmt" ) type Rectangle struct {    breadth int    len int } func (r *Rectangle)Area() int{    return r. len * r.breadth } func main(){    rectangle := Rectangle{       breadth: 10,       ...

Read More

Golang Program to Create a Class and Compute the Area and Perimeter of a Circle

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 524 Views

To compute the area and perimeter of a circle, we can take following steps −Define a struct with circle properties such as radius.Define a method to calculate the area of the circle.Define a method to calculate the perimeter of the circle.In the main method, take the user's input for circle's radius.Instantiate the circle with the radius.Print the area of the circle.Print the perimeter of the circle.Examplepackage main import (    "fmt"    "math" ) type Circle struct {    radius float64 } func (r *Circle)Area() float64{    return math.Pi * r.radius * r.radius } func (r *Circle)Perimeter() float64{    return ...

Read More

Golang Program to create a Class that can perform basic Calculator Operations

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 1K+ Views

To create a class that can perform basic calculator operations, we can take following StepsWe can define a Calculator class with two numbers, a and b.Define a member method to calculate the addition of two numbers.Define a member method to calculate the multiplication of two numbers.Define a member method to calculate the division of two numbers.Define a member method to calculate the subtraction of two numbers.In the main method, declare two variables, a and b.Get an instance of Calculator.Initialize a choice variable, based on which mathematical operations could be performed.Examplepackage main import (    "fmt" ) type Calculator struct { ...

Read More

Golang Program to Calculate the Average of Numbers in a Given List

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 1K+ Views

Input array is: [2, 4, 1, 6, 5]Sum = 2 + 4 + 1 + 6 + 5 => 18Average = 18/5 => 3.6 ~ 3To calculate the average of numbers in a given list, we can take following steps −Let's take an input list of numbers.Find the sum of numbers using sum() method.The sum method calculates the sum of numbers by iterating the given list.Print the average by dividing the sum with the length of the given list.Examplepackage main import (    "fmt" ) func sum(arr []int) int{    result := 0    for _, i :=range arr { ...

Read More

Golang Program to Read a Number (n) and Compute (n+nn+nnn)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 372 Views

Let's read a number, n=5Then, nn=55 and then nnn=555res = 5 + 55 + 555 => 615To read a number (n) and compute (n+nn+nnn), we can take the followingStepsDefine a variable, n.Print a statement to get the number, n.Take user input for variable, n.Make an expression for (n + nn + nnn).Convert the expression into numbers.Compute the sum of the expression.Examplepackage main import (    "fmt"    "strconv" ) func main(){    var n int    fmt.Print("Enter value of n: ")    fmt.Scanf("%d", &n)    t1 := fmt.Sprintf("%d", n)    t2 := fmt.Sprintf("+%d%d", n, n)    t3 := fmt.Sprintf("+%d%d%d", n, ...

Read More

Golang Program to read the marks of subjects and display the Grade

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 624 Views

Let's enter the marks: 89 56 90 67 99Sum of the marks is: 89+56+90+67+99 => 401Avg. = 401/5 = 80.1The steps are as follows:Define variables for 5 subjects.Enter marks for 5 subjects.Find average of the marks to find grade.Use if else block to print grade.Examplepackage main import "fmt" func main(){    var sub1, sub2, sub3, sub4, sub5 int    fmt.Println("Enter marks of the five subjects:")    fmt.Scanf("%d", &sub1)    fmt.Scanf("%d", &sub2)    fmt.Scanf("%d", &sub3)    fmt.Scanf("%d", &sub4)    fmt.Scanf("%d", &sub5)    avg:=(sub1+sub2+sub3+sub4+sub5)/5    if avg>=90{       print("Grade: A")    }else if avg>=80 && avg=70 && avg=60 && avg

Read More
Showing 1–10 of 852 articles
« Prev 1 2 3 4 5 86 Next »
Advertisements