File: server_mux.go

package info (click to toggle)
golang-github-hashicorp-go-plugin 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 552 kB
  • sloc: python: 38; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 715 bytes parent folder | download | duplicates (6)
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
package plugin

import (
	"fmt"
	"os"
)

// ServeMuxMap is the type that is used to configure ServeMux
type ServeMuxMap map[string]*ServeConfig

// ServeMux is like Serve, but serves multiple types of plugins determined
// by the argument given on the command-line.
//
// This command doesn't return until the plugin is done being executed. Any
// errors are logged or output to stderr.
func ServeMux(m ServeMuxMap) {
	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr,
			"Invoked improperly. This is an internal command that shouldn't\n"+
				"be manually invoked.\n")
		os.Exit(1)
	}

	opts, ok := m[os.Args[1]]
	if !ok {
		fmt.Fprintf(os.Stderr, "Unknown plugin: %s\n", os.Args[1])
		os.Exit(1)
	}

	Serve(opts)
}