gitmyhub

web

Go ★ 3.7k updated 2y ago

The easiest way to create web applications with Go

A minimal Go web framework that handles regex-based URL routing, secure cookies, and static file serving in about seven lines of code, inspired by Sinatra and web.py.

Gosetup: easycomplexity 2/5

web.go is a lightweight framework for building web applications in the Go programming language. A web framework provides the basic plumbing that most web services need, such as routing incoming requests to the right handler function, reading URL parameters, and sending responses. web.go aims to be minimal and not impose any particular project structure on the developer.

The framework matches incoming URL paths using regular expressions and calls the corresponding Go function. It handles secure cookies for managing user sessions, supports static file serving, and works with two alternative server protocols called FastCGI and SCGI in addition to the standard HTTP server. Because Go compiles to native machine code rather than running on a virtual machine, applications built with web.go execute quickly.

The README compares it to Sinatra (a Ruby framework) and web.py (a Python framework), positioning it as a similar thin layer for developers who want routing and helpers without a larger, more opinionated system.

Installation requires a working Go environment. Adding the library to a project is a single command: go get github.com/hoisie/web. A minimal example in the README shows a complete working web server in about seven lines of code: import the package, define a handler function that returns a string, register a route with web.Get, and call web.Run with a host and port. Handler functions can also accept a context object that carries request data including URL query parameters.

API documentation is hosted separately. The project was written by Michael Hoisie and is one of the early Go web frameworks, predating more widely adopted options that came later in the Go ecosystem.

Where it fits