
Go in bits
Archive of all the links from my socials for go tuts.

Archive of all the links from my socials for go tuts.
Join the conversation by signing in with your Google account
A guide to Next.js data fetching mistakes & security vulnerabilities
A guide to JavaScript for frontend development for beginners part 1
A guide to routing in Next.js (App Router) covering Catch-All Segments, Dynamic Routes, Nested Routes, and more.
Design & Developed by Ramxcodes
© 2025. All rights reserved.
that's why i'm learning go!
I'll attach links and resources i'm from as we progress. Bookmark this blog for later.
package main
import "fmt"
func main() {
fmt.Println("Hello sir")
}
To run this just run this following command :
go run ./filname.goIf you want to build this then just
go build ./filaname.goyou will get a asm file just do
./filanamepackage main
import "fmt"
func main() {
var age = 20
if age >= 18 {
fmt.Println("i'm an adult")
} else {
fmt.Println("i'm a kid")
}
//we do not have ternary op like js have
}
package main
import "fmt"
const age = 30
const (
PORT = 3000
URL = "http://localhost"
)
func main() {
name := "ram"
fmt.Println(name)
fmt.Println(age)
fmt.Println(PORT)
fmt.Println(URL)
}
package main
import "fmt"
// for -> is the only construct go have for looping there is no other kind of loops
func main() {
// comment other loops and use only loop at a time
// otherwise infinite loop will block scope of range loop
// While loop
i := 0
for i <= 3 {
fmt.Println(i)
i = i + 1
}
// common for loop syntax like c++ and js
for j := 0; j <= 3; j++ {
fmt.Println(j)
}
// Infinite loop
for {
fmt.Println("ramxcodes")
}
// range loop but you should not use on integers
// like i'm doing right now it only be used on arrays and slices
for x := range 3 {
fmt.Println(x)
}
}
package main
import "fmt"
func main() {
age := 22
if age >= 18 {
fmt.Println("adult")
} else if age >= 12 {
fmt.Println("teenagaer")
} else {
fmt.Println("kid")
}
var role = "admin"
var hasPermissions = false
if role == "admin" || hasPermissions {
fmt.Println("Access Granted!")
} else {
fmt.Println("No Access")
}
// we do not have ternary op ? like js have
// so we need to use if else
}
package main
import (
"fmt"
"time"
)
func main() {
// simple switch
i := 2
switch i {
case 1:
fmt.Println("one")
// break
case 2:
fmt.Println("two")
case 3:
fmt.Println("three")
default:
fmt.Println(" other val ")
}
// multiple condition switch
switch time.Now().Weekday() {
case time.Saturday, time.Sunday:
fmt.Println("Its weekend")
default:
fmt.Println("its a working day")
}
// type switch case
WhoAmI := func(i interface{}) {
switch t := i.(type) {
case int:
fmt.Println("its an integer")
case bool:
fmt.Println("its a bool")
case string:
fmt.Println("its a string")
default:
fmt.Println("this is ", t, "you can see")
}
}
WhoAmI(234.324)
}package main
import "fmt"
func main() {
// Arrays are numbered sequence of a specific length
var nums [6]int // <- array declaration, default values will be 0.
fmt.Println(len(nums)) // <- len is a length funcation comes inbuilt in go
fmt.Println("--------")
// Push
nums[0] = 1
// pushed 1 at 0th index
nums[1] = 4
// pushed 4 at 1st index
fmt.Println(nums)
fmt.Println(nums[0])
fmt.Println(nums[1])
fmt.Println("--------")
// Bool array
var vals [4]bool
// Default bool value is false
fmt.Println(vals)
fmt.Println("--------")
// String array
var names [4]string
// Default is empty string
names[0] = "R"
names[1] = "a"
names[2] = "M"
names[3] = "x"
fmt.Println(names)
// Decalre array and add elements like js
fmt.Println("--------")
numbers := [3]int{1, 2, 3}
fmt.Println(numbers)
// 2-D arrays
fmt.Println("--------")
number := [2][2]int{{1, 2}, {3, 4}}
fmt.Println(number)
}package main
import (
"fmt"
)
func main() {
var nums = make([]int, 0, 5)
nums = append(nums, 1)
nums = append(nums, 2)
nums = append(nums, 3)
nums = append(nums, 4)
nums = append(nums, 5)
nums = append(nums, 6)
var nums2 = make([]int, len(nums))
copy(nums2, nums)
fmt.Println(nums2)
fmt.Println(nums)
var numx = []int{1, 2, 3}
var numy = []int{1, 2, 3}
// slice package
fmt.Println(slices.Equal(numx, numy))
var nums2D = [][]int{{1, 2}, {3, 4}}
fmt.Println(nums2D)
// slice operator
var nums3 = []int{0, 1, 2, 3}
fmt.Println(nums3[:])
}
package main
import (
"fmt"
"maps"
)
func main() {
m := make(map[string]string)
m["name"] = "ram"
m["x"] = "ramxcodes"
m["github"] = "@ramxcodes"
fmt.Println(m["phone"])
map2 := make(map[string]int)
map2["age"] = 30
fmt.Println(len(map2))
fmt.Println(m)
delete(m, "x")
fmt.Println(m)
clear(m)
fmt.Println(m)
map3 := map[string]int{"price": 40, "phone": 123}
fmt.Println(map3)
v, ok := map3["x"]
fmt.Println(v)
if ok {
fmt.Println("price exists")
} else {
fmt.Println("not sure")
}
map4 := map[string]int{"price": 40, "x": 32}
map5 := map[string]int{"price": 40, "x": 32}
fmt.Println(maps.Equal(map4, map5))
}
package main
import "fmt"
// range -> iterating over data structure
func main() {
// slice
nums := []int{5, 6, 7, 8}
for i := 0; i < len(nums); i++ {
fmt.Println(nums[i])
}
// now with range
for _, num := range nums {
fmt.Println(num)
}
sum := 0
for _, num := range nums {
sum = sum + num
}
fmt.Println(sum)
for i, num := range nums {
fmt.Println(num, i)
}
// Map
m := map[string]string{"fname": "ram", "lname": "codes"}
for k, v := range m {
fmt.Println(k, v)
}
// string
// i -> starting byte of rune, c -> unicode of charachter (rube ds)
for i, c := range "ramxcodes" {
fmt.Println(i, c)
}
}
package main
import "fmt"
func add(n int) int {
return n
}
func getLang() (string, string, string, bool) {
return "go", "Js", "c++", true
}
func applyOperation(n int, operation func(int) int) int {
return operation(n)
}
func multiplier(factorial int) func(int) int {
return func(n int) int {
return n * factorial
}
}
func main() {
result := add(3 + 5)
fmt.Println(result)
lang1, lang2, lang3, isCool := getLang()
fmt.Println(lang1)
fmt.Println(lang2)
fmt.Println(lang3)
fmt.Println(isCool)
double := func(x int) int {
return x * 2
}
square := func(x int) int {
return x * x
}
fmt.Println(applyOperation(5, double)) // prints 10
fmt.Println(applyOperation(5, square)) // prints 25
timesTwo := multiplier(2)
timesThree := multiplier(3)
fmt.Println(timesTwo(5))
fmt.Println(timesThree(5))
}
package main
import "fmt"
func sum(nums ...int) int {
total := 0
for _, num := range nums {
total = total + num
}
return total
}
func main() {
nums := []int{1, 2, 3, 4, 5}
result := sum(nums...)
fmt.Println(result)
}
package main
import "fmt"
func counter() func() int {
var count int = 0
return func() int {
count += 1
return count
}
}
func main() {
increment := counter()
fmt.Println(increment())
fmt.Println(increment())
fmt.Println(increment())
fmt.Println(increment())
}