Sha256: c3c1e0986ab20e439c0d9227cbd5c32e6fd4a8b75718f18da3a51b1128962cb5

Contents?: true

Size: 1.57 KB

Versions: 14

Compression:

Stored size: 1.57 KB

Contents

package main

import (
	"fmt"
	"net/http"
	"os"
	"log"
	"log/syslog"
	"<%= namespace %>/<%= application_name %>/global"
	"<%= namespace %>/<%= application_name %>/handlers"

	"github.com/facebookgo/inject"
	"github.com/alexcesaro/statsd"
)

func main() {
	config := os.Args[1]
	rootfolder := os.Args[2]

	global.LoadConfig(config, rootfolder)

	setupInjection()
	setupHandlers()
}

func setupHandlers() {
	http.Handle("/", handlers.GetRouter())

	fmt.Println("Listening for connections on port", 8001)
	http.ListenAndServe(fmt.Sprintf(":%v", 8001), nil)
}

func setupInjection() {
	var g inject.Graph

	var err error

	statsdClient, err := statsd.New(statsd.Address(global.Config.StatsDServerIP)) // reference to a statsd client
	if err != nil {
		panic(fmt.Sprintln("Unable to create StatsD Client: ", err))
	}

	syslogWriter, err := syslog.Dial("udp", global.Config.SysLogIP, syslog.LOG_SYSLOG, "sorcery")
	if err != nil {
		panic(fmt.Sprintln("Unable to connect to syslog: ", err))
	}

	logWriter := log.New(syslogWriter, "<%= application_name %>: ", log.Lshortfile)

	err = g.Provide(
		&inject.Object{Value: handlers.RouterDependencies},
		&inject.Object{Value: handlers.HealthDependencies},
		&inject.Object{Value: handlers.EchoDependencies},
		&inject.Object{Value: statsdClient, Name: "statsd"},
		&inject.Object{Value: logWriter},
	)

	if err != nil {
		fmt.Println(err)
	}

	// Here the Populate call is creating instances of NameAPI &
	// PlanetAPI, and setting the HTTPTransport on both to the
	// http.DefaultTransport provided above:
	if err := g.Populate(); err != nil {
		fmt.Println(err)
	}
}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
minke-generator-go-0.8.7 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.8.6 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.8.5 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.8.4 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.8.3 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.8.2 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.8.1 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.8.0 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.7.2 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.7.1 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.7.0 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.6.0 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.5.0 lib/generators/gomicroservice/scaffold/main.go.erb
minke-generator-go-0.4.0 lib/generators/gomicroservice/scaffold/main.go.erb