driver.go 673 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2019 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package core
  5. type Driver interface {
  6. Parse(string, string) (*Uri, error)
  7. }
  8. var (
  9. drivers = map[string]Driver{}
  10. )
  11. func RegisterDriver(driverName string, driver Driver) {
  12. if driver == nil {
  13. panic("core: Register driver is nil")
  14. }
  15. if _, dup := drivers[driverName]; dup {
  16. panic("core: Register called twice for driver " + driverName)
  17. }
  18. drivers[driverName] = driver
  19. }
  20. func QueryDriver(driverName string) Driver {
  21. return drivers[driverName]
  22. }
  23. func RegisteredDriverSize() int {
  24. return len(drivers)
  25. }