go-report-builder
Why
In the e-commerce business, you always have need to print labels, invoices and build reports online.
We've built this tool at Adika to get rid of the cumbersome process of creating such reports and moving them
to the server side.
How
Download using go get
or via the releases page:
$> go get -u github.com/AdikaStyle/go-report-builder
- Build your template in pure HTML, for example:
- Use go's templating language to template the data of your report.
- Mark your printable area with the id tag
<div id="printable">...</div>
- Set the page size on the body tag
- Start go-report-builder with a reference to the folder containing your templates:
$> go-report-builder <TEMPLATES PATH>
- Use the API to export your rendered html report to HTML, PDF and PNG.
Example of html report:
<!DOCTYPE html>
<html>
<head>
<style>
body {
width: 150mm;
height: 100mm;
}
</style>
</head>
<body>
<div id="printable">
Hello {{ .Values.name }}
</div>
</body>
</html>
Example
Check the examples folder.
Api Reference
List Reports
Will return a list of all loaded reports:
Url: GET /reports/list
Example Response:
{
"list": [
"report1",
"withdata/report2",
"withdata/report3"
]
}
Render Report
Will render a report (as HTML) using the provided data.
Url: GET /reports/render/${reportId}?d=${base64Data}
Response: the rendered HTML report.
Preview (and debug) Report
Will open a web page that allows you to debug and test your reports.
Url: GET /reports/preview/${reportId}?d=${base64Data}
Response: the rendered HTML preview tool.
Export HTML/PDF/PNG
Will create a base64 encoded string containing your rendered report:
Urls:
POST /reports/export/html/${reportId}
POST /reports/export/pdf/${reportId}
POST /reports/export/png/${reportId}
Body: json body that represents the data input for that report.
Response: json response with the base64 encoded content:
{
"reportId": "myReport",
"type": "png",
"data": "[BASE64 CONTENT]"
}