greypot

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

greypot

An experimental library for Report building and generations, based on go-report-builder.

Very much WIP.

What does it do?

Say you want to produce reports or other such type of documents in your applications. greypot allows you to design your reports with HTML as template files that use the standard Go html/template templating engine.

These HTML reports can then be generated as HTML, PNG or PDF via endpoints that greypot adds to your application.

Once you add the middleware to your application, it adds the following routes:

GET /reports/list

GET /reports/preview/:reportTemplateName

GET /reports/render/:reportTemplateName

POST /reports/export/html/:reportTemplateName

POST /reports/export/png/:reportTemplateName

POST /reports/export/pdf/:reportTemplateName

You can then call these from within your applications to generate/export the reports e.g. from a frontend UI.

Playwright Module

Currently, we are focusing on making the playwright based renderer work really good! The base project used Chrome Developer Protocol to connect with a Chromium instance. We are evaluating that decision here

In order to use the Playwright rendering functionality, you will need to have the playwright dependencies installed.

Read here for more info. But in short, you can use the following command to do so:

$ npx playwright install-deps chromium
Basic Fiber example
package main

import (
	"embed"
	"time"

	"github.com/gofiber/fiber/v2"
	"github.com/nndi-oss/greypot"
	greypotFiber "github.com/nndi-oss/greypot/http/fiber"
)

//go:embed "templates"
var templatesFS embed.FS

func main() {
	app := fiber.New()

	module := greypot.NewModule(
		greypot.WithRenderTimeout(10*time.Second),
		greypot.WithViewport(2048, 1920),
		greypot.WithDjangoTemplateEngine(),
		greypot.WithTemplatesFromFilesystem("./templates/"),
		greypot.WithPlaywrightRenderer(),
	)

	greypotFiber.Use(app, module)

	embedModule := greypot.NewModule(
		greypot.WithRenderTimeout(10*time.Second),
		greypot.WithViewport(2048, 1920),
		greypot.WithTemplatesFromFS(templatesFS),
		greypot.WithGolangTemplateEngine(),
		greypot.WithPlaywrightRenderer(),
	)

	greypotFiber.Use(app.Group("/embedded/"), embedModule)

	app.Listen(":3000")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDjangoTemplateEngine added in v0.0.3

func NewDjangoTemplateEngine() engine.TemplateEngine

func NewFSTemplateRepo

func NewFSTemplateRepo(templatesFolder fs.FS) repo.TemplateRepository

func NewFilesystemRepo added in v0.0.3

func NewFilesystemRepo(templatesFolder string) repo.TemplateRepository

func NewGolangTemplateEngine added in v0.0.3

func NewGolangTemplateEngine() engine.TemplateEngine

func NewPongo2TemplateEngine added in v0.0.3

func NewPongo2TemplateEngine() engine.TemplateEngine

Types

type GreypotOption added in v0.0.3

type GreypotOption func(*Module)

func WithChromeDPRenderer added in v0.0.3

func WithChromeDPRenderer(url string) GreypotOption

func WithDjangoTemplateEngine added in v0.0.3

func WithDjangoTemplateEngine() GreypotOption

func WithGolangTemplateEngine added in v0.0.3

func WithGolangTemplateEngine() GreypotOption

func WithPlaywrightRenderer added in v0.0.3

func WithPlaywrightRenderer(options ...*playwright.RunOptions) GreypotOption

func WithRenderTimeout added in v0.0.3

func WithRenderTimeout(timeout time.Duration) GreypotOption

func WithTemplateEngine added in v0.0.3

func WithTemplateEngine(e engine.TemplateEngine) GreypotOption

func WithTemplatesFromFS added in v0.0.3

func WithTemplatesFromFS(dir fs.FS) GreypotOption

func WithTemplatesFromFilesystem added in v0.0.3

func WithTemplatesFromFilesystem(dir string) GreypotOption

func WithTemplatesRepository added in v0.0.3

func WithTemplatesRepository(repository repo.TemplateRepository) GreypotOption

func WithViewport added in v0.0.3

func WithViewport(width, height int) GreypotOption

type Module

type Module struct {
	RenderTimeout  time.Duration
	ViewportHeight int
	ViewportWidth  int

	TemplateService service.TemplateService
	ReportService   service.ReportService

	TemplateEngine     engine.TemplateEngine
	TemplateRepository repo.TemplateRepository
	PDFExporter        exporter.ReportExporter
	PNGExporter        exporter.ReportExporter
}

func NewChromeDPModule added in v0.0.3

func NewChromeDPModule(renderTimeout time.Duration, repo repo.TemplateRepository) *Module

func NewModule

func NewModule(options ...GreypotOption) *Module

func NewPlaywrightModule

func NewPlaywrightModule(renderTimeout time.Duration, repo repo.TemplateRepository) *Module

Directories

Path Synopsis
http
gin
template

Jump to

Keyboard shortcuts

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