mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 20:32:13 +01:00
feat(api): add version route
This commit is contained in:
@@ -35,6 +35,7 @@ var Version = "snapshot"
|
|||||||
// Run starts the Gotenberg application. Call this in the main of your program.
|
// Run starts the Gotenberg application. Call this in the main of your program.
|
||||||
func Run() {
|
func Run() {
|
||||||
fmt.Printf(banner, Version)
|
fmt.Printf(banner, Version)
|
||||||
|
gotenberg.Version = Version
|
||||||
|
|
||||||
// Create the root FlagSet and adds the modules flags to it.
|
// Create the root FlagSet and adds the modules flags to it.
|
||||||
fs := flag.NewFlagSet("gotenberg", flag.ExitOnError)
|
fs := flag.NewFlagSet("gotenberg", flag.ExitOnError)
|
||||||
|
|||||||
4
pkg/gotenberg/version.go
Normal file
4
pkg/gotenberg/version.go
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package gotenberg
|
||||||
|
|
||||||
|
// Version is the... version of the Gotenberg application.
|
||||||
|
var Version = "snapshot"
|
||||||
@@ -323,8 +323,9 @@ func (a *Api) Validate() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
routesMap := make(map[string]string, len(a.routes)+1)
|
routesMap := make(map[string]string, len(a.routes)+2)
|
||||||
routesMap["/health"] = "/health"
|
routesMap["/health"] = "/health"
|
||||||
|
routesMap["/version"] = "/version"
|
||||||
|
|
||||||
for _, route := range a.routes {
|
for _, route := range a.routes {
|
||||||
if route.Path == "" {
|
if route.Path == "" {
|
||||||
@@ -442,7 +443,7 @@ func (a *Api) Start() error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's not forget the health check route.
|
// Let's not forget the health check route...
|
||||||
a.srv.GET(
|
a.srv.GET(
|
||||||
fmt.Sprintf("%s%s", a.rootPath, "health"),
|
fmt.Sprintf("%s%s", a.rootPath, "health"),
|
||||||
func() echo.HandlerFunc {
|
func() echo.HandlerFunc {
|
||||||
@@ -453,6 +454,14 @@ func (a *Api) Start() error {
|
|||||||
hardTimeoutMiddleware(hardTimeout),
|
hardTimeoutMiddleware(hardTimeout),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ...and the version route.
|
||||||
|
a.srv.GET(
|
||||||
|
fmt.Sprintf("%s%s", a.rootPath, "version"),
|
||||||
|
func(c echo.Context) error {
|
||||||
|
return c.String(http.StatusOK, gotenberg.Version)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
// Wait for all modules to be ready.
|
// Wait for all modules to be ready.
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), a.startTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), a.startTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
@@ -790,6 +790,15 @@ func TestApi_Start(t *testing.T) {
|
|||||||
t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code)
|
t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// version request.
|
||||||
|
versionRequest := httptest.NewRequest(http.MethodGet, "/version", nil)
|
||||||
|
versionRequest.SetBasicAuth(mod.basicAuthUsername, mod.basicAuthPassword)
|
||||||
|
|
||||||
|
mod.srv.ServeHTTP(recorder, versionRequest)
|
||||||
|
if recorder.Code != http.StatusOK {
|
||||||
|
t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code)
|
||||||
|
}
|
||||||
|
|
||||||
// "multipart/form-data" request.
|
// "multipart/form-data" request.
|
||||||
multipartRequest := func(url string) *http.Request {
|
multipartRequest := func(url string) *http.Request {
|
||||||
body := &bytes.Buffer{}
|
body := &bytes.Buffer{}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ func webhookMiddleware(w *Webhook) api.Middleware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
headers := map[string]string{
|
headers := map[string]string{
|
||||||
echo.HeaderContentType: echo.MIMEApplicationJSONCharsetUTF8,
|
echo.HeaderContentType: echo.MIMEApplicationJSON,
|
||||||
c.Get("traceHeader").(string): c.Get("trace").(string),
|
c.Get("traceHeader").(string): c.Get("trace").(string),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ func TestWebhookMiddlewareAsynchronousProcess(t *testing.T) {
|
|||||||
return errors.New("foo")
|
return errors.New("foo")
|
||||||
}
|
}
|
||||||
}(),
|
}(),
|
||||||
expectWebhookContentType: echo.MIMEApplicationJSONCharsetUTF8,
|
expectWebhookContentType: echo.MIMEApplicationJSON,
|
||||||
expectWebhookMethod: http.MethodPost,
|
expectWebhookMethod: http.MethodPost,
|
||||||
expectWebhookErrorStatus: http.StatusInternalServerError,
|
expectWebhookErrorStatus: http.StatusInternalServerError,
|
||||||
expectWebhookErrorMessage: http.StatusText(http.StatusInternalServerError),
|
expectWebhookErrorMessage: http.StatusText(http.StatusInternalServerError),
|
||||||
@@ -390,7 +390,7 @@ func TestWebhookMiddlewareAsynchronousProcess(t *testing.T) {
|
|||||||
return api.NewSentinelHttpError(http.StatusBadRequest, http.StatusText(http.StatusBadRequest))
|
return api.NewSentinelHttpError(http.StatusBadRequest, http.StatusText(http.StatusBadRequest))
|
||||||
}
|
}
|
||||||
}(),
|
}(),
|
||||||
expectWebhookContentType: echo.MIMEApplicationJSONCharsetUTF8,
|
expectWebhookContentType: echo.MIMEApplicationJSON,
|
||||||
expectWebhookMethod: http.MethodPost,
|
expectWebhookMethod: http.MethodPost,
|
||||||
expectWebhookErrorStatus: http.StatusBadRequest,
|
expectWebhookErrorStatus: http.StatusBadRequest,
|
||||||
expectWebhookErrorMessage: http.StatusText(http.StatusBadRequest),
|
expectWebhookErrorMessage: http.StatusText(http.StatusBadRequest),
|
||||||
@@ -430,7 +430,7 @@ func TestWebhookMiddlewareAsynchronousProcess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}(),
|
}(),
|
||||||
returnedError: echo.ErrInternalServerError,
|
returnedError: echo.ErrInternalServerError,
|
||||||
expectWebhookContentType: echo.MIMEApplicationJSONCharsetUTF8,
|
expectWebhookContentType: echo.MIMEApplicationJSON,
|
||||||
expectWebhookMethod: http.MethodPost,
|
expectWebhookMethod: http.MethodPost,
|
||||||
expectWebhookErrorStatus: http.StatusInternalServerError,
|
expectWebhookErrorStatus: http.StatusInternalServerError,
|
||||||
expectWebhookErrorMessage: http.StatusText(http.StatusInternalServerError),
|
expectWebhookErrorMessage: http.StatusText(http.StatusInternalServerError),
|
||||||
@@ -493,7 +493,7 @@ func TestWebhookMiddlewareAsynchronousProcess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if contentType == echo.MIMEApplicationJSONCharsetUTF8 {
|
if contentType == echo.MIMEApplicationJSON {
|
||||||
body, err := io.ReadAll(c.Request().Body)
|
body, err := io.ReadAll(c.Request().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errChan <- err
|
errChan <- err
|
||||||
|
|||||||
Reference in New Issue
Block a user