Skip to content

Commit

Permalink
Add /v1/version endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Oct 8, 2023
1 parent e4285c2 commit 52cf236
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
16 changes: 16 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ func New(endpoint string, credentials ...string) *Client {
return &Client{request: &request{endpoint: endpoint, apiKey: credentials[0]}}
}

// Version returns the version of the Miniflux instance.
func (c *Client) Version() (*VersionResponse, error) {
body, err := c.request.Get("/v1/version")
if err != nil {
return nil, err
}
defer body.Close()

var versionResponse *VersionResponse
if err := json.NewDecoder(body).Decode(&versionResponse); err != nil {
return nil, fmt.Errorf("miniflux: json error (%v)", err)
}

return versionResponse, nil
}

// Me returns the logged user information.
func (c *Client) Me() (*User, error) {
body, err := c.request.Get("/v1/me")
Expand Down
11 changes: 11 additions & 0 deletions client/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,14 @@ type EntryResultSet struct {
Total int `json:"total"`
Entries Entries `json:"entries"`
}

// VersionResponse represents the version and the build information of the Miniflux instance.
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"`
}
16 changes: 16 additions & 0 deletions contrib/bruno/miniflux/Get version and build information.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
meta {
name: Get version and build information
type: http
seq: 42
}

get {
url: {{minifluxBaseURL}}/v1/version
body: none
auth: basic
}

auth:basic {
username: {{minifluxUsername}}
password: {{minifluxPassword}}
}
16 changes: 16 additions & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
})
}
10 changes: 10 additions & 0 deletions internal/api/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
49 changes: 49 additions & 0 deletions internal/tests/version_test.go
Original file line number Diff line number Diff line change
@@ -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`)
}
}

0 comments on commit 52cf236

Please sign in to comment.