Example #1
0
func (s *S) TestInts(c *C) {
	c.Assert(func() { env.Int("DOESNT_EXIST") }, Panics, errors.New("env: Environment variable DOESNT_EXIST doesn't exist"))

	os.Setenv("test", "a")
	c.Assert(func() { env.Int("test") }, Panics, errors.New(`env: failed parsing int: strconv.ParseInt: parsing "a": invalid syntax`))

	os.Setenv("test", "1")
	os.Setenv("test2", "02")
	test := map[int]int{
		env.Int("test"):                                    1,
		env.Int("test2"):                                   2,
		env.IntDefault("foobar", 3):                        3,
		env.IntDefaultF("foobar", func() int { return 4 }): 4,
	}

	for obtained, expected := range test {
		c.Assert(obtained, Equals, expected)
	}
}
Example #2
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)
}
Example #3
0
	"os"
	"sync"
	"time"
)

type Any interface{}

const (
	OneHour           = 60 * 60
	MaxAttachmentSize = 10485760
	Subject           = "convert"
	FriendlyMessage   = "Sorry, email sending failed."
)

var (
	logger = log.New(os.Stdout, "[emailer] ", env.IntDefault("LOG_FLAGS", log.LstdFlags|log.Lmicroseconds))
	client http.Client
)

type Emailer struct {
	postmark *postmark.Postmark
	from     string
	wg       sync.WaitGroup
	Input    <-chan J.Job
	Output   chan<- J.Job
	Error    chan<- J.Job
}

func New(pm *postmark.Postmark, from string, input <-chan J.Job, output chan<- J.Job, error chan<- J.Job) *Emailer {
	return &Emailer{
		postmark: pm,
Example #4
0
	SubmitSuccess  = "submit.success"
	SubmitError    = "submit.error"
	SubmitEmail    = "submit.email"
	PostmarkBounce = "postmark.bounce"

	ContentType           = "Content-Type"
	Location              = "Location"
	ContentTypeHTML       = "text/html; charset=utf-8"
	ContentTypePlain      = "text/plain; charset=utf-8"
	ContentTypeJavascript = "application/javascript; charset=utf-8"
	ContentTypeJSON       = "application/json; charset=utf-8"
)

var (
	doneRegex     = regexp.MustCompile("(?i:done|failed|limited|invalid|error|sorry)")
	port          = env.IntDefault("PORT", 8080)
	canonicalHost = env.StringDefaultF("CANONICAL_HOST", func() string { return fmt.Sprintf("tinderizer.dev:%d", port) })
	logger        = log.New(os.Stdout, "[server] ", env.IntDefault("LOG_FLAGS", log.LstdFlags|log.Lmicroseconds))
	templates     = template.Must(template.ParseGlob("views/*.tmpl"))
	app           *tinderizer.App
)

type JSON map[string]interface{}

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")
Example #5
0
func SetupRedis(url, options string) {
	url = regexp.MustCompile(`^redis:`).ReplaceAllString(url, "tcp:")
	url += "/0?" + options
	logger = log.New(os.Stdout, "[redis] ", env.IntDefault("LOG_FLAGS", log.LstdFlags|log.Lmicroseconds))
	impl = newRedisCache(url)
}
Example #6
0
package config

import (
	"fmt"
	"github.com/darkhelmet/env"
	"log"
)

var (
	Port            = env.IntDefault("PORT", 5000)
	CanonicalHost   = env.StringDefaultF("CANONICAL_HOST", func() string { return fmt.Sprintf("localhost:%d", Port) })
	AssetHost       = env.StringDefaultF("ASSET_HOST", func() string { return fmt.Sprintf("http://%s", CanonicalHost) })
	LogFlags        = env.IntDefault("LOG_FLAGS", log.LstdFlags|log.Lmicroseconds)
	SiteTitle       = "Verbose Logging"
	SiteDescription = "software development with some really amazing hair"
	SiteContact     = "*****@*****.**"
	SiteAuthor      = "Daniel Huckstep"
)