carbone-sdk-go

command module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README

Carbone Cloud API Go SDK

GitHub release (latest by date) Documentation

The golang SDK to request the Carbone Cloud API easily.

Carbone is a document generator (PDF, DOCX, XLSX, ODT, PPTX, ODS, XML, CSV...) using templates and JSON data. Learn more about the Carbone ecosystem.

🔖 API REFERENCE

Install

go install github.com/carboneio/carbone-sdk-go@latest

Usage

You can copy and run the code bellow to try.

package main

import (
	"io/ioutil"
	"log"

	"github.com/carboneio/carbone-sdk-go/carbone"
)

func main() {
	// SDK constructor
	// The access token can be passed as an argument to NewCarboneSDK
	// Or by the environment variable "CARBONE_TOKEN", use the command "export CARBONE_TOKEN=secret-token"
	csdk, err := carbone.NewCarboneSDK("secret-token")
	if err != nil {
		log.Fatal(err)
	}

	// The template ID
	templateID := "template"
	// Data injected into the template to generate the report with Carbone
	jsonData := `{"data":{"id":42,"date":1492012745,"company":{"name":"myCompany","address":"here","city":"Notfar","postalCode":123456},"customer":{"name":"myCustomer","address":"there","city":"Faraway","postalCode":654321},"products":[{"name":"product 1","priceUnit":0.1,"quantity":10,"priceTotal":1}],"total":140},"convertTo":"pdf"}`

	// Render and return the report as []byte
	reportBuffer, err := csdk.Render(templateID, jsonData)
	if err != nil {
		log.Fatal(err)
	}
	// Create the file
	err = ioutil.WriteFile("Invoice.pdf", reportBuffer, 0644)
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Run tests

First, Go to the carbone package directory.

$ cd carbone

To run all the tests (-v for verbose output):

$ go test -v

To run only one test:

$ go test -v -run NameOfTheTest

If you need to test the generation of templateId, you can use the nodejs main.js to test the sha256 generation.

$ node ./tests/main.js

👤 Author

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package carbone provide an SDK to communicate with Carbone Render Carbone is the most efficient report generator It render from a JSON and template into PDF, DOCX, XLSX, PPTX, ODS and many more reports
Package carbone provide an SDK to communicate with Carbone Render Carbone is the most efficient report generator It render from a JSON and template into PDF, DOCX, XLSX, PPTX, ODS and many more reports

Jump to

Keyboard shortcuts

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