A collection of small, focused Go projects—each folder is its own “tiny lab” exploring one idea (HTTP routing, cookies, sessions, DB access, WebSockets, templates, etc.).
Most folders are standalone Go modules (they include a go.mod). A few are single-file examples without modules.
# pick a folder and run it
cd <project-folder>
go run .If a folder doesn’t have a main.go (or doesn’t compile as-is), run the specific file called out in that section.
crud-go-apiform-login-logoutgo-cachego-fiber-crm-basichttp-clienthttp-errorhttp-image-generator-apihttp-request-gorilla-muxhttp-resthttp-serverhttp-sessionmysql-book-managermysql-db-gosecure-cookieserving-templatestcp-serveruploading-filewebsockets-go
What it is: A tiny REST-ish CRUD API for a Movie resource using Gorilla Mux and in-memory storage.
Key ideas:
- Routing with path params (
/movies/{id}) and HTTP methods. - Encoding/decoding JSON with
encoding/json. - In-memory slice as a “database” (great for learning flows without persistence complexity).
Main file: crud-go-api/main.go
Endpoints:
GET /movies→ list all moviesGET /movies/{id}→ fetch one moviePOST /movies/→ create a movie (reads JSON body)PUT /movies/{id}→ update a movie (reads JSON body)DELETE /movies/{id}→ delete a movie
Run:
cd crud-go-api
go run .
# server: http://localhost:8000What it is: UI templates for a login flow (HTML only right now). The Go server file (html-form-auth.go) exists but is empty.
Key ideas:
- Template structure for authentication UI:
templates/login-form.html(basic login form)templates/home.html(home screen with logout form)
Run:
- Not runnable yet (no server implementation in
html-form-auth.go).
Suggested next step (if you want to evolve it):
- Add handlers for
GET /(show login),POST /login(validate),POST /logout(clear session/cookie) and render these templates.
What it is: A tiny HTTP server that demonstrates in-memory caching using github.com/patrickmn/go-cache.
Key ideas:
- Application-level cache with TTL:
- cache is created with a default expiration (5 minutes)
- a sample key
foo=baris stored ininit()
- Simple “read-through” behavior: on request, attempt cache read and return a response.
Main file: go-cache/go-cache.go
Run:
cd go-cache
go run .
# server: http://localhost:8080Try:
GET /→ returnsHello bar(as long as the cached key exists and hasn’t expired)
What it is: A minimal “CRM-style” API skeleton using Fiber + GORM with SQLite (leads.db).
Key ideas:
- Fiber routing under
/api/v1/... - SQLite persistence via GORM
- Auto-migration for the
Leadmodel
Main files:
go-fiber-crm-basic/main.go(server + routes + DB init)go-fiber-crm-basic/lead/lead.go(model + handlers)go-fiber-crm-basic/database/database.go(global DB connection)
Routes (intended):
GET /api/v1/lead→ list leadsGET /api/v1/lead/:id→ fetch a leadPOST /api/v1/lead→ create a leadDELETE /api/v1/lead/:id→ delete a lead
Run:
cd go-fiber-crm-basic
go run .
# server: http://localhost:3000What it is: An example of building an HTTP “client façade” using Resty to call another service, with Gorilla Mux routes defined for local endpoints.
Key ideas:
- Calling a backing service at
http://localhost:8080using Resty:GET /employeesproxies toGET http://localhost:8080/employeesPOST /employee/addproxies toPOST http://localhost:8080/employee/add
- Decoding JSON request bodies into Go structs.
Main file: http-client/http-rest-client.go
Run (as-is):
- The router is set up, but
http.ListenAndServe(...)isn’t called inmain(), so it won’t start a server until that’s added.
When completed, you’d expect:
- Local server on
localhost:8090forwarding requests to a “real” service onlocalhost:8080.
What it is: A pattern for centralized HTTP error handling by wrapping handlers that can return errors.
Key ideas:
- Define
type WrapperHandler func(http.ResponseWriter, *http.Request) error - Implement
ServeHTTPon that function type to handle errors consistently. - Use a custom error type (
NameNotFoundError) to map business errors to HTTP status codes.
Main file: http-error/http-error.go
Run:
cd http-error
go run .
# server: http://localhost:8080Try:
GET /employee/get/foo→Hello fooGET /employee/get/anything-else→ error response
What it is: A small Gin API showcasing route groups, JSON binding/validation, and file upload handling.
Key ideas:
r.Group("/user")to group routesBindJSONwith validation tags (example:emailrequired)- Multipart upload with
FormFileandSaveUploadedFile
Main file: http-image-generator-api/main.go
Run:
cd http-image-generator-api
go run .
# server: http://localhost:8080 (Gin default)Endpoints:
GET /user/hello/:name→ text greetingPOST /user/post→ validates and echoes JSON payloadPOST /user/upload→ uploads a file and saves it to/tmp/tempfile
What it is: A Gorilla Mux server that demonstrates:
- Basic routing
- Request logging middleware (
gorilla/handlers) - Path variables
Main file: http-request-gorilla-mux/gorilla-mux-routing.go
Run:
cd http-request-gorilla-mux
go run .
# server: http://localhost:8080Endpoints:
GET /→Hello Go(logged to stdout)POST /post→I am posting(logged toserver.log)GET /hello/{name}→Hi{name}(combined logging toserver.log)
What it is: A compact REST API for an Employee resource, including versioned endpoints (/v1, /v2).
Key ideas:
- Route table pattern (
Routesslice) + helper (AddRoutes) - Basic CRUD-ish flows (in-memory slice)
- Versioning via subrouters:
/v1/employees/v2/employees
Main file: http-rest/http-rest-api.go
Run:
cd http-rest
go run .
# server: http://localhost:8080Endpoints:
GET /employees→ base datasetGET /employee/{id}→ fetch by IDPOST /employee/add→ addPUT /employee/update→ update (upsert behavior)DELETE /employee/delete→ delete (expects JSON body)GET /v1/employees→ v1 datasetGET /v2/employees→ v2 dataset
What it is: A “hello world” HTTP server protected by Basic Auth, using constant-time comparisons.
Key ideas:
r.BasicAuth()extractioncrypto/subtlefor constant-time string comparison- Wrapper auth middleware returning
http.HandlerFunc
Main file: http-server/http-server.go
Run:
cd http-server
go run .
# server: http://localhost:8080Try:
GET /→ requires basic auth (admin/admin)GET /loginandGET /logout→ simple text pages
What it is: A minimal authentication session example using Redis-backed sessions via redistore (Gorilla sessions).
Key ideas:
- Redis-backed session store:
- connects to
localhost:6379 - session key:
"session-name" - session value:
authenticated=true/false
- connects to
- Route protection:
/homechecks the session value before allowing access.
Main file: http-session/http-session.go
Run:
cd http-session
go run .
# server: http://localhost:8080Prerequisites:
- Redis running on
localhost:6379
Endpoints:
GET /login→ setsauthenticated=trueGET /home→ requiresauthenticated=trueGET /logout→ setsauthenticated=false
What it is: A small REST API for managing Book records using Gorilla Mux + GORM + MySQL.
Key ideas:
- “Package layering” (config → models → controllers → routes)
- GORM auto-migration of the
Bookmodel on init - CRUD endpoints with path params (
/book/{bookId})
Main files:
mysql-book-manager/cmd/main/main.go(server entrypoint)mysql-book-manager/pkg/config/app.go(MySQL connection)mysql-book-manager/pkg/models/book.go(GORM model + queries)mysql-book-manager/pkg/controllers/book-controller.go(HTTP handlers)mysql-book-manager/pkg/routes/bookstore-routes.go(route registration)mysql-book-manager/pkg/utils/utils.go(body parsing helper)
Run:
cd mysql-book-manager
go run ./cmd/main
# server: http://localhost:9010Prerequisites:
- A MySQL instance reachable with the DSN in
pkg/config/app.go
Endpoints:
POST /book/→ create book (JSON body)GET /book/→ list booksGET /book/{bookId}→ fetch by IDPUT /book/{bookId}→ updateDELETE /book/{bookId}→ delete (note: route path in code is missing a leading/)
What it is: A direct MySQL CRUD demo using the standard library database/sql (plus Gorilla Mux for routing).
Key ideas:
sql.Open+db.Query+db.Exec- Prepared statements for update/delete
- Mix of path params and query params
Main file: mysql-db-go/connect-mysql.go
Run:
cd mysql-db-go
go run .
# server: http://localhost:8080Prerequisites:
- MySQL running and a database/table matching:
- DSN:
root:@/mydb - table:
employee(columns expected:id,name)
- DSN:
Endpoints:
GET /→ prints current DB nameGET /employees→ list recordsPOST /employee/create?name=Alice→ insertPUT /employee/update/{id}?name=Bob→ updateDELETE /employee/delete?name=Bob→ delete by name
What it is: A demonstration of signed/encoded cookies using gorilla/securecookie.
Key ideas:
- Create a secure cookie with generated hash + block keys.
- Encode a map payload into a cookie value.
- Decode and read that payload back on later requests.
Main file: secure-cookie/http-cookie.go
Run:
cd secure-cookie
go run .
# server: http://localhost:8080Endpoints:
GET /create→ sets cookiefirst-cookieGET /read→ reads and decodesfirst-cookie
What it is: A small server that serves HTML templates and static assets, plus a login form with validation.
Key ideas:
- Template rendering with
html/template - Static assets with
http.FileServermounted under/static/ - Form parsing + schema decoding
- Validation using
govalidator(alpha + required)
Main files:
serving-templates/first-template.goserving-templates/templates/first-template.htmlserving-templates/templates/login-form.htmlserving-templates/static/main.css
Run:
cd serving-templates
go run .
# server: http://localhost:8080Flow:
GET /→ shows login form templatePOST /→ validates fields and responds with a greeting or validation message/static/*→ serves CSS
What it is: A minimal TCP echo server using net—a great contrast to the HTTP examples.
Key ideas:
net.Listen("tcp", ...)- Accept loop + per-connection goroutine
- Read until newline and echo back
Main file: tcp-server/tcp-server.go
Run:
go run tcp-server/tcp-server.go
# server: tcp://localhost:8080Try:
nc localhost 8080
hello thereWhat it is: A minimal HTML + Go server that accepts file uploads using multipart form data.
Key ideas:
r.FormFile("file")to fetch uploaded file- Persist uploaded bytes using
io.Copy - Render a simple upload HTML form
Main files:
uploading-file/upload-file.gouploading-file/templates/upload-file.html
Run:
go run uploading-file/upload-file.go
# server: http://localhost:8080Endpoints:
GET /→ upload formPOST /upload→ saves file totmp/uploadedFile
What it is: A broadcast-style WebSocket server using gorilla/websocket where messages from one client are fanned out to all connected clients.
Key ideas:
- WebSocket upgrade + connection tracking in a
clientsmap - Broadcast channel to decouple read/write loops
- Server-side fan-out to all active clients
Main file: websockets-go/websocket-server.go
Run:
cd websockets-go
go run .
# server: http://localhost:8080Endpoints:
GET /→ servesindex.html(client page)GET /echo→ WebSocket endpoint (JSON messages like{ "message": "hi" })