mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-10-12 23:33:16 +01:00
feat: add metrics system, move webhook feature to dedicated module (#372)
This commit is contained in:
@@ -131,8 +131,8 @@ func (mod PDFEngines) PDFEngine() (gotenberg.PDFEngine, error) {
|
||||
return newMultiPDFEngines(engines...), nil
|
||||
}
|
||||
|
||||
// Routes returns the API routes.
|
||||
func (mod PDFEngines) Routes() ([]api.MultipartFormDataRoute, error) {
|
||||
// Routes returns the HTTP routes.
|
||||
func (mod PDFEngines) Routes() ([]api.Route, error) {
|
||||
if mod.disableRoutes {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func (mod PDFEngines) Routes() ([]api.MultipartFormDataRoute, error) {
|
||||
return nil, fmt.Errorf("get pdf engine: %w", err)
|
||||
}
|
||||
|
||||
return []api.MultipartFormDataRoute{
|
||||
return []api.Route{
|
||||
mergeRoute(engine),
|
||||
convertRoute(engine),
|
||||
}, nil
|
||||
@@ -156,5 +156,5 @@ var (
|
||||
_ gotenberg.Provisioner = (*PDFEngines)(nil)
|
||||
_ gotenberg.Validator = (*PDFEngines)(nil)
|
||||
_ gotenberg.PDFEngineProvider = (*PDFEngines)(nil)
|
||||
_ api.MultipartFormDataRouter = (*PDFEngines)(nil)
|
||||
_ api.Router = (*PDFEngines)(nil)
|
||||
)
|
||||
|
||||
@@ -7,13 +7,18 @@ import (
|
||||
|
||||
"github.com/gotenberg/gotenberg/v7/pkg/gotenberg"
|
||||
"github.com/gotenberg/gotenberg/v7/pkg/modules/api"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// mergeRoute returns an api.MultipartFormDataRoute which can merge PDFs.
|
||||
func mergeRoute(engine gotenberg.PDFEngine) api.MultipartFormDataRoute {
|
||||
return api.MultipartFormDataRoute{
|
||||
Path: "/pdfengines/merge",
|
||||
Handler: func(ctx *api.Context) error {
|
||||
// mergeRoute returns an api.Route which can merge PDFs.
|
||||
func mergeRoute(engine gotenberg.PDFEngine) api.Route {
|
||||
return api.Route{
|
||||
Method: http.MethodPost,
|
||||
Path: "/forms/pdfengines/merge",
|
||||
IsMultipart: true,
|
||||
Handler: func(c echo.Context) error {
|
||||
ctx := c.Get("context").(*api.Context)
|
||||
|
||||
// Let's get the data from the form and validate them.
|
||||
var (
|
||||
inputPaths []string
|
||||
@@ -79,12 +84,16 @@ func mergeRoute(engine gotenberg.PDFEngine) api.MultipartFormDataRoute {
|
||||
}
|
||||
}
|
||||
|
||||
// convertRoute returns an api.MultipartFormDataRoute which can convert a PDF
|
||||
// to a specific PDF format.
|
||||
func convertRoute(engine gotenberg.PDFEngine) api.MultipartFormDataRoute {
|
||||
return api.MultipartFormDataRoute{
|
||||
Path: "/pdfengines/convert",
|
||||
Handler: func(ctx *api.Context) error {
|
||||
// convertRoute returns an api.Route which can convert a PDF to a specific PDF
|
||||
// format.
|
||||
func convertRoute(engine gotenberg.PDFEngine) api.Route {
|
||||
return api.Route{
|
||||
Method: http.MethodPost,
|
||||
Path: "/forms/pdfengines/convert",
|
||||
IsMultipart: true,
|
||||
Handler: func(c echo.Context) error {
|
||||
ctx := c.Get("context").(*api.Context)
|
||||
|
||||
// Let's get the data from the form and validate them.
|
||||
var (
|
||||
inputPaths []string
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/gotenberg/gotenberg/v7/pkg/gotenberg"
|
||||
"github.com/gotenberg/gotenberg/v7/pkg/modules/api"
|
||||
"github.com/labstack/echo/v4"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -168,7 +169,10 @@ func TestMergeHandler(t *testing.T) {
|
||||
expectOutputPathsCount: 1,
|
||||
},
|
||||
} {
|
||||
err := mergeRoute(tc.engine).Handler(tc.ctx.Context)
|
||||
c := echo.New().NewContext(nil, nil)
|
||||
c.Set("context", tc.ctx.Context)
|
||||
|
||||
err := mergeRoute(tc.engine).Handler(c)
|
||||
|
||||
if tc.expectErr && err == nil {
|
||||
t.Errorf("test %d: expected error but got: %v", i, err)
|
||||
@@ -357,7 +361,10 @@ func TestConvertHandler(t *testing.T) {
|
||||
expectOutputPathsCount: 2,
|
||||
},
|
||||
} {
|
||||
err := convertRoute(tc.engine).Handler(tc.ctx.Context)
|
||||
c := echo.New().NewContext(nil, nil)
|
||||
c.Set("context", tc.ctx.Context)
|
||||
|
||||
err := convertRoute(tc.engine).Handler(c)
|
||||
|
||||
if tc.expectErr && err == nil {
|
||||
t.Errorf("test %d: expected error but got: %v", i, err)
|
||||
|
||||
Reference in New Issue
Block a user