Pogodoc Quickstart
Generate documents in seconds using Pogodoc with Go.
Prerequisites
Before getting started with Pogodoc, make sure you have:
- Go (version 1.18 or higher)
- A Pogodoc account - Sign up here if you don't have one
- A Pogodoc API token - Generate one from your API tokens page
1. Installing the package
Before using the Pogodoc SDK, you can install the required package:
- Go
go get github.com/Pogodoc/pogodoc-go
2. Create a client
Before creating a pogodoc client you need to generate POGODOC API token.
import (
"os"
"github.com/Pogodoc/pogodoc-go"
)
client, err := PogodocClientInit()
if err != nil {
log.Fatal("Error initializing PogodocClient")
}
⚠️ Don't forget to set your
POGODOC_API_TOKEN
in your.env
file.
3. Generate a document
ctx := context.Background()
var sampleData map[string]interface{}
jsonData := `{
"name": "John Doe"
}`
err := json.Unmarshal([]byte(jsonData), &sampleData)
if err != nil {
log.Fatal("Error unmarshaling data")
}
documentProps := GenerateDocumentProps{
InitializeRenderJobRequest: InitializeRenderJobRequest{
Template: String("<h1>Hello <%= name %></h1>"),
Type: InitializeRenderJobRequestType("ejs"),
Target: InitializeRenderJobRequestTarget("pdf"),
Data: sampleData,
},
}
doc, err := client.GenerateDocument(documentProps, ctx)
if err != nil {
log.Fatal("Error generating document")
}
fmt.Println(doc.Output.Data.Url)