Git Product home page Git Product logo

gregson's Introduction

Gregson: A REST API Server Builder

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.

Quick start

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.

About the name

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".

If you find it hard to customize... yes, it's by design

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.

gregson's People

Contributors

fuzhouch avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.