Skip to content

AdikaStyle/go-report-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-report-builder Go Report Card

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

  1. Build your template in pure HTML, for example:
  2. Use go's templating language to template the data of your report.
  3. Mark your printable area with the id tag <div id="printable">...</div>
  4. Set the page size on the body tag
  5. Start go-report-builder with a reference to the folder containing your templates:
    $> go-report-builder <TEMPLATES PATH>
  6. 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]"
}