fabric/restapi/serve.go

29 lines
506 B
Go
Raw Normal View History

2024-10-06 13:29:01 +00:00
package restapi
import (
"github.com/danielmiessler/fabric/core"
2024-10-12 19:25:17 +00:00
"github.com/gin-gonic/gin"
2024-10-06 13:29:01 +00:00
)
func Serve(registry *core.PluginRegistry, address string) (err error) {
2024-10-12 19:25:17 +00:00
r := gin.Default()
2024-10-06 13:29:01 +00:00
// Middleware
2024-10-12 19:25:17 +00:00
r.Use(gin.Logger())
r.Use(gin.Recovery())
2024-10-06 13:29:01 +00:00
// Register routes
fabricDb := registry.Db
2024-10-12 19:25:17 +00:00
NewPatternsHandler(r, fabricDb.Patterns)
NewContextsHandler(r, fabricDb.Contexts)
NewSessionsHandler(r, fabricDb.Sessions)
2024-10-06 13:29:01 +00:00
// Start server
2024-10-12 19:25:17 +00:00
err = r.Run(address)
if err != nil {
return err
}
2024-10-06 13:40:29 +00:00
return
2024-10-06 13:29:01 +00:00
}