1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Add /v1/version endpoint

This commit is contained in:
Frédéric Guillot 2023-10-08 15:21:38 -07:00
parent e4285c2cba
commit 52cf236699
6 changed files with 118 additions and 0 deletions

View file

@ -5,8 +5,11 @@ package api // import "miniflux.app/v2/internal/api"
import (
"net/http"
"runtime"
"miniflux.app/v2/internal/http/response/json"
"miniflux.app/v2/internal/storage"
"miniflux.app/v2/internal/version"
"miniflux.app/v2/internal/worker"
"github.com/gorilla/mux"
@ -69,4 +72,17 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) {
sr.HandleFunc("/entries/{entryID}/fetch-content", handler.fetchContent).Methods(http.MethodGet)
sr.HandleFunc("/flush-history", handler.flushHistory).Methods(http.MethodPut, http.MethodDelete)
sr.HandleFunc("/icons/{iconID}", handler.getIconByIconID).Methods(http.MethodGet)
sr.HandleFunc("/version", handler.versionHandler).Methods(http.MethodGet)
}
func (h *handler) versionHandler(w http.ResponseWriter, r *http.Request) {
json.OK(w, r, &versionResponse{
Version: version.Version,
Commit: version.Commit,
BuildDate: version.BuildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Arch: runtime.GOARCH,
OS: runtime.GOOS,
})
}

View file

@ -21,3 +21,13 @@ type entriesResponse struct {
type feedCreationResponse struct {
FeedID int64 `json:"feed_id"`
}
type versionResponse struct {
Version string `json:"version"`
Commit string `json:"commit"`
BuildDate string `json:"build_date"`
GoVersion string `json:"go_version"`
Compiler string `json:"compiler"`
Arch string `json:"arch"`
OS string `json:"os"`
}

View file

@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//go:build integration
// +build integration
package tests
import (
"testing"
miniflux "miniflux.app/v2/client"
)
func TestVersionEndpoint(t *testing.T) {
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
version, err := client.Version()
if err != nil {
t.Fatal(err)
}
if version.Version == "" {
t.Fatal(`Version should not be empty`)
}
if version.Commit == "" {
t.Fatal(`Commit should not be empty`)
}
if version.BuildDate == "" {
t.Fatal(`Build date should not be empty`)
}
if version.GoVersion == "" {
t.Fatal(`Go version should not be empty`)
}
if version.Compiler == "" {
t.Fatal(`Compiler should not be empty`)
}
if version.Arch == "" {
t.Fatal(`Arch should not be empty`)
}
if version.OS == "" {
t.Fatal(`OS should not be empty`)
}
}