This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
53 lines (46 loc) · 1.5 KB
/
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
50
51
52
53
package main
import (
"flag"
"os"
sdkConfig "github.com/gatewayd-io/gatewayd-plugin-sdk/config"
"github.com/gatewayd-io/gatewayd-plugin-sdk/logging"
"github.com/gatewayd-io/gatewayd-plugin-sdk/metrics"
p "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin"
v1 "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1"
"github.com/gatewayd-io/plugin-template-go/plugin"
"github.com/hashicorp/go-hclog"
goplugin "github.com/hashicorp/go-plugin"
"github.com/spf13/cast"
)
func main() {
// Parse command line flags, passed by GatewayD via the plugin config
logLevel := flag.String("log-level", "info", "Log level")
flag.Parse()
logger := hclog.New(&hclog.LoggerOptions{
Level: logging.GetLogLevel(*logLevel),
Output: os.Stderr,
JSONFormat: true,
Color: hclog.ColorOff,
})
pluginInstance := plugin.NewTemplatePlugin(plugin.Plugin{
Logger: logger,
})
if cfg := cast.ToStringMap(plugin.PluginConfig["config"]); cfg != nil {
metricsConfig := metrics.NewMetricsConfig(cfg)
if metricsConfig != nil && metricsConfig.Enabled {
go metrics.ExposeMetrics(metricsConfig, logger)
}
}
goplugin.Serve(&goplugin.ServeConfig{
HandshakeConfig: goplugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: sdkConfig.GetEnv("MAGIC_COOKIE_KEY", ""),
MagicCookieValue: sdkConfig.GetEnv("MAGIC_COOKIE_VALUE", ""),
},
Plugins: v1.GetPluginSetMap(map[string]goplugin.Plugin{
plugin.PluginID.GetName(): pluginInstance,
}),
GRPCServer: p.DefaultGRPCServer,
Logger: logger,
})
}