get slowtwitch categories
This commit is contained in:
parent
f4e7e3446c
commit
00ba765dc8
28
main.go
28
main.go
@ -1,35 +1,33 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"federated.computer/wp-sync-slowtwitch/services/slowtwitch"
|
||||||
"fmt"
|
"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"
|
||||||
|
|
||||||
|
const slowtwitchAdminUser = "admin"
|
||||||
|
const slowtwitchAdminPass = "yxnh93Ybbz2Nm8#mp28zCVv"
|
||||||
|
const slowtwitchDbUrl = "slowtwitch.northend.network"
|
||||||
|
const slowtwitchDbPort = "3306"
|
||||||
|
const slowtwitchDbName = "slowtwitch"
|
||||||
|
|
||||||
var appCache AppCache
|
var appCache AppCache
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// TODO Create Category with or without parent + add to cache
|
|
||||||
// TODO Use cached data to correctly build post form submissions
|
// TODO Use cached data to correctly build post form submissions
|
||||||
|
slowtwitchDB, err := slowtwitch.Connect(slowtwitchAdminUser, slowtwitchAdminPass, slowtwitchDbUrl, slowtwitchDbPort, slowtwitchDbName)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func connectToMariaDB() (*sql.DB, error) {
|
|
||||||
db, err := sql.Open("mysql", "username:password@tcp(localhost:3306)/mydb")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ping the MariaDB server to ensure connectivity
|
categories := slowtwitch.GetCategories(slowtwitchDB)
|
||||||
err = db.Ping()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Connected to MariaDB!")
|
for _, category := range categories {
|
||||||
return db, nil
|
fmt.Println(category.FullName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
40
services/slowtwitch/get-category.go
Normal file
40
services/slowtwitch/get-category.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package slowtwitch
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SlowtwitchCategory struct {
|
||||||
|
Id int
|
||||||
|
Name string
|
||||||
|
FullName string
|
||||||
|
FatherId int
|
||||||
|
CatDepth int
|
||||||
|
NumberOfLinks int
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCategories(db *sql.DB) []SlowtwitchCategory {
|
||||||
|
rows, err := db.Query("select ID, Name, Full_Name, FatherID, CatDepth, Number_of_Links from glinks_Category;")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
var categories []SlowtwitchCategory
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
category := SlowtwitchCategory{}
|
||||||
|
err := rows.Scan(&category.Id, &category.Name, &category.FullName, &category.FatherId, &category.CatDepth, &category.NumberOfLinks)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
categories = append(categories, category)
|
||||||
|
}
|
||||||
|
|
||||||
|
return categories
|
||||||
|
}
|
26
services/slowtwitch/slowtwitch-db.go
Normal file
26
services/slowtwitch/slowtwitch-db.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package slowtwitch
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Connect(user, pass, url, port, dbName string) (*sql.DB, error) {
|
||||||
|
connectionString := user + ":" + pass + "@tcp(" + url + ":" + port + ")/" + dbName
|
||||||
|
|
||||||
|
db, err := sql.Open("mysql", connectionString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.Ping()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Successfully connected!")
|
||||||
|
|
||||||
|
return db, nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user