From f4e7e3446ca89ce8909ebfce1332afee3a8781ec Mon Sep 17 00:00:00 2001 From: Ross Trottier Date: Fri, 10 May 2024 14:01:05 -0600 Subject: [PATCH] install mysql to connect to external db, scaffold needed code --- go.mod | 5 +++++ go.sum | 4 ++++ main.go | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 go.sum diff --git a/go.mod b/go.mod index 584a23a..5cdcd5f 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,8 @@ module federated.computer/wp-sync-slowtwitch go 1.22.2 + +require ( + filippo.io/edwards25519 v1.1.0 // indirect + github.com/go-sql-driver/mysql v1.8.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..19dbcec --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= +github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= diff --git a/main.go b/main.go index 49168ed..82d4c13 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,11 @@ package main +import ( + "database/sql" + "fmt" + _ "github.com/go-sql-driver/mysql" +) + const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/" const wordpressKey = "admin" const wordpressSecret = "S34E keY1 A1uX 6ncs Rx4T f21W" @@ -11,3 +17,19 @@ func main() { // TODO Use cached data to correctly build post form submissions } + +func connectToMariaDB() (*sql.DB, error) { + db, err := sql.Open("mysql", "username:password@tcp(localhost:3306)/mydb") + if err != nil { + return nil, err + } + + // Ping the MariaDB server to ensure connectivity + err = db.Ping() + if err != nil { + return nil, err + } + + fmt.Println("Connected to MariaDB!") + return db, nil +}