peasydocument

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 9 Imported by: 0

README

peasy-document-go

Go Reference Go Report Card GitHub stars

Go client for the PeasyFormats API -- convert between Markdown, JSON, YAML, CSV, and other document formats with tools for format identification, MIME type lookup, and structured data transformation. Zero dependencies beyond the Go standard library.

Built from PeasyFormats, a comprehensive document conversion toolkit offering free online tools for transforming between structured data formats. The glossary covers document formats from lightweight Markdown to structured JSON and YAML, while guides explain format conversion strategies and encoding best practices.

Try the interactive tools at peasyformats.com -- Markdown to HTML, YAML/JSON Converter, Format Identifier, and more.

peasy-document-go demo -- Markdown, JSON, YAML, and CSV conversion tools in Go terminal

Table of Contents

Install

go get github.com/peasytools/peasy-document-go

Requires Go 1.21+.

Quick Start

package main

import (
	"context"
	"fmt"
	"log"

	peasy "github.com/peasytools/peasy-document-go"
)

func main() {
	client := peasy.New()
	ctx := context.Background()

	// List available document tools
	tools, err := client.ListTools(ctx, nil)
	if err != nil {
		log.Fatal(err)
	}
	for _, t := range tools.Results {
		fmt.Printf("%s: %s\n", t.Name, t.Description)
	}
}

What You Can Do

Document Conversion Tools

Document format conversion is a core workflow for developers, data engineers, and content authors. Converting Markdown to HTML powers static site generators and documentation systems. Transforming JSON to YAML (and vice versa) is essential for configuration management across Kubernetes, Docker Compose, and CI/CD pipelines. CSV-to-JSON conversion bridges the gap between spreadsheet data and web APIs.

Tool Description Use Case
Markdown to HTML Convert Markdown syntax to semantic HTML Static sites, documentation pipelines
YAML/JSON Converter Bidirectional YAML and JSON transformation Kubernetes configs, API payloads
Format Identifier Detect file format from content or extension File upload validation, data pipelines
package main

import (
	"context"
	"fmt"
	"log"

	peasy "github.com/peasytools/peasy-document-go"
)

func main() {
	client := peasy.New()
	ctx := context.Background()

	// Fetch the Markdown to HTML conversion tool
	tool, err := client.GetTool(ctx, "markdown-to-html")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Tool: %s\n", tool.Name)           // Markdown to HTML converter
	fmt.Printf("Category: %s\n", tool.Category)   // Document conversion category

	// List supported document formats and their MIME types
	formats, err := client.ListFormats(ctx)
	if err != nil {
		log.Fatal(err)
	}
	for _, f := range formats.Results {
		fmt.Printf("%s (%s): %s\n", f.Name, f.Extension, f.MimeType)
	}

	// List available format conversions from Markdown
	conversions, err := client.ListConversions(ctx, &peasy.ListConversionsOptions{Source: str("markdown")})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Found %d conversion paths from Markdown\n", len(conversions.Results))
}

func str(s string) *string { return &s }

Learn more: Markdown to HTML Tool · YAML/JSON Converter · File Format Conversion Guide

Browse Document Format Reference

The document format glossary provides clear definitions for structured data formats, markup languages, and serialization standards. Understanding the differences between JSON and YAML syntax, when CSV is preferable to JSON for tabular data, and how Markdown flavors (CommonMark, GFM) differ helps developers choose the right format for each use case.

Glossary Term Description
Markdown Lightweight markup language for creating formatted text with plain-text syntax
CSV Comma-separated values format for tabular data interchange
JSON JavaScript Object Notation for structured data serialization
YAML Human-readable data serialization format used in configuration files
// Browse document format glossary terms
glossary, err := client.ListGlossary(ctx, &peasy.ListOptions{Search: str("encoding")})
if err != nil {
	log.Fatal(err)
}
for _, term := range glossary.Results {
	fmt.Printf("%s: %s\n", term.Term, term.Definition) // Document format definition
}

// Read in-depth guides on format conversion strategies
guides, err := client.ListGuides(ctx, &peasy.ListGuidesOptions{Category: str("conversion")})
if err != nil {
	log.Fatal(err)
}
for _, g := range guides.Results {
	fmt.Printf("%s (%s)\n", g.Title, g.AudienceLevel) // Guide title and difficulty level
}

Learn more: Markdown Glossary · JSON Glossary · How to Convert Markdown to Other Formats

Search and Discovery

The unified search endpoint queries across all document tools, glossary terms, guides, and supported file formats simultaneously. This is useful for building editor plugins, documentation search, or data pipeline tools that need to discover conversion capabilities.

// Search across all document tools, glossary, and guides
results, err := client.Search(ctx, "csv to json", nil)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Found %d tools, %d glossary terms\n",
	len(results.Results.Tools),
	len(results.Results.Glossary)) // Cross-content document format search results

Learn more: CSV Glossary · YAML Glossary · All Document Guides

