lego

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2017 License: MIT Imports: 12 Imported by: 0

README

lego CircleCI Go Report Card

Why

People don't buy painting, they buy painted walls.

Go is gaining popularity at exponential speed, but adopting the language to build web applications at the early stage of a company can be challenging due to the lack of ready-to-use tools. LEGO has been solving that problem with a framework that contains the tools required to build robust distributed services. LEGO made most of the decisions for you, so that you can focus on bringing more values to your products.

Manifesto

1. Grow with the product
2. Defer decisions
3. Not for everyone
1. Grow with the product

LEGO is a framework designed to grow with developers from the first service to multiple resilient microservices at decent scale.

2. Defer decisions

Making technical decisions can be needlessly time consuming, especially at the early stage of a product development. That is the reason why LEGO made a lot of these decisions for you and as trivial as possible. That means you won't be locked-in into a specific vendor technology.

3. Not for everyone

Even though LEGO can grow with your product, it does not necessarily mean that it is the right choice for you. LEGO primarily solves Stairlin's problems and may discard very important problems in your product. Nevertheless, LEGO is open to new ideas and contributions as long as they are consistent with our philosophy.

Demo

Start a simple HTTP server

$ git clone https://github.com/stairlin/lego.git
$ cd lego/example
$ CONFIG_URI=file://${PWD}/config.json go run http_server.go

Send a request

$ curl -v http://127.0.0.1:3000/ping

Example

Simple HTTP server

This code creates a LEGO instance and attach and HTTP handler to it with one route /ping.

package main

import (
	"fmt"
	"os"

	"github.com/stairlin/lego"
	"github.com/stairlin/lego/ctx/journey"
	"github.com/stairlin/lego/log"
	"github.com/stairlin/lego/net/http"
)

type AppConfig struct {
	Foo string `json:"foo"`
}

func main() {
	// Create lego
	config := &AppConfig{}
	app, err := lego.New("api", config)
	if err != nil {
		fmt.Println("Problem initialising lego", err)
		os.Exit(1)
	}

	// Register HTTP handler
	s := http.NewServer()
	s.HandleFunc("/ping", http.GET, Ping)
	app.RegisterServer("127.0.0.1:3000", s)

	// Start serving requests
	err = app.Serve()
	if err != nil {
		fmt.Println("Problem serving requests", err)
		os.Exit(1)
	}
}

// Ping handler example
func Ping(ctx journey.Ctx, w http.ResponseWriter, r *http.Request) {
	ctx.Trace("action.ping", "Simple request", log.String("ua", r.HTTP.UserAgent()))
	w.Head(http.StatusOK)
}

Config

Example of a configuration file

{
    "node": "node.test",
    "version": "test",
    "log": {
        "level": "trace",
        "formatter": {
            "adapter": "logf"
        },
        "printer": {
            "adapter": "stdout"
        }
    },
    "stats": {
        "on": false
    },
    "request": {
        "timeout_ms": 500
    },
    "app": {
        "foo": "bar"
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is the core structure for a new service

func New

func New(service string, appConfig interface{}) (*App, error)

New creates a new App and returns it

func NewWithConfig added in v0.2.0

func NewWithConfig(service string, c *config.Config) (*App, error)

NewWithConfig creates a new App with the config config

func (*App) Config

func (a *App) Config() *config.Config

Config returns the lego config

func (*App) Ctx

func (a *App) Ctx() app.Ctx

Ctx returns the appliation context

func (*App) Drain

func (a *App) Drain()

Drain notify all handlers to enter in draining mode. It means they are no longer accepting new requests, but they can finish all in-flight requests

func (*App) Ready

func (a *App) Ready()

Ready holds the callee until the app is fully operational

func (*App) RegisterServer added in v1.3.0

func (a *App) RegisterServer(addr string, s net.Server)

RegisterServer adds the given server to the list of managed servers

func (*App) Serve

func (a *App) Serve() error

Serve allows handlers to serve requests and blocks the call

Directories

Path Synopsis
Package bg aims to manage all background jobs run on lego.
Package bg aims to manage all background jobs run on lego.
Package config implements logic to load dynamic configuration from various sources It also defines environment specific configuration (dev, prod, ...)
Package config implements logic to load dynamic configuration from various sources It also defines environment specific configuration (dev, prod, ...)
adapter/consul
Package consul reads configuration from the Consul KV store Consul is a highly available and distributed service discovery and key-value store designed with support for the modern data center to make distributed systems and configuration easy.
Package consul reads configuration from the Consul KV store Consul is a highly available and distributed service discovery and key-value store designed with support for the modern data center to make distributed systems and configuration easy.
adapter/file
Package file reads configuration from a JSON file e.g.
Package file reads configuration from a JSON file e.g.
ctx
Package ctx defines the context types, which carry information defined for a specific scope (application, request, ...) A context can be passed across API boundaries and between processes.
Package ctx defines the context types, which carry information defined for a specific scope (application, request, ...) A context can be passed across API boundaries and between processes.
app
Package app defines an application context, which carries information about the application environment.
Package app defines an application context, which carries information about the application environment.
journey
Package journey defines a context type, which carries information about a specific inbound request.
Package journey defines a context type, which carries information about a specific inbound request.
log
Package log defines the logging facade A logger is composed of a formatter that serialises the log structure into a text line, and a log printer that outputs the formatted log lines.
Package log defines the logging facade A logger is composed of a formatter that serialises the log structure into a text line, and a log printer that outputs the formatted log lines.
formatter/json
Package json is a JSON log formatter.
Package json is a JSON log formatter.
formatter/logf
Package logf is a human friendly log formatter.
Package logf is a human friendly log formatter.
printer/stdout
Package stdout prints log lines into the standard output.
Package stdout prints log lines into the standard output.
net
Package net contains the main logic to send and receive requests I defines interfaces shared by other packages that accept or send requests Packages that implement these interfaces include: * net/http It also manages the lifecycle of the handlers.
Package net contains the main logic to send and receive requests I defines interfaces shared by other packages that accept or send requests Packages that implement these interfaces include: * net/http It also manages the lifecycle of the handlers.
http
Package http is an extra layer on to of the standard go net/http package.
Package http is an extra layer on to of the standard go net/http package.
Package stats provides functions for reporting metrics to a service.
Package stats provides functions for reporting metrics to a service.
Package testing is an extension to the standard go testing package tailored for testing the lego framework.
Package testing is an extension to the standard go testing package tailored for testing the lego framework.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL