2024-10-06 13:29:01 +00:00
|
|
|
package restapi
|
|
|
|
|
|
|
|
import (
|
2024-10-19 11:09:37 +00:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2024-10-19 11:09:37 +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
|
2024-10-19 11:09:37 +00:00
|
|
|
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
|
|
|
}
|