Example #1
0
package hawk

import (
	"fmt"
	"github.com/gorilla/mux"
	"github.com/pzduniak/log"
	"github.com/pzduniak/utility"
	"net/http"
	"reflect"
)

var Log = log.NewSub("hawk")

type Application struct {
	router      *mux.Router
	routesCount int
}

// Creates a new application object
func NewApplication() *Application {
	instance := new(Application)
	instance.router = mux.NewRouter()
	instance.router.NotFoundHandler = http.HandlerFunc(instance.NotFound)
	instance.routesCount = 0
	return instance
}

// Mapping of HTTP methods to struct methods
var http_mapping = map[string]string{
	"GET":    "Get",
	"POST":   "Post",
Example #2
0
package config

import (
	"github.com/laurent22/toml-go/toml"
	"github.com/pzduniak/log"
	"time"
)

var Log = log.NewSub("config")

// This file creates a singleton accessible by including the module.
// It wraps every Get function from laurent22's toml-go library.
// Use it like a document.

// I believe there would be no use for it if it was exported
var document toml.Document

// Load the settings file
func Load(path string) {
	// Print a message (of course we're lying)
	Log.Printf("loaded settings from %s", path)
	// Create a new parser
	var parser toml.Parser
	// Parse the file
	document = parser.ParseFile(path)
}

// Returns a slice of toml.Values from the TOML file
func GetArray(name string, defaultValue []toml.Value) []toml.Value {
	return document.GetArray(name, defaultValue)
}
Example #3
0
package tokener

import (
	"github.com/dchest/uniuri"
	"github.com/pzduniak/log"
	"github.com/pzduniak/utility"
	"io/ioutil"
	"os"
)

var logger = log.NewSub("tokener")
var secret string

const secretfile = ".secret"

func init() {
	// If the file exists, read the current secret
	if utility.FileExists(secretfile) {
		// Read the file
		contents, _ := ioutil.ReadFile(secretfile)
		// Set the secret
		secret = string(contents)
		// Print it to the logs
		logger.Printf("%s loaded", secretfile)
	} else {
		// Generate a new random 32 char-long string
		secret = uniuri.NewLen(32)
		// Write it to the secretfile
		ioutil.WriteFile(secretfile, []byte(secret), os.ModePerm)
		// Print it to the logs
		logger.Printf("%s created", secretfile)