server_mux.go 715 B

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