Skip to content

Add proper mqtt2http version in the info API endpoint - #24

Merged
amm0nite merged 3 commits into
mainfrom
proper-version-info-endpoint
Feb 18, 2026
Merged

Add proper mqtt2http version in the info API endpoint#24
amm0nite merged 3 commits into
mainfrom
proper-version-info-endpoint

Conversation

@amm0nite

@amm0nite amm0nite commented Feb 17, 2026

Copy link
Copy Markdown
Owner

Closes #10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses issue #10 by adding proper mqtt2http version information to the info API endpoint. Previously, the root endpoint (/) returned only the underlying MQTT broker's version (from the mochi-mqtt library), which was confusing for users trying to identify the mqtt2http version.

Changes:

  • Introduced version injection at build time via Docker build args and Go ldflags
  • Modified API response structure to include both mqtt2http version and broker information
  • Added version logging at startup for better visibility

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/mqtt2http.go Added version variable with ldflags injection and default "dev" fallback
broker/config.go Extended BrokerConfig to include Version field
broker/broker.go Added version logging at startup and passes version to API controller
api/controller.go Restructured root endpoint response to wrap broker info with mqtt2http version in AppInfo struct
Dockerfile Added BUILD_VERSION build arg and configured ldflags for version injection
.github/workflows/build.yml Added BUILD_VERSION build arg to release workflow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: BUILD_VERSION=${{ github.ref_name }}

Copilot AI Feb 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build-args parameter should also be added to the build-latest job (around line 66-75 in the file) to ensure builds from the main branch don't always default to "dev" version. Without this, the latest Docker tag will show version="dev" instead of a meaningful version identifier. Consider passing BUILD_VERSION for consistency across all build jobs.

Copilot uses AI. Check for mistakes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/controller.go
Comment on lines +20 to +23
type AppInfo struct {
Version string `json:"version"`
Broker *system.Info `json:"broker"`
}

Copilot AI Feb 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root endpoint response shape changes from returning the broker info directly to wrapping it under broker. That is a breaking API change for any consumers expecting the previous top-level fields. If the goal is only to fix the version field, consider preserving the existing JSON structure and overriding/adding fields (e.g., keep broker fields at the top-level and introduce a separate brokerVersion/mqttVersion field) rather than nesting everything under broker.

Copilot uses AI. Check for mistakes.
Comment thread api/controller.go
Broker *system.Info `json:"broker"`
}

func NewController(version string, server *mqtt.Server, store *lib.ClientStore, password string) *Controller {

Copilot AI Feb 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version can be an empty string (e.g., tests/other callers construct BrokerConfig without setting it), which would make the / endpoint report an empty version. Consider defaulting version to something like "dev" inside NewController (or earlier when building BrokerConfig) when an empty value is passed in.

Suggested change
func NewController(version string, server *mqtt.Server, store *lib.ClientStore, password string) *Controller {
func NewController(version string, server *mqtt.Server, store *lib.ClientStore, password string) *Controller {
if version == "" {
version = "dev"
}

Copilot uses AI. Check for mistakes.
Comment thread api/controller.go
Comment on lines 29 to 45
func (c *Controller) RootHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
info, _ := json.Marshal(c.server.Info)
info := &AppInfo{
Version: c.version,
Broker: c.server.Info.Clone(),
}

data, err := json.Marshal(info)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
io.WriteString(w, err.Error())
return
}

w.Header().Set("Content-Type", "application/json")
w.Write(info)
w.Write(data)
}

Copilot AI Feb 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior is introduced for / (including application version and broker info nesting), but there are no tests asserting the root endpoint’s JSON structure or version value. Adding a focused test would prevent regressions and clarify the intended contract for the info endpoint.

Copilot uses AI. Check for mistakes.
Comment thread Dockerfile Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@amm0nite
amm0nite merged commit e4fbcfa into main Feb 18, 2026
3 checks passed
@amm0nite
amm0nite deleted the proper-version-info-endpoint branch February 18, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The HTTP Endpoint / returns version of underlying HTTP service

2 participants