Exemplo n.º 1
0
func main() {
	// Gather configuration from environment
	port := env.StringDefault("PORT", "8080")
	pwd := env.String("PWD")
	dbDir := env.StringDefault("DB_DIR", pwd+"/db")

	// Start the service
	setupDb(dbDir)
	fmt.Printf("Starting server on localhost:%v\n", port)
	log.Fatal(http.ListenAndServe(":"+port, muxer()))
}
Exemplo n.º 2
0
func init() {
	flag.StringVar(&url, "url", "", "the url to send")
	flag.StringVar(&email, "email", "", "the email to send to")
	path, _ := exec.LookPath("kindlegen")
	flag.StringVar(&kindlegen, "kindlegen", path, "the path to the kindlegen binary")

	flag.StringVar(&rdbToken, "readability", env.StringDefault("READABILITY_TOKEN", ""), "the readability token")
	flag.StringVar(&pmToken, "postmark", env.StringDefault("POSTMARK_TOKEN", ""), "the postmark token")
	flag.StringVar(&from, "from", env.StringDefault("FROM", ""), "the from address")

	flag.Parse()
}
Exemplo n.º 3
0
func main() {
	port := env.StringDefault("PORT", "9000")
	pwd := env.StringDefault("PWD", "/app")
	//
	// File Server
	//
	http.Handle("/", http.FileServer(http.Dir(pwd+"/public")))
	//
	// Start Webserver
	//
	log.Println("Starting webserver on port " + port + "...")
	log.Fatal(http.ListenAndServe(":"+port, nil))
}
Exemplo n.º 4
0
func main() {
	log.SetFlags(log.Ltime | log.Lshortfile)
	//
	// Connect to MongoDB
	//
	mongoUrl := env.StringDefault("MONGOLAB_URI", "localhost")
	log.Println("Connecting to MongoDB on " + mongoUrl + "...")
	session, err := mgo.Dial(mongoUrl)
	if err != nil {
		log.Fatal(err)
	}
	defer session.Close()
	db := session.DB("")
	_, err = db.CollectionNames()
	if err != nil || db.Name == "test" {
		log.Println("Setting db name to 'o2pro'.")
		db = session.DB("o2pro")
	}
	a := o2pro.Authorizer(fakeAuth)
	srv, err := o2pro.NewMongoServer(db, "8h", a)
	if err != nil {
		log.Fatal(err)
	}
	hf := srv.PasswordHandler()
	http.HandleFunc("/auth", hf)
	log.Println("Listening on ", addr)
	log.Fatal(http.ListenAndServe(addr, nil))
}
Exemplo n.º 5
0
func init() {
	redis := env.StringDefault("REDISCLOUD_URL", env.StringDefault("REDIS_PORT", ""))
	if redis != "" {
		cache.SetupRedis(redis, env.StringDefault("REDIS_OPTIONS", "timeout=15s&maxidle=1"))
	}

	rdbToken := env.String("READABILITY_TOKEN")
	pmToken := env.String("POSTMARK_TOKEN")
	from := env.String("FROM")
	binary, _ := exec.LookPath(fmt.Sprintf("kindlegen-%s", runtime.GOOS))

	tlogger := log.New(os.Stdout, "[tinderizer] ", env.IntDefault("LOG_FLAGS", log.LstdFlags|log.Lmicroseconds))

	app = tinderizer.New(rdbToken, pmToken, from, binary, tlogger)
	app.Run(QueueSize)

	// TODO: handle SIGINT
	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
	go shutdown(c)
}
Exemplo n.º 6
0
func SetupPostgres() error {
	dbUrl := env.StringDefault("DATABASE_URL", "postgres://")
	dsn, err := pq.ParseURL(dbUrl)
	if err != nil {
		return err
	}
	db, err := sql.Open("postgres", dsn)
	if err != nil {
		return err
	}
	dbmap.Db = db
	dbmap.Dialect = gorp.PostgresDialect{}
	return nil
}
Exemplo n.º 7
0
func (s *S) TestStrings(c *C) {
	c.Assert(func() { env.String("DOESNT_EXIST") }, Panics, errors.New("env: Environment variable DOESNT_EXIST doesn't exist"))

	os.Setenv("test", "gocheck")
	test := map[string]string{
		env.String("test"):                                               "gocheck",
		env.StringDefault("foobar", "fizzbin"):                           "fizzbin",
		env.StringDefaultF("foobar", func() string { return "fizzbot" }): "fizzbot",
	}

	for obtained, expected := range test {
		c.Assert(obtained, Equals, expected)
	}
}
Exemplo n.º 8
0
func main() {
	port := env.StringDefault("PORT", "8000")
	log.SetPrefix("[lgtts] ")
	log.SetFlags(log.Ltime | log.Ldate | log.Lshortfile)
	err := lgtts.SetupPostgres()
	if err != nil {
		log.Fatal(err)
	}
	ws := lgtts.NewWebService()
	restful.Add(ws)
	log.Printf("Listening on localhost:" + port)
	log.Fatal(http.ListenAndServe(":"+port, nil))

}
Exemplo n.º 9
0
func main() {
	port := env.StringDefault("PORT", "8080")
	baseUrl := ":" + port
	var ws restful.WebService
	ws.Path("/api").
		Consumes(restful.MIME_JSON).
		Produces(restful.MIME_JSON)
	ws.Route(ws.GET("/bar").To(getBar).
		Writes(Bar{}))
	ws.Route(ws.GET("/foo").To(getFoo).
		Writes(Foo{}))
	restful.Add(&ws)
	log.Printf("Starting webserver on %v...", baseUrl)
	log.Fatal(http.ListenAndServe(baseUrl, nil))
}
Exemplo n.º 10
0
func main() {
	log.SetFlags(log.Ltime | log.Lshortfile)
	//
	// Configuration
	//
	port := env.StringDefault("PORT", "9000")
	pwd := env.StringDefault("PWD", "/app")
	mongoUrl := env.StringDefault("MONGOLAB_URI", "localhost")
	neoUrl := env.StringDefault("NEO4J_URL", "http://localhost:7474/db/data")
	statPrefix = env.StringDefault("STATHAT_PREFIX", "")
	ezkey = env.StringDefault("STATHAT_EZKEY", "")
	//
	// Connect to MongoDB
	//
	log.Println("Connecting to MongoDB on " + mongoUrl + "...")
	session, err := mgo.Dial(mongoUrl)
	if err != nil {
		log.Panicln(err)
	}
	defer session.Close()
	mongo = session.DB("")
	_, err = mongo.CollectionNames()
	if err != nil {
		log.Println("Setting db name to 'decisions'.")
		mongo = session.DB("decisions")
	}
	//
	// Connect to Neo4j
	//
	log.Println("Connecting to Neo4j on " + neoUrl + "...")
	neo, err = neo4j.Connect(neoUrl)
	if err != nil {
		log.Println("Cannot connect to Neo4j:")
		log.Println(err)
	}
	//
	// Routing
	//
	mux := pat.New()
	mux.Post("/decide", track(http.HandlerFunc(Decide), "/v1/decide"))
	http.Handle("/v1/", http.StripPrefix("/v1", mux))
	http.Handle("/", http.FileServer(http.Dir(pwd+"/app")))
	//
	// Start Webserver
	//
	log.Println("Starting webserver on port " + port + "...")
	err = http.ListenAndServe(":"+port, nil)
	if err != nil {
		log.Panicln(err)
	}
}
Exemplo n.º 11
0
func setupMongoStorage() *srom.MongoStorage {
	//
	// Setup MongoDB
	//
	mongoUrl := env.StringDefault("MONGOLAB_URI", "localhost")
	log.Println("Connecting to MongoDB on " + mongoUrl + "...")
	session, err := mgo.Dial(mongoUrl)
	if err != nil {
		log.Panic(err)
	}
	defer session.Close()
	db := session.DB("")
	_, err = db.CollectionNames()
	if err != nil {
		log.Println("Setting db name to 'SROM'.")
		db = session.DB("SROM")
	}
	collection := db.C("terms")
	termIdx := mgo.Index{
		Key:        []string{"Term", "Timestamp"},
		Unique:     false,
		Background: true,
	}
	log.Println("Ensuring Term, Timestamp index")
	err = collection.EnsureIndex(termIdx)
	if err != nil {
		log.Panic(err)
	}
	ratioIdx := mgo.Index{
		Key:        []string{"Ratio", "Timestamp"},
		Unique:     false,
		Background: true,
	}
	log.Println("Ensuring Ratio, Timestamp index")
	err = collection.EnsureIndex(ratioIdx)
	if err != nil {
		log.Panic(err)
	}
	mongo := srom.MongoStorage{
		Col: collection,
	}
	return &mongo
}
Exemplo n.º 12
0
	"io/ioutil"
	"log"
	"os"
	"os/signal"
	"syscall"
	"text/template"
)

const (
	CoffeeScriptPath = "bookmarklet/bookmarklet.coffee"
	LessPath         = "bookmarklet/bookmarklet.less"
)

var (
	script   = make(chan []byte, 1)
	protocol = env.StringDefault("PROTOCOL", "http")
	port     = env.IntDefault("PORT", 8080)
	host     = env.StringDefaultF("CANONICAL_HOST", func() string { return fmt.Sprintf("tinderizer.dev:%d", port) })
	compress = env.StringDefault("BOOKMARKLET_PRECOMPILE", "") == "ugly"
	logger   = log.New(os.Stdout, "[bookmarklet] ", env.IntDefault("LOG_FLAGS", log.LstdFlags|log.Lmicroseconds))
)

func init() {
	script <- compileCoffeeScript(compress)
	update := make(chan os.Signal, 1)
	signal.Notify(update, syscall.SIGUSR1)
	go handleSignals(update)
}

func handleSignals(c <-chan os.Signal) {
	for _ = range c {