Backend building block written in Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
bg bg: Implement BG func Jan 2, 2019
cache Add util funcs Dec 27, 2018
config Refactor: Remove ctx/app package Dec 26, 2018
context context: Implement Shipment Dec 31, 2018
crypto
disco
example Remove ctx package Jan 2, 2019
log log: Add JoinFields func Dec 28, 2018
net net/grpc: Support client/server-side streaming RPC Jan 3, 2019
schedule
stats Add util funcs Dec 27, 2018
testing testing: Randomise port sequencer Dec 31, 2018
tracing net: Fix journey KV Dec 29, 2018
.gitignore Implement job scheduler Apr 6, 2018
Gopkg.lock net/pubsub: Implement PubSub Jan 2, 2019
Gopkg.toml dep: Fix deps Dec 26, 2018
LICENSE
Makefile
README.md Remove ctx package Jan 2, 2019
ROADMAP.md Remove ctx package Jan 2, 2019
app.go
heartbeat.go

README.md

lego CircleCI Go Report Card FOSSA Status

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.toml 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 (
	"context"
	"fmt"
	"os"

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

var (
	version = "dirty"
	date    = "now"
)

type Config struct {
	Foo string `toml:"foo"`
}

func main() {
	// Create lego
	appConfig := &Config{}
	app, err := lego.New("demo", appConfig)
	if err != nil {
		return errors.Wrap(err, "error initialising lego")
	}
	app.Config().Version = version

	// Register HTTP handler
	httpServer := http.NewServer()
	httpServer.HandleFunc("/ping", http.GET, Ping)
	app.RegisterService(&lego.ServiceRegistration{
		Name:   "http.demo",
		Host:   os.Getenv("IP"),
		Port:   8080,
		Server: httpServer,
		Tags:   []string{"http"},
	})

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

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

Config

Example of a configuration file

node = "$HOSTNAME"
version = "1.1"

[request]
  timeout_ms = 1000
  allow_context = false

[disco.consul]
  address = "localhost:7500"
  dc = "local"

[log.printer.stdout]

[cache.local]

[app.demo]
  foo = "bar"

License

FOSSA Status