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