refactor runner using titan

This commit is contained in:
Pedro Nasser
2016-07-24 17:46:08 -03:00
parent a8e984f834
commit 14cc57fd9c
12 changed files with 339 additions and 369 deletions

View File

@@ -7,16 +7,17 @@ import (
"github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/models"
"github.com/iron-io/functions/api/server/datastore"
"github.com/iron-io/functions/api/server/router"
)
type Server struct {
router *gin.Engine
cfg *Config
cfg *models.Config
}
func New(config *Config) *Server {
func New(config *models.Config) *Server {
return &Server{
router: gin.Default(),
cfg: config,
@@ -37,6 +38,10 @@ func (s *Server) Start() {
s.cfg.DatabaseURL = fmt.Sprintf("bolt://%s/bolt.db?bucket=funcs", cwd)
}
if s.cfg.API == "" {
s.cfg.API = "http://localhost:8080"
}
ds, err := datastore.New(s.cfg.DatabaseURL)
if err != nil {
logrus.WithError(err).Fatalln("Invalid DB url.")
@@ -46,6 +51,7 @@ func (s *Server) Start() {
logrus.SetLevel(logrus.DebugLevel)
s.router.Use(func(c *gin.Context) {
c.Set("config", s.cfg)
c.Set("store", ds)
c.Set("log", logrus.WithFields(extractFields(c)))
c.Next()