API Client

The client wraps the PeasyFormats REST API with typed Go structs and zero external dependencies.

client := peasy.New()
// Or with a custom base URL:
// client := peasy.New(peasy.WithBaseURL("https://custom.example.com"))
ctx := context.Background()

// List tools with pagination
tools, _ := client.ListTools(ctx, &peasy.ListOptions{Page: 1, Limit: 10})

// Get a specific tool by slug
tool, _ := client.GetTool(ctx, "markdown-to-html")
fmt.Println(tool.Name, tool.Description)

// Search across all content
results, _ := client.Search(ctx, "csv to json", nil)
fmt.Printf("Found %d tools\n", len(results.Results.Tools))

// Browse the glossary
glossary, _ := client.ListGlossary(ctx, &peasy.ListOptions{Search: str("encoding")})
for _, term := range glossary.Results {
	fmt.Printf("%s: %s\n", term.Term, term.Definition)
}

// Discover guides
guides, _ := client.ListGuides(ctx, &peasy.ListGuidesOptions{Category: str("conversion")})
for _, g := range guides.Results {
	fmt.Printf("%s (%s)\n", g.Title, g.AudienceLevel)
}

// List file format conversions
conversions, _ := client.ListConversions(ctx, &peasy.ListConversionsOptions{Source: str("markdown")})

// Get format details
format, _ := client.GetFormat(ctx, "csv")
fmt.Printf("%s (%s): %s\n", format.Name, format.Extension, format.MimeType)

Helper for optional string parameters:

func str(s string) *string { return &s }
Available Methods
Method Description
ListTools(ctx, opts) List tools (paginated, filterable)
GetTool(ctx, slug) Get tool by slug
ListCategories(ctx, opts) List tool categories
ListFormats(ctx, opts) List file formats
GetFormat(ctx, slug) Get format by slug
ListConversions(ctx, opts) List format conversions
ListGlossary(ctx, opts) List glossary terms
GetGlossaryTerm(ctx, slug) Get glossary term
ListGuides(ctx, opts) List guides
GetGuide(ctx, slug) Get guide by slug
ListUseCases(ctx, opts) List use cases
Search(ctx, query, limit) Search across all content
ListSites(ctx) List Peasy sites
OpenAPISpec(ctx) Get OpenAPI specification

Full API documentation at peasyformats.com/developers/. OpenAPI 3.1.0 spec: peasyformats.com/api/openapi.json.

Learn More About Document Formats

Also Available

Language Package Install
Python peasy-document pip install "peasy-document[all]"
TypeScript peasy-document npm install peasy-document
Rust peasy-document cargo add peasy-document
Ruby peasy-document gem install peasy-document

Peasy Developer Tools

Part of the Peasy Tools open-source developer ecosystem.

Package PyPI npm Go Description
peasy-pdf PyPI npm Go PDF merge, split, rotate, compress -- peasypdf.com
peasy-image PyPI npm Go Image resize, crop, convert, compress -- peasyimage.com
peasy-audio PyPI npm Go Audio trim, merge, convert, normalize -- peasyaudio.com
peasy-video PyPI npm Go Video trim, resize, thumbnails, GIF -- peasyvideo.com
peasy-css PyPI npm Go CSS minify, format, analyze -- peasycss.com
peasy-compress PyPI npm Go ZIP, TAR, gzip compression -- peasytools.com
peasy-document PyPI npm Go Markdown, HTML, CSV, JSON conversion -- peasyformats.com
peasytext PyPI npm Go Text case conversion, slugify, word count -- peasytext.com

License

MIT

Documentation

Overview

Package peasyimage provides a Go client for the PeasyDocument API.

PeasyDocument offers document tools for format conversion and processing. This client requires no authentication and has zero external dependencies.

Usage:

client := peasyimage.New()
tools, err := client.ListTools(ctx)
term, err := client.GetGlossaryTerm(ctx, "webp")

Index

Constants

View Source
const DefaultBaseURL = "https://peasyformats.com"

DefaultBaseURL is the default PeasyDocument API base URL.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default HTTP client timeout.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	Description string `json:"description"`
	ToolCount   int    `json:"tool_count"`
}

Category represents a tool category.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the PeasyDocument API client.

func New

func New(opts ...Option) *Client

New creates a new PeasyDocument API client.

func (*Client) GetFormat

func (c *Client) GetFormat(ctx context.Context, slug string) (*Format, error)

GetFormat returns a single format by slug.

func (*Client) GetGlossaryTerm

func (c *Client) GetGlossaryTerm(ctx context.Context, slug string) (*GlossaryTerm, error)

GetGlossaryTerm returns a single glossary term by slug.

func (*Client) GetGuide

func (c *Client) GetGuide(ctx context.Context, slug string) (*Guide, error)

GetGuide returns a single guide by slug.

func (*Client) GetTool

func (c *Client) GetTool(ctx context.Context, slug string) (*Tool, error)

