Go
Go (Golang) was designed at Google for modern cloud infrastructure. It combines C-like performance with garbage collection, built-in concurrency, and fast compilation making it ideal for APIs, microservices, and CLI tools.
Contents 6 Sections
1Go Fundamentals
package mainimport ( "fmt" "strings" "strconv" )
func main() { // Variables strong static typing with inference name := "Sufi" // short declaration var age int = 30 // explicit var score float64 = 9.5 active := true
// Zero values (no undefined!) var x int // 0 var s string // "" var b bool // false
// Multiple assignment a, b2, c := 1, "hello", true x, y := y, x // swap
// Strings fmt.Println(strings.ToUpper(name)) fmt.Println(strings.Contains(name, "ufi")) n, _ := strconv.Atoi("42") // string to int
fmt.Printf("Name: %s, Age: %d, Score: %.1f\n", name, age, score) _ = active; _ = a; _ = b2; _ = c; _ = n; _ = x; _ = y } ```
2Types, Structs & Methods
package mainimport "fmt"
type Employee struct { Name string Age int Salary float64 }
// Method with pointer receiver (can modify struct) func (e *Employee) GiveRaise(percent float64) { e.Salary *= (1 + percent/100) }
// Method with value receiver (read-only) func (e Employee) String() string { return fmt.Sprintf("%s ($%.0f)", e.Name, e.Salary) }
// Interface type Stringer interface { String() string }
// Go uses implicit interface implementation no "implements" func printInfo(s Stringer) { fmt.Println(s.String()) }
func main() { emp := Employee{Name: "Sufi", Age: 30, Salary: 95000} emp.GiveRaise(10) printInfo(emp) // Sufi ($104500)
// Anonymous struct point := struct{ X, Y int }{X: 10, Y: 20} fmt.Println(point.X) } ```
3Goroutines & Channels
package mainimport ( "fmt" "sync" "time" )
// Goroutines lightweight threads (2KB stack, scales to millions) func fetchData(id int, wg *sync.WaitGroup, ch chan<- string) { defer wg.Done() time.Sleep(time.Millisecond * 100) // simulate work ch <- fmt.Sprintf("data from %d", id) }
func main() { ch := make(chan string, 10) // buffered channel var wg sync.WaitGroup
for i := 1; i <= 5; i++ { wg.Add(1) go fetchData(i, &wg, ch) }
// Close channel when all goroutines done go func() { wg.Wait() close(ch) }()
// Consume results for result := range ch { fmt.Println(result) }
// Select non-blocking channel operations select { case msg := <-ch: fmt.Println(msg) case <-time.After(time.Second): fmt.Println("timeout") default: fmt.Println("no message ready") } } ```
4Error Handling & Defer
package mainimport ( "errors" "fmt" "os" )
// Custom error types type ValidationError struct { Field string Message string }
func (e *ValidationError) Error() string { return fmt.Sprintf("validation error on %s: %s", e.Field, e.Message) }
// Explicit error returns no exceptions func divide(a, b float64) (float64, error) { if b == 0 { return 0, errors.New("division by zero") } return a / b, nil }
func readFile(path string) ([]byte, error) { f, err := os.Open(path) if err != nil { return nil, fmt.Errorf("readFile: %w", err) // wrap error } defer f.Close() // ALWAYS called when function returns
// defer is LIFO multiple defers execute in reverse order data := make([]byte, 1024) n, err := f.Read(data) return data[:n], err }
// errors.Is and errors.As for unwrapping var ve *ValidationError if errors.As(err, &ve) { fmt.Println("Field:", ve.Field) } ```
5HTTP & REST APIs
package mainimport ( "encoding/json" "log" "net/http" )
type User struct {
ID int json:"id"
Name string json:"name"
Email string json:"email,omitempty"
}
func usersHandler(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: users := []User{{1, "Sufi", "s@example.com"}} w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(users)
case http.MethodPost: var user User if err := json.NewDecoder(r.Body).Decode(&user); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } user.ID = 42 w.WriteHeader(http.StatusCreated) json.NewEncoder(w).Encode(user)
default: http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) } }
func main() { mux := http.NewServeMux() mux.HandleFunc("/users", usersHandler) log.Fatal(http.ListenAndServe(":8080", mux)) } ```
6Testing & Modules
// math_test.go
package mathimport "testing"
func TestAdd(t *testing.T) { got := Add(2, 3) want := 5 if got != want { t.Errorf("Add(2,3) = %d; want %d", got, want) } }
func TestDivide_ZeroError(t *testing.T) { _, err := Divide(10, 0) if err == nil { t.Error("expected error for division by zero") } }
// Table-driven tests (idiomatic Go) func TestMultiply(t *testing.T) { cases := []struct{ a, b, want int }{ {2, 3, 6}, {0, 5, 0}, {-1, 4, -4}, } for _, tc := range cases { if got := Multiply(tc.a, tc.b); got != tc.want { t.Errorf("Multiply(%d,%d)=%d; want %d", tc.a, tc.b, got, tc.want) } } }
// go test ./... run all tests // go test -race ./... race condition detection // go test -bench=. ./... benchmarks ```
Explore the Full Portfolio
This is the complete portfolio of Sufi Khan Sulaiman, a technology leader specialising in B2B commerce and digital automation. Start from the Home page for the overview, then move through two decades of career experience across FLIR Systems, Lorex Technology, and 1c Platform, and the full catalogue of project case studies spanning headless commerce migrations, AI recommendation engines, and multi-channel fulfilment systems.
The skills and certifications page maps the technical and leadership capabilities behind the work, while the articles and the knowledge base break down the thinking into actionable frameworks. For hands-on learning, the tutorials and applications sections cover practical builds from front-end fundamentals to full-stack web apps.
For consulting engagement, the expertise page outlines service offerings, the ecommerce hub covers platform architecture and automation strategy, and the ecommerce guide (PDF) is a downloadable 55-page field manual. When you are ready to talk, the contact page is the direct line.