Skip to content

Latest commit

 

History

History
212 lines (157 loc) · 10.1 KB

File metadata and controls

212 lines (157 loc) · 10.1 KB

Course Summary: Golang Web Development: Create Powerful Servers with Golang

This document summarizes the key points from the course. I highly recommend watching the full course if you have the opportunity.

Before You Get Started

  • I summarize key points from useful courses to learn and review quickly.
  • Simply click on Ask AI links to dive into any topic you want.

AI-Powered buttons

Teach Me: 5 Years Old | Beginner | Intermediate | Advanced | (reset auto redirect)

Learn Differently: Analogy | Storytelling | Cheatsheet | Mindmap | Flashcards | Practical Projects | Code Examples | Common Mistakes

Check Understanding: Generate Quiz | Interview Me | Refactor Challenge | Assessment Rubric | Next Steps

1. Course Introduction & Why Go for Web Development

Rajan kicks off the course by explaining why big companies are moving to Go: it’s fast, memory-efficient, and perfect for building scalable backend services. He gives a high-level roadmap: start with a bare-bones Go server, add Gin for nicer routing, use Docker + PostgreSQL, build full CRUD APIs, add Google OAuth + JWT auth, and finally deploy everything to AWS with CI/CD in mind.

Example: You’ll end the course with a production-ready task-management API that runs on AWS, uses Google login, and talks to a real cloud database.

Ask AI: Why Go for backend

2. Installing Go & Your Very First Server

Learn how to download and install Go (1.23+), set up GOPATH, and write a classic “hello world” server using only the standard net/http package in ~15 lines.

Example:

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "OK")
    })
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Ask AI: Installing Go and first server

3. Why Gin & Migrating to Gin Framework

Rajan compares native net/http vs Gin and shows why Gin wins for real projects: automatic logging, easy JSON responses, built-in validation, middleware support, route grouping, and better performance.

Example:

r := gin.Default()
r.GET("/", func(c *gin.Context) {
    c.JSON(200, gin.H{"message": "OK"})
})
r.Run(":8080")

Ask AI: Gin vs net/http

4. Environment Variables & Config Management

Never hard-code secrets! Rajan shows how to use godotenv to load a .env file and create a clean config package that’s loaded once at startup using init().

Example:

APP_PORT=8080
DB_PATH=postgres://postgres:adminpassword@localhost:5433/tasks?sslmode=disable

Ask AI: Environment variables in Go

5. Docker + PostgreSQL Setup

Learn why Docker is perfect for local databases (multiple versions, easy cleanup). Rajan provides a ready docker-compose.yml that spins up PostgreSQL 16 with a tasks database.

Example:

services:
  postgres:
    image: postgres:16.3
    container_name: postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: adminpassword
      POSTGRES_DB: tasks
    ports:
      - "5433:5432"

Ask AI: Docker PostgreSQL for Go

6. Live Reload with Air

Stop restarting the server manually. Install air and watch your changes reflect instantly.

Example terminal command:

air
# → Server restarts automatically on every save

Ask AI: Live reload Go with Air

7. CRUD – Create Task (POST, Validation & Migrations)

Build a /tasks POST route, use Gin’s binding + tags for validation, create migrations with golang-migrate, and separate queries into a repository layer.

Example validation:

type CreateTaskPayload struct {
    Title       string `json:"title" binding:"required,max=100"`
    Description string `json:"description" binding:"required,max=1000"`
}

Ask AI: CRUD Create and validation Gin

8. Read, Update & Delete Tasks (GET, PATCH, DELETE)

Finish the full CRUD set: route grouping, query parameters, PATCH with selective updates, and clean repository methods.

Example update payload:

type UpdateTaskPayload struct {
    ID          int    `json:"id" binding:"required"`
    Title       *string `json:"title" binding:"omitempty,max=100"`
    Description *string `json:"description" binding:"omitempty,max=1000"`
}

Ask AI: CRUD Read Update Delete Gin

9. Google OAuth2 + JWT Authentication

Set up a Google Cloud project, implement /login/google and /callback/google, exchange code for token, fetch user info, and sign your own JWT (24-hour expiry).

Example JWT generation:

token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
    "email": user.Email,
    "name":  user.Name,
    "exp":   time.Now().Add(time.Hour * 24).Unix(),
})
tokenString, _ := token.SignedString([]byte(config.JWT_SECRET))

Ask AI: Google OAuth JWT Go

10. Authentication Middleware (Protect Routes)

Create a reusable middleware that reads the Authorization: Bearer <token> header, verifies the JWT, and aborts with 403 if invalid/expired.

Example middleware:

func AuthMiddleware() gin.HandlerFunc {
    return func(c *gin.Context) {
        tokenString := c.GetHeader("Authorization")
        if tokenString == "" || !strings.HasPrefix(tokenString, "Bearer ") {
            c.AbortWithStatusJSON(403, gin.H{"error": "Unauthorized"})
            return
        }
        // ...parse and verify token
        c.Next()
    }
}

Ask AI: JWT middleware Gin

11. Deployment – AWS Elastic Beanstalk + RDS

Install AWS CLI, create an IAM user with limited permissions, use eb init & eb deploy, configure Procfile, connect to AWS RDS PostgreSQL (private), and run migrations in production.

Example Procfile:

web: bin/application

Ask AI: Deploy Go to AWS Elastic Beanstalk RDS


About the summarizer

I'm Ali Sol, a Backend Developer. Learn more: