Build Fast, Reliable Backends with Golang
Discovery Week – MicroClub
Go powers some of the biggest systems on the internet!
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000);
package main
import (
"net/http"
"github.com/go-chi/chi/v5"
)
func main() {
r := chi.NewRouter()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
})
http.ListenAndServe(":3000", r)
}
GET /posts
POST /posts
GET /posts/{id}
DELETE /posts/{id}
Storage: In-memory
// Post represents a blog post
type Post struct {
ID int `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Author string `json:"author"`
}
// In-memory storage
var posts []Post
var nextID = 1
func getPosts(w http.ResponseWriter, r *http.Request) {
// Set content type
w.Header().Set("Content-Type", "application/json")
// Encode posts to JSON and send response
if err := json.NewEncoder(w).Encode(posts); err != nil {
http.Error(w, "Error encoding posts", http.StatusInternalServerError)
return
}
}
Challenge: Build a small project in Go this week!
Let's discuss Go and answer your questions!
Workshop materials: Available on GitHub
Stay connected: Join our community discussions