๐Ÿ“š Lit - Awesome Go Library for Web Frameworks

Go Gopher mascot for Lit

Highly performant declarative web framework for Golang, aiming for simplicity and quality of life

๐Ÿท๏ธ Web Frameworks
๐Ÿ“‚ Web Frameworks
โญ 0 stars
View on GitHub ๐Ÿ”—

Detailed Description of Lit

Go Reference Go Report Card codecov

Lit ๐Ÿ”ฅ

Lit is an expressive and fast HTTP framework for Golang. It aims to enhance development by providing great simplicity, extensibility and maintainability.

Documentation

Check Lit documentation.

Getting started

Create a new Go project and import Lit with the command:

go get github.com/jvcoutinho/lit

Write this to your main.go file:

package main

import (
  "log"
  "net/http"

  "github.com/jvcoutinho/lit"
  "github.com/jvcoutinho/lit/render"
)

func main() {
  r := lit.NewRouter()
  r.Use(lit.Log)
  r.Use(lit.Recover)

  r.GET("/", HelloWorld)

  server := http.Server{Addr: ":8080", Handler: r}
  log.Fatalln(server.ListenAndServe())
}

func HelloWorld(r *lit.Request) lit.Response {
  return render.OK("Hello, World!")
}

Then you can start adding new routes and middlewares.

Features

  • Speed and efficiency: It uses httprouter, a very fast zero-allocation router. See benchmarks.
  • Expressiveness: Its constructs make room for declarative programming, creating code that is more readable, maintainable, extensible and testable.
  • Flexibility: It allows one to easily extend its constructs. Creating new validations, middlewares and responses, for example, is very simple and intuitive.
  • Idiomatic: It uses latest Go features, such as generics, in order to build a framework that is elegant to code.

Check an example of lit.Handler vs http.Handler.

Benchmarks

The instances below were tested with the specifications:

goos: windows
goarch: amd64
pkg: github.com/julienschmidt/go-http-routing-benchmark
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz

You can check the methodology or try yourself with go-http-routing-benchmark.

GitHub API

RouterMemory for handler registrationNumber repetitionsLatency per repetitionHeap memory per repetitionAllocations per repetition
Chi94888 B10000105680 ns/op61713 B/op406 allocs/op
Gin94888 B8415214056 ns/op0 B/op0 allocs/op
Lit ๐Ÿ”ฅ42088 B6598917919 ns/op0 B/op0 allocs/op
Gorilla1319632 B6121886488 ns/op199684 B/op1588 allocs/op
HttpRouter37136 B11493310511 ns/op0 B/op0 allocs/op
Martini485032 B5962070638 ns/op231420 B/op2731 allocs/op

Parse API

RouterMemory for handler registrationNumber repetitionsLatency per repetitionHeap memory per repetitionAllocations per repetition
Chi9656 B31566611549 ns/op7904 B/op52 allocs/op
Gin7864 B31180211144 ns/op0 B/op0 allocs/op
Lit ๐Ÿ”ฅ5776 B26703311342 ns/op0 B/op0 allocs/op
Gorilla105448 B7529047507 ns/op23632 B/op198 allocs/op
HttpRouter5072 B4421617816 ns/op0 B/op0 allocs/op
Martini45808 B4536279979 ns/op25696 B/op305 allocs/op

Fake API (only static routes)

RouterMemory for handler registrationNumber repetitionsLatency per repetitionHeap memory per repetitionAllocations per repetition
Chi83160 B5168569608 ns/op47728 B/op314 allocs/op
Gin34344 B3853289302 ns/op0 B/op0 allocs/op
Lit ๐Ÿ”ฅ25560 B4500727944 ns/op0 B/op0 allocs/op
Gorilla582536 B7695500949 ns/op113042 B/op1099 allocs/op
HttpRouter21712 B6384225716 ns/op0 B/op0 allocs/op
Martini309880 B3915916608 ns/op129211 B/op2031 allocs/op

As seen, Lit consumes less memory to register a batch of routes and has performance comparable to the top performers, such as Gin Gonic and HttpRouter.

Contributing

Feel free to open issues or pull requests!


Copyright (c) 2023-2024

Joรฃo Victor de Sรก Ferraz Coutinho [email protected]