-
-
Save redhajuanda/a802ed3b59d15da39609ce4e3c6ef999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"flag" | |
"fmt" | |
"log" | |
"os" | |
"github.com/redhajuanda/goseeder/seeds" | |
_ "github.com/go-sql-driver/mysql" | |
"github.com/joho/godotenv" | |
) | |
func main() { | |
godotenv.Load() | |
handleArgs() | |
} | |
func handleArgs() { | |
flag.Parse() | |
args := flag.Args() | |
if len(args) >= 1 { | |
switch args[0] { | |
case "seed": | |
connString := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local&multiStatements=true", os.Getenv("DB_USERNAME"), os.Getenv("DB_PASSWORD"), os.Getenv("DB_HOST"), os.Getenv("DB_PORT"), os.Getenv("DB_NAME")) | |
// connect DB | |
db, err := sql.Open("mysql", connString) | |
if err != nil { | |
log.Fatalf("Error opening DB: %v", err) | |
} | |
seeds.Execute(db, args[1:]...) | |
os.Exit(0) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment