mirror of
https://github.com/danielmiessler/fabric
synced 2024-11-08 07:11:06 +00:00
29 lines
506 B
Go
29 lines
506 B
Go
package restapi
|
|
|
|
import (
|
|
"github.com/danielmiessler/fabric/core"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func Serve(registry *core.PluginRegistry, address string) (err error) {
|
|
r := gin.Default()
|
|
|
|
// Middleware
|
|
r.Use(gin.Logger())
|
|
r.Use(gin.Recovery())
|
|
|
|
// Register routes
|
|
fabricDb := registry.Db
|
|
NewPatternsHandler(r, fabricDb.Patterns)
|
|
NewContextsHandler(r, fabricDb.Contexts)
|
|
NewSessionsHandler(r, fabricDb.Sessions)
|
|
|
|
// Start server
|
|
err = r.Run(address)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return
|
|
}
|