Skip to content

sklinkert/ghost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unofficial Go Client for Ghost Blogs

Not affiliated in any way with Ghost.org.

Ghost Client (ContentAPI + AdminAPI)

Supported features

Generic

  • Upload images

Posts

  • Add post
  • Get posts
  • Update post
  • Delete post

Pages

  • Add page
  • Get pages
  • Update page
  • Delete page

Tags

  • Add tag
  • Get tags
  • Update tag
  • Delete tag

Members

  • Add member
  • Get members
  • Update member

Images

  • Add image
package main

import (
	"fmt"
	"github.com/sklinkert/ghost"
)

func main() {
	contentAPIToken := "837484..."
	adminAPIToken := "90968696..."
	ghostAPI := ghost.New("https://example.com", contentAPIToken, adminAPIToken)

	posts, err := ghostAPI.GetPosts()
	if err != nil {
		fmt.Printf("cannot get posts from ghost api: %v\n", err)
		return
	}

	for _, post := range posts.Posts {
		fmt.Println(post.Title)

		// Update existing post
		post.Title = "new title"
		if err := ghostAPI.AdminUpdatePost(post); err != nil {
			fmt.Printf("update failed: %v\n", err)
			break
		}
	}
	
	// Upload new image
	imageURL, err := ghostAPI.AdminUploadImage("./myimage.jpg")
	if err != nil {
		fmt.Printf("Image upload failed: %v\n", err)
	}
	fmt.Println(imageURL)
}

Releases

No releases published

Packages

No packages published

Languages