mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
refactor runner using titan
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user