-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (39 loc) · 828 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"log"
"net/http"
"os"
"plugin"
"github.com/go-chi/chi"
)
type PluginAPI interface {
RegisterRoutes(router chi.Router)
}
func main() {
// Create a new Chi router
router := chi.NewRouter()
// Load the plugin
p, err := plugin.Open("./plugins/myplugin.so")
if err != nil {
log.Fatal(err)
}
// Lookup the plugin's symbol
symbol, err := p.Lookup("Plugin")
if err != nil {
log.Fatal(err)
}
// Assert that the symbol implements PluginAPI interface
pluginAPI, ok := symbol.(PluginAPI)
if !ok {
log.Fatal("Invalid plugin")
}
// Register routes from the plugin
pluginAPI.RegisterRoutes(router)
// Start the server
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Printf("Server listening on port %s", port)
log.Fatal(http.ListenAndServe(":"+port, router))
}