Exemple #1
0
import (
	"time"

	"github.com/ello/streams/model"
	"github.com/ello/streams/service"
	"github.com/ello/streams/util"
	"github.com/m4rw3r/uuid"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Roshi Channel Service", func() {
	var _ = Describe("Instantiation", func() {

		It("sanity?", func() {
			s, err := service.NewRoshiStreamService(util.GetEnvWithDefault("ROSHI_URL", "http://localhost:6302"), (5 * time.Second))
			Expect(err).To(BeNil())
			Expect(s).NotTo(BeNil())
		})

	})
	var s service.StreamService
	BeforeEach(func() {
		s, _ = service.NewRoshiStreamService(util.GetEnvWithDefault("ROSHI_URL", "http://localhost:6302"), (5 * time.Second))
	})

	Context(".Add", func() {
		It("will add a single content item", func() {
			chanID, _ := uuid.V4()
			contentID, _ := uuid.V4()
Exemple #2
0
func main() {

	flag.BoolVar(&help, "h", false, "help?")
	flag.Parse()

	if help {
		fmt.Println(helpMessage)
		os.Exit(0)
	}

	var logLevel log.Level

	switch util.GetEnvWithDefault("LOG_LEVEL", "warn") {
	case "debug":
		logLevel = log.DebugLevel
	case "info":
		logLevel = log.InfoLevel
	case "error":
		logLevel = log.ErrorLevel
	default:
		logLevel = log.WarnLevel
	}

	log.SetLevel(logLevel)
	fmt.Printf("Using log level [%v]\n", logLevel)

	roshi := util.GetEnvWithDefault("ROSHI_URL", "http://localhost:6302")
	streamsService, err := service.NewRoshiStreamService(roshi, time.Duration(util.GetEnvIntWithDefault("ROSHI_TIMEOUT", 5))*time.Second)
	if err != nil {
		log.Panic(err)
	}

	authConfig := api.AuthConfig{
		Username: []byte(util.GetEnvWithDefault("AUTH_USERNAME", "ello")),
		Password: []byte(util.GetEnvWithDefault("AUTH_PASSWORD", "password")),
		Enabled:  util.IsEnvPresent("AUTH_ENABLED"),
	}
	log.Infof(authConfig.String())

	if util.IsEnvPresent("LIBRATO_TOKEN") {
		go librato.Librato(metrics.DefaultRegistry,
			10e9, // interval
			os.Getenv("LIBRATO_EMAIL"),    // account owner email address
			os.Getenv("LIBRATO_TOKEN"),    // Librato API token
			os.Getenv("LIBRATO_HOSTNAME"), // source
			[]float64{0.95},               // percentiles to send
			time.Millisecond,              // time unit
		)
	}

	router := httprouter.New()

	streamsController := api.NewStreamController(streamsService, authConfig)
	streamsController.Register(router)

	healthController := api.NewHealthController(startTime, commit, roshi)
	healthController.Register(router)

	n := negroni.New(
		negroni.NewRecovery(),
		nlog.NewCustomMiddleware(logLevel, &log.TextFormatter{}, "web"),
	)
	n.UseHandler(router)

	port := util.GetEnvWithDefault("PORT", "8080")
	serverAt := ":" + port
	n.Run(serverAt)
}