driver.go 511 B

123456789101112131415161718192021222324252627
  1. package core
  2. type Driver interface {
  3. Parse(string, string) (*Uri, error)
  4. }
  5. var (
  6. drivers = map[string]Driver{}
  7. )
  8. func RegisterDriver(driverName string, driver Driver) {
  9. if driver == nil {
  10. panic("core: Register driver is nil")
  11. }
  12. if _, dup := drivers[driverName]; dup {
  13. panic("core: Register called twice for driver " + driverName)
  14. }
  15. drivers[driverName] = driver
  16. }
  17. func QueryDriver(driverName string) Driver {
  18. return drivers[driverName]
  19. }
  20. func RegisteredDriverSize() int {
  21. return len(drivers)
  22. }