github.com/manicqin/nomad@v0.9.5/plugins/serve.go (about)

     1  package plugins
     2  
     3  import (
     4  	"fmt"
     5  
     6  	log "github.com/hashicorp/go-hclog"
     7  	"github.com/hashicorp/nomad/plugins/device"
     8  	"github.com/hashicorp/nomad/plugins/drivers"
     9  )
    10  
    11  // PluginFactory returns a new plugin instance
    12  type PluginFactory func(log log.Logger) interface{}
    13  
    14  // Serve is used to serve a new Nomad plugin
    15  func Serve(f PluginFactory) {
    16  	logger := log.New(&log.LoggerOptions{
    17  		Level:      log.Trace,
    18  		JSONFormat: true,
    19  	})
    20  
    21  	plugin := f(logger)
    22  	switch p := plugin.(type) {
    23  	case device.DevicePlugin:
    24  		device.Serve(p, logger)
    25  	case drivers.DriverPlugin:
    26  		drivers.Serve(p, logger)
    27  	default:
    28  		fmt.Println("Unsupported plugin type")
    29  	}
    30  }