install mysql to connect to external db, scaffold needed code
This commit is contained in:
parent
45358bca52
commit
f4e7e3446c
5
go.mod
5
go.mod
@ -1,3 +1,8 @@
|
|||||||
module federated.computer/wp-sync-slowtwitch
|
module federated.computer/wp-sync-slowtwitch
|
||||||
|
|
||||||
go 1.22.2
|
go 1.22.2
|
||||||
|
|
||||||
|
require (
|
||||||
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
|
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
||||||
|
)
|
||||||
|
4
go.sum
Normal file
4
go.sum
Normal file
@ -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=
|
22
main.go
22
main.go
@ -1,5 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
)
|
||||||
|
|
||||||
const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/"
|
const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/"
|
||||||
const wordpressKey = "admin"
|
const wordpressKey = "admin"
|
||||||
const wordpressSecret = "S34E keY1 A1uX 6ncs Rx4T f21W"
|
const wordpressSecret = "S34E keY1 A1uX 6ncs Rx4T f21W"
|
||||||
@ -11,3 +17,19 @@ func main() {
|
|||||||
// TODO Use cached data to correctly build post form submissions
|
// 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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user