GetTool returns a single tool by slug.

func (*Client) ListCategories

func (c *Client) ListCategories(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[Category], error)

ListCategories returns a paginated list of categories.

func (*Client) ListConversions

func (c *Client) ListConversions(ctx context.Context, opts ...ListConversionsOptions) (*PaginatedResponse[Conversion], error)

ListConversions returns a paginated list of conversions.

func (*Client) ListFormats

func (c *Client) ListFormats(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[Format], error)

ListFormats returns a paginated list of file formats.

func (*Client) ListGlossary

func (c *Client) ListGlossary(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[GlossaryTerm], error)

ListGlossary returns a paginated list of glossary terms.

func (*Client) ListGuides

func (c *Client) ListGuides(ctx context.Context, opts ...ListGuidesOptions) (*PaginatedResponse[Guide], error)

ListGuides returns a paginated list of guides.

func (*Client) ListSites

func (c *Client) ListSites(ctx context.Context) (*PaginatedResponse[Site], error)

ListSites returns all Peasy Tools sites.

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[Tool], error)

ListTools returns a paginated list of tools.

func (*Client) ListUseCases

func (c *Client) ListUseCases(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[UseCase], error)

ListUseCases returns a paginated list of use cases.

func (*Client) OpenAPISpec

func (c *Client) OpenAPISpec(ctx context.Context) (json.RawMessage, error)

OpenAPISpec returns the raw OpenAPI spec as JSON.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, opts ...SearchOptions) (*SearchResult, error)

Search performs a unified search across tools, formats, and glossary.

type Conversion

type Conversion struct {
	Source      string `json:"source"`
	Target      string `json:"target"`
	Description string `json:"description"`
	ToolSlug    string `json:"tool_slug"`
}

Conversion represents a format conversion.

type Format

type Format struct {
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	Extension   string `json:"extension"`
	MimeType    string `json:"mime_type"`
	Category    string `json:"category"`
	Description string `json:"description"`
}

Format represents a file format.

type GlossaryTerm

type GlossaryTerm struct {
	Slug       string `json:"slug"`
	Term       string `json:"term"`
	Definition string `json:"definition"`
	Category   string `json:"category"`
}

GlossaryTerm represents a glossary entry.

type Guide

type Guide struct {
	Slug          string `json:"slug"`
	Title         string `json:"title"`
	Description   string `json:"description"`
	Category      string `json:"category"`
	AudienceLevel string `json:"audience_level"`
	WordCount     int    `json:"word_count"`
}

Guide represents a how-to guide.

type ListConversionsOptions

type ListConversionsOptions struct {
	Page   int
	Limit  int
	Source string
	Target string
}

ListConversionsOptions adds source/target filtering.

type ListGuidesOptions

type ListGuidesOptions struct {
	Page          int
	Limit         int
	Category      string
	AudienceLevel string
	Search        string
}

ListGuidesOptions adds audience level filtering.

type ListOptions

type ListOptions struct {
	Page     int
	Limit    int
	Category string
	Search   string
}

ListOptions are common parameters for paginated list endpoints.

type NotFoundError

type NotFoundError struct {
	Resource   string
	Identifier string
}

NotFoundError is returned when a resource is not found (404).

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Option

type Option func(*Client)

Option configures the Client.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the default base URL.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the HTTP client timeout.

type PaginatedResponse

type PaginatedResponse[T any] struct {
	Count    int     `json:"count"`
	Next     *string `json:"next"`
	Previous *string `json:"previous"`
	Results  []T     `json:"results"`
}

PaginatedResponse represents a paginated API response.

type PeasyError

type PeasyError struct {
	StatusCode int
	Message    string
}

PeasyError represents an API error response.

func (*PeasyError) Error

func (e *PeasyError) Error() string

type SearchCategories

type SearchCategories struct {
	Tools    []Tool         `json:"tools"`
	Formats  []Format       `json:"formats"`
	Glossary []GlossaryTerm `json:"glossary"`
}

SearchCategories groups search results by type.

type SearchOptions

type SearchOptions struct {
	Limit int
}

SearchOptions for the search endpoint.

type SearchResult

type SearchResult struct {
	Query   string           `json:"query"`
	Results SearchCategories `json:"results"`
}

SearchResult represents unified search results.

type Site

type Site struct {
	Name   string `json:"name"`
	Domain string `json:"domain"`
	URL    string `json:"url"`
}

Site represents a Peasy Tools site.

type Tool

type Tool struct {
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Category    string `json:"category"`
	URL         string `json:"url"`
}

Tool represents a PDF tool.

type UseCase

type UseCase struct {
	Slug     string `json:"slug"`
	Title    string `json:"title"`
	Industry string `json:"industry"`
}

UseCase represents an industry use case.

Directories

Path Synopsis
examples
demo command
Demo script for peasy-document-go — PeasyDocument API client.
Demo script for peasy-document-go — PeasyDocument API client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL