Go SDK
Use LifeAstroAPI from Go 1.22 or later in an HTTP server, CLI or background worker. The SDK provides typed request parameters and returns the response body for your own JSON decoding or report rendering. View the source and runnable examples on GitHub.
Install and make your first call
Run the install command in your Go module. If you are starting in an empty directory, run
go mod init example.com/astro-demo first.
go get github.com/ayanshulife/[email protected]Create an API key and set it as LIFEASTRO_API_KEY in your server
or terminal environment. Save this example as main.go and run go run ..
package main
import (
"context"
"fmt"
"log"
"github.com/ayanshulife/lifeastroapi-go"
)
func main() {
client, err := lifeastroapi.NewClient(lifeastroapi.Options{})
if err != nil {
log.Fatal(err)
}
res, err := client.Panchang.Tithi(context.Background(), lifeastroapi.PanchangTithiParams{
Date: "2026-04-19", TZ: "Asia/Kolkata",
Lat: 28.61, Lon: 77.21, Lang: lifeastroapi.Gujarati,
})
if err != nil {
log.Fatal(err)
}
fmt.Println(string(res.Body))
}Reuse the client across requests and pass your request's context.Context from a web server.
Use res.Decode(&target) to decode the JSON into your own Go struct. The client also exposes response
headers and returns a typed *lifeastroapi.APIError for API errors.
Render branded HTML and PDFs
Fetch a report once, then pass its response body to the matching template. The pdf package
supports all 12 report variants, including Kundli Lite, Detailed and Brihad, and daily, weekly
and monthly Horoscope. It renders in the language returned by the API. Rendering an existing
response uses no further API credits.
package main
import (
"context"
"log"
"os"
"github.com/ayanshulife/lifeastroapi-go"
"github.com/ayanshulife/lifeastroapi-go/pdf"
)
func main() {
if err := renderKundli(context.Background()); err != nil {
log.Fatal(err)
}
}
func renderKundli(ctx context.Context) error {
client, err := lifeastroapi.NewClient(lifeastroapi.Options{})
if err != nil {
return err
}
report, err := client.Reports.KundliLite(ctx, lifeastroapi.ReportsKundliLiteParams{
Name: "Demo", Date: "1990-01-15", Time: "10:30",
Place: "Mumbai", TZ: "Asia/Kolkata", Lat: 19.076, Lon: 72.8777,
Lang: lifeastroapi.Hindi,
})
if err != nil {
return err
}
branding := pdf.Branding{CompanyName: "Your Company", PrimaryColor: "#45206b"}
html, err := pdf.RenderHTML(pdf.KundliLite, report.Body, branding)
if err != nil {
return err
}
if err := os.WriteFile("kundli.html", []byte(html), 0600); err != nil {
return err
}
data, err := pdf.RenderPDF(ctx, pdf.ChromeEngine{}, pdf.KundliLite, report.Body, pdf.Options{
Branding: branding,
})
if err != nil {
return err
}
return os.WriteFile("kundli.pdf", data, 0600)
}- HTML renders in Go with embedded templates and needs no browser.
- Local PDF requires Chrome or Chromium. Set
ChromeEngine.ExecutablePathif needed. Use a data URL inBranding.LogoURLto embed a logo without a network request. - Remote PDF uses
pdf.GotenbergEngine{BaseURL: "http://gotenberg:3000"}in place ofpdf.ChromeEngine{}. Install fonts for your report languages wherever Chromium runs. - Brihad Kundli includes a table of contents with page numbers and nested PDF bookmarks.