71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"federated.computer/wp-sync-slowtwitch/services/wordpress"
|
|
"fmt"
|
|
)
|
|
|
|
const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/"
|
|
const user = "admin"
|
|
const password = "S34E keY1 A1uX 6ncs Rx4T f21W"
|
|
|
|
var appCache AppCache
|
|
|
|
func main() {
|
|
//Get user and cache
|
|
//Get category and cache
|
|
//Get single category from cache by name
|
|
//Get tag and cache
|
|
//Get single tag from cache by name
|
|
//Get photo and cache with URL
|
|
//Create Category (with parent) + add to cache
|
|
//Create Tag + add to cache
|
|
//Upload Photo + add to cache
|
|
//Use cached data to correctly build post form submissions
|
|
|
|
createPost := wordpress.CreatePost{
|
|
Title: "Test 634534",
|
|
Content: "<h1>HELLO WORLD</h1>",
|
|
Excerpt: "This article will blow your mind.",
|
|
FeaturedMedia: 18,
|
|
Author: 1,
|
|
Tags: []int{6, 3},
|
|
Status: "publish",
|
|
Categories: []int{7},
|
|
Slug: "/scoop-it-up",
|
|
}
|
|
|
|
post := createPost.Execute(baseUrl, user, password)
|
|
fmt.Println(post.Title.Rendered)
|
|
|
|
createUser := wordpress.CreateUser{
|
|
Username: "Crkaaadfdfdfain",
|
|
Password: "raadfadomPass",
|
|
Name: "Chekadadsing Msocadsfker",
|
|
FirstName: "Cafhefarking",
|
|
LastName: "McCloaaddfcker",
|
|
Email: "chedfsddfsdfgs@gmail.com",
|
|
Roles: "author",
|
|
}
|
|
|
|
user := createUser.Execute(baseUrl, user, password)
|
|
appCache.SetUser(user)
|
|
fmt.Println("Created:", user.Username)
|
|
}
|
|
|
|
type AppCache struct {
|
|
UsersCache map[string]wordpress.UserData
|
|
}
|
|
|
|
func (appCache *AppCache) GetUser(username string) (wordpress.UserData, bool) {
|
|
user, ok := appCache.UsersCache[username]
|
|
return user, ok
|
|
}
|
|
|
|
func (appCache *AppCache) SetUser(user wordpress.UserData) {
|
|
if appCache.UsersCache == nil {
|
|
appCache.UsersCache = make(map[string]wordpress.UserData)
|
|
}
|
|
appCache.UsersCache[user.Username] = user
|
|
}
|