1package main 2 3import ( 4 "fmt" 5 6 _ "github.com/go-sql-driver/mysql" 7 "github.com/jinzhu/gorm" 8) 9 10func main() { 11 _, err := sqlConnect() 12 if err != nil { 13 panic(err.Error()) 14 } else { 15 fmt.Println("DB接続成功") 16 } 17} 18 19// SQLConnect DB接続 20func sqlConnect() (database *gorm.DB, err error) { 21 DBMS := "mysql" 22 USER := "go_example" 23 PASS := "12345!" 24 PROTOCOL := "tcp(localh