github.com/hashicorp/go-plugin@v1.6.0/server_mux.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package plugin 5 6 import ( 7 "fmt" 8 "os" 9 ) 10 11 // ServeMuxMap is the type that is used to configure ServeMux 12 type ServeMuxMap map[string]*ServeConfig 13 14 // ServeMux is like Serve, but serves multiple types of plugins determined 15 // by the argument given on the command-line. 16 // 17 // This command doesn't return until the plugin is done being executed. Any 18 // errors are logged or output to stderr. 19 func ServeMux(m ServeMuxMap) { 20 if len(os.Args) != 2 { 21 fmt.Fprintf(os.Stderr, 22 "Invoked improperly. This is an internal command that shouldn't\n"+ 23 "be manually invoked.\n") 24 os.Exit(1) 25 } 26 27 opts, ok := m[os.Args[1]] 28 if !ok { 29 fmt.Fprintf(os.Stderr, "Unknown plugin: %s\n", os.Args[1]) 30 os.Exit(1) 31 } 32 33 Serve(opts) 34 }