github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/go-xorm/xorm/oci8_driver.go (about) 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 5 package xorm 6 7 import ( 8 "errors" 9 "regexp" 10 11 "github.com/insionng/yougam/libraries/go-xorm/core" 12 ) 13 14 type oci8Driver struct { 15 } 16 17 //dataSourceName=user/password@ipv4:port/dbname 18 //dataSourceName=user/password@[ipv6]:port/dbname 19 func (p *oci8Driver) Parse(driverName, dataSourceName string) (*core.Uri, error) { 20 db := &core.Uri{DbType: core.ORACLE} 21 dsnPattern := regexp.MustCompile( 22 `^(?P<user>.*)\/(?P<password>.*)@` + // user:password@ 23 `(?P<net>.*)` + // ip:port 24 `\/(?P<dbname>.*)`) // dbname 25 matches := dsnPattern.FindStringSubmatch(dataSourceName) 26 names := dsnPattern.SubexpNames() 27 for i, match := range matches { 28 switch names[i] { 29 case "dbname": 30 db.DbName = match 31 } 32 } 33 if db.DbName == "" { 34 return nil, errors.New("dbname is empty") 35 } 36 return db, nil 37 }