tonylinyy / core

Volatile Core

Home Page:https://volatile.whitedevops.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Volatile Core

Volatile Core is the perfect foundation for any web app as it's designed to have the best balance between readability, flexibility and performance.

It provides a pure handler (or middleware) stack so you can perform actions downstream, then filter and manipulate the response upstream.

No handlers or helpers are bundled in the Core: it does one thing and does it well.
You can find official packages below.

For a complete documentation, see the Volatile website.
You can also read all the code (~100 LOC) within minutes.

Installation

$ go get github.com/volatile/core

Usage GoDoc

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/volatile/core"
)

func main() {
	// Log
	core.Use(func(c *core.Context) {
		start := time.Now()
		c.Next()
		log.Printf(" %s  %s  %s", c.Request.Method, c.Request.URL, time.Since(start))
	})

	// Response
	core.Use(func(c *core.Context) {
		fmt.Fprint(c.ResponseWriter, "Hello, World!")
	})

	core.Run()
}

By default, your app is reachable at localhost:8080.


Note that these parameters are preset:

  • -address to set a custom listening address.
    The value is saved in Address.

  • -production to switch on production environment settings.
    Some third-party handlers may have different behaviors depending on the environment.
    The value is saved in Production.

It's up to you to call flag.Parse() in your main function if you want to use them.


Also, this package is fully compatible with the net/http.Handler interface:

package main

import (
	"fmt"
	"net/http"

	"github.com/volatile/core"
)

func main() {
	hs := core.NewHandlersStack()

	hs.Use(func(c *core.Context) {
		fmt.Fprint(c.ResponseWriter, "Hello, World!")
	})

	http.ListenAndServe(":8080", hs)
}

Official handlers

These handlers are ready to be integrated in any of your app…

  • Compress — Clever response compressing
  • CORS — Cross-Origin Resource Sharing support
  • Log — Requests logging
  • Secure — Quick security wins
  • Static — Simple assets serving
  • Others come…

Official helpers

Helpers provide syntactic sugar to ease repetitive code…

  • I18n — Simple internationalization
  • Response — Readable response helper
  • Route — Flexible routing helper
  • Others come…

About

Volatile Core

https://volatile.whitedevops.com

License:MIT License


Languages

Language:Go 100.0%