This library provides a set of functions to create an web app, which provides functionalities that can be accessed via a command line client (behave like awscli), or works with an HTML5 Single Page Application.
Gregson does not aim to be a "framework" but a utility library to use existing popular Go libraries, with a set of configured settings to make web app reasonable to diagnose after it's deployed in production.
Gregson is built on the popular Golang libraries like Gin, Zerolog, and Prometheus. Given it's not framework, it directly expose data structures from the libraries it references, with a purpose to avoid introduce new concepts in code.
Gregson is built upon Go 1.14 or above, supporting go.mod
mode only.
To reference Gregson, run commands below from your Go project.
go get -v https://github.com/fuzhouch/gregson
A minimized example looks like below. It forces applying global logging
settings via InitGlobalZeroLog()
, then creates an gin.Engine
object with zerolog
and Prometheus
hooked. Once g.Run()
is called, developer can immediately see JSON log written in io.Stderr.
They can also use /metrics
path to access Prometheus metrics.
package main
import (
"io"
"github.com/gin-gonic/go"
"github.com/fuzhouch/gregson"
)
func main() {
gregson.InitGlobalZeroLog(io.Stderr)
s := gregson.NewSetting()
g := gregson.NewGin(s) // Zerolog and Prometheus are integrated.
g.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "")
})
g.Run() // Listen and serve on 0.0.0.0:8080
}
Developer can use gregson.Setting
structure to configure how
gin.Engine
object is created.
The name of this library, "Gregson", refers to Tobias Gregson, the Scotland Yard inspector who worked with Sherlock Holmes in A Study of Scalet case. He created his own theory to explain what happens, though mostly wrong, which was named by Sherlock Holmes as "the smartest detective in Scottland Yard".
I pick name "Gregson" to reflect what we may find in this library: it has its own attitude to select library and options which is needed in web development scenario, even if this is not "correct" to everyone. Customization is never part of design goals of Gregson.
For example, Gregson picks
Gin as web
framework and zerolog as logger.
If a developer wants to use echo
and logrus, don't submit a feature
request or PR. This library will not offer any customization to adopt
different frameworks. For same reason, if a developer want to change
default log level (which is forced to be zerolog.Info
), it will not
be accepted either.
The best option for these requests, is to copy useful snippets from Gregson to your code base. It's completely allowed by MIT License.