As you may know, this blog is currently a go project I created a few months ago: https://github.com/compscidr/goblog
I previously had a hosted blog in wordpress which I developed custom templates and plugins for over a few years. More recently I've been writing on medium (https://medium.com/@compscidr), however, I decided to revive my hosted blog with the latest project. I also want to pull together all of my posts from recent years. The first step was importing the old wordpress posts.
I had the posts backed up in a mysql dump, and still have access to the `wp-uploads` folder. The first thing I did was spin up docker containers with a `mysql-server` and `php-my-admin`. Here is the `docker-compose.yml` file I used:
```
version: "3.0"
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
ports:
- "3306:3306"
expose:
- "3306"
networks:
- backend
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8080:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
UPLOAD_LIMIT: 3000000000
networks:
- backend
networks:
backend:
```
Note that the upload limit size is set high because the mysql dump was larger than the 2MB default limit. I was brought up the containers with: `docker-compose up`. Once this was up, I went to the `phpmyadmin` page at `http://localhost:8080` and login:
<center>  </center>
then after logging in, I go to `import`:
<center>  </center>
After the import succeeds, I could then browse through the posts in the table:
<center>  </center>
I used the view of the structure to define a go struct that can represent a row in the database for a post.
```
type Post struct {
ID int `json:"ID"`
Author int `json:"post_author"`
Date time.Time `json:"post_date"`
DateGmt time.Time `json:"post_date_gmt"`
Content string `json:"post_content"`
Title string `json:"post_title"`
Category int `json:"post_category"`
Excerpt string `json:"post_excerpt"`
Status string `json:"post_status"`
CommentStatus string `json:"comment_status"`
PingStatus string `json:"ping_status"`
PostPassword string `json:"post_password"`
Slug string `json:"post_name"`
ToPing string `json:"to_ping"`
Pinged string `json:"pinged"`
Modified time.Time `json:"post_modified"`
ModifiedGMT time.Time `json:"post_modified_gmt"`
ContentFiltered string `json:"post_content_filtered"`
Parent int `json:"post_parent"`
GUID string `json:"guid"`
MenuOrder int `json:"menu_order"`
Type string `json:"post_type"`
MimeType string `json:"post_mime_type"`
CommentCount int `json:"comment_count"`
}
```
I could then issue an SQL query and scan the results into the struct:
```
results, err := db.Query("select * from jason_posts where post_status = 'publish' and post_type = 'post' order by post_date DESC")
if err != nil {
panic(err.Error()) // proper error handling instead of panic in your app
}
for results.Next() {
var post Post
err = results.Scan(&post.ID, &post.Author, &post.Date, &post.DateGmt, &post.Content, &post.Title,
&post.Category, &post.Excerpt, &post.Status, &post.CommentStatus, &post.PingStatus, &post.PostPassword,
&post.Slug, &post.ToPing, &post.Pinged, &post.Modified, &post.ModifiedGMT, &post.ContentFiltered,
&post.Parent, &post.GUID, &post.MenuOrder, &post.Type, &post.MimeType, &post.CommentCount)
if err != nil {
panic(err.Error()) // proper error handling instead of panic in your app
}
```
From here, I did additional parsing and did a similar set of queries to determine the tags associated with the posts. I then used the Gorm post type in my existing goblog code to save the posts in the database compatible with my live blog.