github.com/yaoapp/kun@v0.9.0/grpc/serve.go (about) 1 package grpc 2 3 import ( 4 "io" 5 6 "github.com/hashicorp/go-hclog" 7 "github.com/hashicorp/go-plugin" 8 ) 9 10 // Plugin Here is a real implementation of Pluine that writes to a local file with 11 // the key name and the contents are the value of the key. 12 type Plugin struct { 13 Logger hclog.Logger 14 } 15 16 // SetLogger set logger output 17 func (plugin *Plugin) SetLogger(output io.Writer, level Level) { 18 logger := hclog.New(&hclog.LoggerOptions{ 19 Level: hclog.Level(level), 20 Output: output, 21 JSONFormat: true, 22 }) 23 plugin.Logger = logger 24 } 25 26 // Serve GRPC Server 27 func Serve(model Model) { 28 pluginMap := map[string]plugin.Plugin{ 29 "model": &ModelGRPCPlugin{Impl: model}, 30 } 31 plugin.Serve(&plugin.ServeConfig{ 32 HandshakeConfig: Handshake, 33 Plugins: pluginMap, 34 GRPCServer: plugin.DefaultGRPCServer, 35 }) 36 }