Pogodoc
Get Started

Golang

Get started with Pogodoc using Go - from installation to your first document render

Golang Quickstart

Welcome! This guide will help you get started with Pogodoc using Go. You'll learn how to install the SDK, authenticate, and generate your first document in minutes.

Prerequisites

Before you begin, make sure you have:

Quick Start Guide

Install the SDK

Install the Pogodoc SDK using Go modules:

go get github.com/Pogodoc/pogodoc-go

Initialize the Client

Create a Pogodoc client with your API token. You can get your token from the API tokens page.

package main

import (
    "context"
    "fmt"
    "log"
    "github.com/Pogodoc/pogodoc-go"
)

func main() {
    client, err := pogodoc.PogodocClientInitWithToken("<YOUR_API_TOKEN>")
    if err != nil {
        log.Fatal(err)
    }
}

Using Environment Variables

For better security, store your API token in an environment variable:

.env
POGODOC_API_TOKEN=your_token_here

Then initialize without a parameter:

client, err := pogodoc.PogodocClientInit()

Generate Your First Document

Now you're ready to generate a document! Here's a simple example using an EJS template:

package main

import (
    "context"
    "fmt"
    "log"
    "time"
    "github.com/Pogodoc/pogodoc-go"
)

func main() {
    client, err := pogodoc.PogodocClientInit()
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    template := `
    <!DOCTYPE html>
    <html>
      <head>
        <title>Invoice</title>
        <style>
          body { font-family: Arial, sans-serif; }
          h1 { color: #333; }
        </style>
      </head>
      <body>
        <h1>Invoice for <%= customerName %></h1>
        <p>Amount: $<%= amount %></p>
        <p>Date: <%= date %></p>
      </body>
    </html>
    `

    data := map[string]interface{}{
        "customerName": "John Doe",
        "amount":       1299.99,
        "date":         time.Now().Format("01/02/2006"),
    }

    result, err := client.GenerateDocument(pogodoc.GenerateDocumentProps{
        Template: &template,
        InitializeRenderJobRequest: pogodoc.InitializeRenderJobRequest{
            Data:   data,
            Type:   pogodoc.InitializeRenderJobRequestType("ejs"),
            Target: pogodoc.InitializeRenderJobRequestTarget("pdf"),
        },
    }, ctx)

    if err != nil {
        log.Fatal(err)
    }

    // Get the URL to your generated PDF
    fmt.Printf("Document URL: %s\n", result.Output.Data.Url)
}

Success!

Your document is now generated and available at the returned URL. The URL is publicly accessible and can be shared or downloaded.

Next Steps

Now that you've generated your first document, explore the detailed SDK documentation: