Coder Social home page Coder Social logo

carboneio / carbone-sdk-go Goto Github PK

View Code? Open in Web Editor NEW
8.0 7.0 2.0 105 KB

Golang SDK to generate documents (PDF DOCX ODT XLSX ODS XML ...) with the Carbone Cloud API

Home Page: https://carbone.io

License: Apache License 2.0

Go 96.47% JavaScript 2.89% HTML 0.64%
golang report-generator document-conversion pdf-generation multilingual libreoffice template-engine docx go pdf

carbone-sdk-go's Introduction

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!

carbone-sdk-go's People

Contributors

steevepay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

qibinlin radoen

carbone-sdk-go's Issues

Add function to edit the default API URL

TODO:

  • add SetAPIUrl and GetAPIUrl
  • add documentation

Alternative solution: the apiURL can be edited after initialisation, such as:

csdk, err := carbone.NewCarboneSDK("secret-token")

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

csdk.apiURL = 'https://new-url'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.