From ee30606ddd96a479be00646011470daf6704f1bc Mon Sep 17 00:00:00 2001 From: wangsiyuan <2392948297@qq.com> Date: Mon, 5 Jun 2023 17:20:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=9E=E6=8E=A5=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化连接方式 --- modules/ImportDataBase.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/ImportDataBase.go b/modules/ImportDataBase.go index 792c6e9..536a95f 100644 --- a/modules/ImportDataBase.go +++ b/modules/ImportDataBase.go @@ -6,9 +6,9 @@ import ( "github.com/go-sql-driver/mysql" ) -func ImportDatabaseToString() { +func ImportDatabaseToString(dsn string) { mysql.RegisterLocalFile("C:/Users/wangh/Desktop/code/checkIP/db/GeoLite2-City-Blocks-IPv4-string.csv") - db, err := sql.Open("mysql", "root:990821@tcp(192.168.2.20:3306)/checkip") + db, err := sql.Open("mysql", dsn) if err != nil { fmt.Println("数据库连接错误:", err) return @@ -66,9 +66,9 @@ CREATE TABLE geolite2_city_ipv4_string ( fmt.Println("表geolite2_city_ipv4_string数据加载完成") } -func ImportDatabaseToHex() { +func ImportDatabaseToHex(dsn string) { mysql.RegisterLocalFile("C:/Users/wangh/Desktop/code/checkIP/db/GeoLite2-City-Blocks-IPv4-hex.csv") - db, err := sql.Open("mysql", "root:990821@tcp(192.168.2.20:3306)/checkip") + db, err := sql.Open("mysql", dsn) if err != nil { fmt.Println("数据库连接错误:", err) return @@ -126,9 +126,9 @@ CREATE TABLE geolite2_city_ipv4_hex ( fmt.Println("表geolite2_city_ipv4_hex数据加载完成") } -func ImportLocation_zhCN() { +func ImportLocation_zhCN(dsn string) { mysql.RegisterLocalFile("C:/Users/wangh/Desktop/code/checkIP/db/GeoLite2-City-Locations-zh-CN.csv") - db, err := sql.Open("mysql", "root:990821@tcp(192.168.2.20:3306)/checkip") + db, err := sql.Open("mysql", dsn) if err != nil { fmt.Println("数据库连接错误:", err) return @@ -188,9 +188,9 @@ set country_iso_code = nullif(@country_iso_code, ''), fmt.Println("表geolite2_city_locations_zh_cn数据加载完成") } -func ImportLocation_en() { +func ImportLocation_en(dsn string) { mysql.RegisterLocalFile("C:/Users/wangh/Desktop/code/checkIP/db/GeoLite2-City-Locations-en.csv") - db, err := sql.Open("mysql", "root:990821@tcp(192.168.2.20:3306)/checkip") + db, err := sql.Open("mysql", dsn) if err != nil { fmt.Println("数据库连接错误:", err) return