goracle_driver.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2015 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 xorm
  5. import (
  6. "errors"
  7. "regexp"
  8. "github.com/go-xorm/core"
  9. )
  10. // func init() {
  11. // core.RegisterDriver("goracle", &goracleDriver{})
  12. // }
  13. type goracleDriver struct {
  14. }
  15. func (cfg *goracleDriver) Parse(driverName, dataSourceName string) (*core.Uri, error) {
  16. db := &core.Uri{DbType: core.ORACLE}
  17. dsnPattern := regexp.MustCompile(
  18. `^(?:(?P<user>.*?)(?::(?P<passwd>.*))?@)?` + // [user[:password]@]
  19. `(?:(?P<net>[^\(]*)(?:\((?P<addr>[^\)]*)\))?)?` + // [net[(addr)]]
  20. `\/(?P<dbname>.*?)` + // /dbname
  21. `(?:\?(?P<params>[^\?]*))?$`) // [?param1=value1&paramN=valueN]
  22. matches := dsnPattern.FindStringSubmatch(dataSourceName)
  23. //tlsConfigRegister := make(map[string]*tls.Config)
  24. names := dsnPattern.SubexpNames()
  25. for i, match := range matches {
  26. switch names[i] {
  27. case "dbname":
  28. db.DbName = match
  29. }
  30. }
  31. if db.DbName == "" {
  32. return nil, errors.New("dbname is empty")
  33. }
  34. return db, nil
  35. }