mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 12:22:17 +01:00
removing server timeouts as some process might take time + improving default commands' timeouts + godoc for app and main packages
This commit is contained in:
22
app/app.go
22
app/app.go
@@ -1,9 +1,9 @@
|
|||||||
|
// Package app is the entry point of the application.
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gulien/gotenberg/app/config"
|
"github.com/gulien/gotenberg/app/config"
|
||||||
"github.com/gulien/gotenberg/app/handlers"
|
"github.com/gulien/gotenberg/app/handlers"
|
||||||
@@ -13,12 +13,19 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// App gathers all data required to start the application.
|
||||||
type App struct {
|
type App struct {
|
||||||
|
// version is the application version as defined in the main package.
|
||||||
version string
|
version string
|
||||||
config *config.AppConfig
|
// config is the application configuration.
|
||||||
Server *http.Server
|
// It's populated thanks to the gotenberg.yml file.
|
||||||
|
config *config.AppConfig
|
||||||
|
// Server is the instance of http.Server used by the application.
|
||||||
|
Server *http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewApp instantiates the application by loading the configuration from the
|
||||||
|
// gotenberg.yml file.
|
||||||
func NewApp(version string) (*App, error) {
|
func NewApp(version string) (*App, error) {
|
||||||
c, err := config.NewAppConfig()
|
c, err := config.NewAppConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -38,17 +45,14 @@ func NewApp(version string) (*App, error) {
|
|||||||
r.Handle("/", handlers.GetHandlersChain())
|
r.Handle("/", handlers.GetHandlersChain())
|
||||||
|
|
||||||
a.Server = &http.Server{
|
a.Server = &http.Server{
|
||||||
Addr: fmt.Sprintf(":%s", a.config.Port),
|
Addr: fmt.Sprintf(":%s", a.config.Port),
|
||||||
// good practice to set timeouts to avoid Slowloris attacks.
|
Handler: r,
|
||||||
WriteTimeout: time.Second * 15,
|
|
||||||
ReadTimeout: time.Second * 15,
|
|
||||||
IdleTimeout: time.Second * 60,
|
|
||||||
Handler: r,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run starts the server.
|
||||||
func (a *App) Run() error {
|
func (a *App) Run() error {
|
||||||
process.Load(a.config.CommandsConfig)
|
process.Load(a.config.CommandsConfig)
|
||||||
logger.Infof("Starting Gotenberg version %s", a.version)
|
logger.Infof("Starting Gotenberg version %s", a.version)
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ logs:
|
|||||||
commands:
|
commands:
|
||||||
|
|
||||||
html:
|
html:
|
||||||
timeout: 10
|
timeout: 30
|
||||||
template: "xvfb-run -e /dev/stdout wkhtmltopdf {{ .FilePath }} {{ .ResultFilePath }}"
|
template: "xvfb-run -e /dev/stdout wkhtmltopdf {{ .FilePath }} {{ .ResultFilePath }}"
|
||||||
|
|
||||||
office:
|
office:
|
||||||
timeout: 10
|
timeout: 30
|
||||||
template: "unoconv --format pdf --output \"{{ .ResultFilePath }}\" \"{{ .FilePath }}\""
|
template: "unoconv --format pdf --output \"{{ .ResultFilePath }}\" \"{{ .FilePath }}\""
|
||||||
|
|
||||||
merge:
|
merge:
|
||||||
timeout: 10
|
timeout: 30
|
||||||
template: "pdftk {{ range $filePath := .FilesPaths }} {{ $filePath }} {{ end }} cat output {{ .ResultFilePath }}"
|
template: "pdftk {{ range $filePath := .FilesPaths }} {{ $filePath }} {{ end }} cat output {{ .ResultFilePath }}"
|
||||||
|
|||||||
5
main.go
5
main.go
@@ -1,8 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Package main handles the application startup and shutdown.
|
Package main handles the application startup and shutdown.
|
||||||
|
|
||||||
Gotenberg is a stateless API for generating PDF from many sources
|
Gotenberg is a stateless API for converting HTML files and Office document to PDF.
|
||||||
(".html", ".doc", ".docx").
|
|
||||||
|
|
||||||
For more information, go to https://github.com/gulien/gotenberg.
|
For more information, go to https://github.com/gulien/gotenberg.
|
||||||
*/
|
*/
|
||||||
@@ -23,7 +22,7 @@ import (
|
|||||||
// version will be set on build time.
|
// version will be set on build time.
|
||||||
var version = "master"
|
var version = "master"
|
||||||
|
|
||||||
// main initializes the application and handles
|
// main initializes the application, starts it, and handles
|
||||||
// graceful shutdown.
|
// graceful shutdown.
|
||||||
func main() {
|
func main() {
|
||||||
a, err := app.NewApp(version)
|
a, err := app.NewApp(version)
|
||||||
|
|||||||
Reference in New Issue
Block a user