machinery

module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: MIT

README

Build Status GoDoc

Machinery

Machinery for logging, configuration, abstractions for execution flow, http basic auth etc.

HTTP Basic authentication

Example:

package main

import (
	"fmt"
	"net/http"
	
	httpUtil "github.com/ncraft/machinery/pkg/http"
)

type colors []string

func main() {
	colors := colors{"red", "blue", "green"}

	authHandler := httpUtil.BasicAuthHandler{
		Username:        "user123",
		Password:        "secret",
		Realm:           "Please provide username and password",
		OriginalHandler: http.HandlerFunc(colors.list),
	}

	http.Handle("/colors", authHandler)

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

func (colors colors) list(w http.ResponseWriter, req *http.Request) {
	for _, c := range colors {
		fmt.Fprintf(w, "%s\n", c)
	}
}

Logging

Example:

package main

import "github.com/ncraft/machinery/pkg/log"

func main() {
	log.SetDebug(true)

	log.Info("running logging example")

	colors := []string{"red", "blue", "green"}

	for _, color := range colors {
		log.Debug("added color %s", color)
	}
}

Prints:

INFO: 2018/12/07 11:28:23 main.go:8: this is a log example
DEBUG: 2018/12/07 11:28:23 main.go:13: added color one
DEBUG: 2018/12/07 11:28:23 main.go:13: added color two
DEBUG: 2018/12/07 11:28:23 main.go:13: added color three

Directories

Path Synopsis
examples
log
pkg
base
Package base provides simple validations and value parsing.
Package base provides simple validations and value parsing.
flow
Package flow provides abstractions for execution flow, e.g.
Package flow provides abstractions for execution flow, e.g.
http
HTTP utils for basic authentication etc.
HTTP utils for basic authentication etc.
log
Very simple logging implementation with log levels DEBUG, INFO and ERROR.
Very simple logging implementation with log levels DEBUG, INFO and ERROR.

Jump to

Keyboard shortcuts

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