Sitemap
Urban (@officialurbanus)

Urban (@officialurbanus)

Check out my primary publication on Substack - https://theofficialurban.substack.com - All link https://bio.link/officialurban

Go Module Recommendations

3 min readApr 2, 2024

--

Chi HTTP Framework

Documentation | GitHub

Installation

go get -u github.com/go-chi/chi/v5

Features

  • Lightweight — cloc’d in ~1000 LOC for the chi router
  • Fast — yes, see benchmarks
  • 100% compatible with net/http — use any http or middleware pkg in the ecosystem that is also compatible with net/http
  • Designed for modular/composable APIs — middlewares, inline middlewares, route groups and sub-router mounting
  • Context control — built on new context package, providing value chaining, cancellations and timeouts
  • Robust — in production at Pressly, CloudFlare, Heroku, 99Designs, and many others (see discussion)
  • Doc generation — docgen auto-generates routing documentation from your source to JSON or Markdown
  • Go.mod support — as of v5, go.mod support (see CHANGELOG)
  • No external dependencies — plain ol’ Go stdlib + net/http

SQL /w BunSQL

Documentation | GitHub

Bun is a SQL-first database client for Go. SQL-first means that most SQL queries can be automatically compiled to Bun expressions and Bun expressions look and feel like SQL queries.

The purpose of Bun is to allow writing queries using the good old SQL and to help scanning results into common Go types: structs, maps, slices, and scalars (— Bun Team)

Installation

Bun Module

go get github.com/uptrace/bun@latest

(Example) postgres Driver & Dialect

Bun offers multiple different drivers/dialects for most types of SQL — As an example, I’m using Postgres, so I will install the Postgres Driver & Dialect.

go get github.com/uptrace/bun/driver/pgdriver && go get github.com/uptrace/bun/dialect/pgdialect

</> TEMPL Templating Engine

Documentation | GitHub

Get Urban (@officialurbanus)’s stories in your inbox

Join Medium for free to get updates from this writer.

Create components that render fragments of HTML and compose them to create screens, pages, documents, or apps.

  • Server-side rendering: Deploy as a serverless function, Docker container, or standard Go program.
  • Static rendering: Create static HTML files to deploy however you choose.
  • Compiled code: Components are compiled into performant Go code.
  • Use Go: Call any Go code, and use standard if, switch, and for statements.
  • No JavaScript: Does not require any client or server-side JavaScript.
  • Great developer experience: Ships with IDE autocompletion.

Installation

CLI Installation

go install github.com/a-h/templ/cmd/templ@latest

Module Installation

go get github.com/a-h/templ

VS-Code Settings

Official TEMPL VS-Code Extension

"tailwindCSS.includeLanguages": {
"templ": "html"
},
"[templ]": {
"editor.defaultFormatter": "a-h.templ"
},
"emmet.includeLanguages": {
"templ": "html"
},

BabyAPI — The EASIEST Way To Create APIs

Documentation | GitHub

babyapi is a super simple framework that automatically creates an HTTP API for create, read, update, and delete operations on a struct. Simply extend the babyapi.DefaultResource type to get started.

Implement custom request/response handling by implemented Renderer and Binder from go-chi/render. Use provided extension functions to add additional API functionality:

  • OnCreateOrUpdate: additional handling for create/update requests
  • Storage: set a different storage backend implementing the babyapi.Storage interface
  • AddCustomRoute: add more routes on the base API
  • Patch: add custom logic for handling PATCH requests
  • And many more! (see examples and docs)
  • Override any of the default handlers and use babyapi.Handler shortcut to easily render errors and responses

Installation

go get github.com/calvinmclean/babyapi

Example

package main

import (
"github.com/calvinmclean/babyapi"
)

type Person struct {
babyapi.DefaultResource
Name string `json:"name"`
Age int `json:"age"`
}

func main() {
api := babyapi.NewAPI[*Person](
"PERSONs", "/api/persons",
func() *Person {
// Return Default Person
return &Person{
Name: "<NAME>",
Age: -1
}
},
)
// This code sets up a FULL REST/CRUD API, endpoints and everything!
// (GET) /api/persons - Returns all persons
// (GET) /api/persons/{id} - Returns person by ID
// (POST) /api/persons - POST a new person
// (DELETE) /api/persons/{id} - Delete a person
// & More...
}

--

--