Skip to content

Commit

Permalink
Merge pull request #29 from unicornultrafoundation/develop
Browse files Browse the repository at this point in the history
Add public API for version information
  • Loading branch information
thang14 authored Feb 28, 2025
2 parents df7a19d + aca4927 commit 8f114e7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
OS=${PLATFORM%/*}
ARCH=${PLATFORM#*/}
OUTPUT="dist/${NAME}-${VERSION}-${OS}-${ARCH}"
GOOS=$OS GOARCH=$ARCH CGO_ENABLED=0 go build -o $OUTPUT ./cmd/subnet/main.go
GOOS=$OS GOARCH=$ARCH CGO_ENABLED=0 go build -ldflags "-X 'github.com/unicornultrafoundation/subnet-node.CurrentCommit=$(git rev-parse HEAD)' -X 'github.com/unicornultrafoundation/subnet-node.CurrentVersionNumber=${VERSION}'" -o $OUTPUT ./cmd/subnet/main.go
done
- name: Upload Linux Artifacts
Expand Down
7 changes: 7 additions & 0 deletions core/corehttp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func APIOption() ServeOption {
server.RegisterName("app", api.NewAppAPI(n.Apps))
server.RegisterName("account", api.NewAccountAPI(n.Account))
server.RegisterName("config", api.NewConfigAPI(n.Repo))
server.RegisterName("version", api.NewVersionAPI()) // Register the VersionAPI

// Handle public APIs without authentication
publicServer := rpc.NewServer()
publicServer.RegisterName("version", api.NewVersionAPI())
smux.Handle("/public", WithCORSHeaders(cfg, publicServer))

smux.Handle(APIPath, WithCORSHeaders(cfg, WithAuth(cfg, server)))
return smux, nil
}
Expand Down
17 changes: 17 additions & 0 deletions internal/api/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package api

import (
"context"

version "github.com/unicornultrafoundation/subnet-node"
)

type VersionAPI struct{}

func NewVersionAPI() *VersionAPI {
return &VersionAPI{}
}

func (api *VersionAPI) GetVersion(ctx context.Context) (*version.VersionInfo, error) {
return version.GetVersionInfo(), nil
}
14 changes: 7 additions & 7 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
var CurrentCommit string

// CurrentVersionNumber is the current application's version literal.
const CurrentVersionNumber = "0.0.1-dev"
var CurrentVersionNumber string

const ApiVersion = "/subnet/" + CurrentVersionNumber + "/" //nolint
var ApiVersion = "/subnet/" + CurrentVersionNumber + "/" //nolint

// Note: This will end in `/` when no commit is available. This is expected.
func GetUserAgentVersion() string {
Expand All @@ -31,17 +31,17 @@ func SetUserAgentSuffix(suffix string) {
}

type VersionInfo struct {
Version string
Commit string
System string
Golang string
Version string `json:"version"`
Commit string `json:"commit"`
System string `json:"system"`
Golang string `json:"golang"`
}

func GetVersionInfo() *VersionInfo {
return &VersionInfo{
Version: CurrentVersionNumber,
Commit: CurrentCommit,
System: runtime.GOARCH + "/" + runtime.GOOS, // TODO: Precise version here
System: runtime.GOARCH + "/" + runtime.GOOS,
Golang: runtime.Version(),
}
}

0 comments on commit 8f114e7

Please sign in to comment.