Git Product home page Git Product logo

gotenberg-template-repository's Introduction

Gotenberg Logo

Gotenberg

A Docker-powered stateless API for PDF files

Documentation ยท Live Demo ๐Ÿ”ฅ


Gotenberg provides a developer-friendly API to interact with powerful tools like Chromium and LibreOffice for converting numerous document formats (HTML, Markdown, Word, Excel, etc.) into PDF files, and more!

Quick Start

Open a terminal and run the following command:

docker run --rm -p 3000:3000 gotenberg/gotenberg:8

Alternatively, using the historic Docker repository from our sponsor TheCodingMachine:

docker run --rm -p 3000:3000 thecodingmachine/gotenberg:8

The API is now available on your host at http://localhost:3000.

Head to the documentation to learn how to interact with it ๐Ÿš€

Sponsors

TheCodingMachine Logo

Badges

Docker pulls Docker pulls Continuous Integration Go Reference Codecov

gotenberg-template-repository's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

apollohuang1

gotenberg-template-repository's Issues

Provision and Validate functions not being called in the Example module

I'm looking into creating a custom module. As a first step, I thought I'd get the example module running and play around with it. I put log statements in the init, Descriptor, Provision, and Validate methods to see when they get called. It appears to me that Provision and Validate are never being called. Is that expected? If not, thoughts on how to fix it?

Here's the example.go file with the log statements:

package example

import (
	"fmt"
	"log"

	"github.com/gotenberg/gotenberg/v7/pkg/gotenberg"
	flag "github.com/spf13/pflag"
	"go.uber.org/multierr"
)

func init() {
	log.Print("Running example.init()")

	gotenberg.MustRegisterModule(Example{})
}

// Example is our module. It does nothing.
type Example struct {
	strProp string
	intProp int
}

// Descriptor returns an Example's module descriptor.
func (mod Example) Descriptor() gotenberg.ModuleDescriptor {
	log.Print("Running example.Descriptor()")
	return gotenberg.ModuleDescriptor{
		ID: "example",
		FlagSet: func() *flag.FlagSet {
			fs := flag.NewFlagSet("example", flag.ExitOnError)
			// fs.String("example-str-prop", "", "Set the string property")
			// fs.Int("example-int-prop", 0, "Set the int property")

			return fs
		}(),
		New: func() gotenberg.Module { return new(Example) },
	}
}

// Provision sets the module properties.
func (mod *Example) Provision(ctx *gotenberg.Context) error {
	log.Print("Running example.Provision()")
	flags := ctx.ParsedFlags()
	mod.strProp = flags.MustString("example-str-prop")
	mod.intProp = flags.MustInt("example-int-prop")

	return nil
}

// Validate validates the module properties.
func (mod Example) Validate() error {
	log.Print("Running example.Validate()")
	var err error

	if mod.strProp == "bar" {
		err = multierr.Append(err, fmt.Errorf("str prop must be different than bar"))
	}

	if mod.intProp == 1337 {
		err = multierr.Append(err, fmt.Errorf("int prop must be different than 1337"))
	}

	return err
}

// Interface guards.
var (
	_ gotenberg.Module      = (*Example)(nil)
	_ gotenberg.Provisioner = (*Example)(nil)
	_ gotenberg.Validator   = (*Example)(nil)
)

This is what I get in the console:

> docker run --rm -p 3000:3000 app/gotenberg:7-app-snapshot
2023/04/16 20:19:58 Running ddconfig.init()
2023/04/16 20:19:58 Running ddconfig.Descriptor()

  _____     __           __               
 / ___/__  / /____ ___  / /  ___ _______ _
/ (_ / _ \/ __/ -_) _ \/ _ \/ -_) __/ _ '/
\___/\___/\__/\__/_//_/_.__/\__/_/  \_, / 
                                   /___/

A Docker-powered stateless API for PDF files.
Version: 7-app-snapshot
-------------------------------------------------------
[SYSTEM] modules: api chromium example gc libreoffice logging pdfcpu pdfengines pdftk prometheus qpdf uno uno-pdfengine webhook 
[SYSTEM] pdfengines: pdfcpu pdftk qpdf uno-pdfengine
[SYSTEM] gc: application started
[SYSTEM] prometheus: collecting metrics
[SYSTEM] uno: long-running LibreOffice listener ready to start
[SYSTEM] api: server listening on port 3000

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.