lego

package module
v0.0.0-...-ef924d7 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2016 License: MIT Imports: 12 Imported by: 0

README

lego

CONFIG_URI=file://${PWD}/config/dev.json go run main.go -logtostderr

Setup

Basic setup

package main

import (
	"flag"
	"fmt"
	"os"

    "github.com/stairlin/lego"
    "github.com/stairlin/lego/handler/http"
)

func main() {
    flag.Parse()

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

    // Register HTTP handler
    h := http.NewHandler()
    h.Handle("/ping", http.GET, &Ping{})
    app.RegisterHandler("127.0.0.1:3000", h)

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

// HTTP handler example
type Ping struct{}
func (a *Ping) Call(c *http.Context) http.Renderer {
    c.Ctx.Info("action.ping")
    return c.Head(http.StatusOK)
}

Config

Example of a configuration file

{
  "log": {
    "level": "trace",
    "output": "console",
    "config": { }
  },
  "stats": {
    "on": false
  }
}

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(name string, appConfig interface{}) (*App, error)

New creates a new App and returns it

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) RegisterHandler

func (a *App) RegisterHandler(addr string, h handler.H)

RegisterHandler adds the given handler to the list of handlers

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 configuraton (dev, prod, ...)
Package config implements logic to load dynamic configuration from various sources It also defines environment specific configuraton (dev, prod, ...)
adapter/etcd
Package etcd reads configuration from etcd
Package etcd reads configuration from etcd
adapter/file
Package file reads configuration from a JSON file
Package file reads configuration from a JSON file
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.
Package handler contains the main logic to accept external requests.
Package handler contains the main logic to accept external requests.
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 log implements logging with different levels of severity.
Package log implements logging with different levels of severity.
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