Skip to content

Commit

Permalink
added status (#46)
Browse files Browse the repository at this point in the history
* added status

* removed unused param

* addressed review maarten
  • Loading branch information
RabbITCybErSeC authored Sep 6, 2024
1 parent cfda1bf commit 7f5d021
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ BUILDTIME := $(shell date '+%Y-%m-%dT%T%z')
GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.Buildtime=$(BUILDTIME)
GOFLAGS = -ldflags "$(GOLDFLAGS)"

#-----------------------------------------------------
# DEV
#-----------------------------------------------------


dev:
@make -j dev-templ dev-tailwind dev-server

dev-server:
# run air to detect any go file changes to re-build and re-run the server.

@go run github.com/air-verse/air@latest \
--build.cmd "templ generate && go build --tags dev -o tmp/bin/main ./server/" --build.bin "tmp/bin/main" --build.delay "100" \
--build.cmd "templ generate && go build -ldflags \"-X main.Version=$(VERSION)\" --tags dev -o tmp/bin/main ./server/" --build.bin "tmp/bin/main" --build.delay "100" \
--build.exclude_dir "node_modules" \
--build.exclude_regex ".*_templ.go" \
--build.include_ext "go,templ" \
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module soarca-gui
go 1.22.2

require (
github.com/a-h/templ v0.2.747
github.com/a-h/templ v0.2.771
github.com/gin-gonic/gin v1.10.0
github.com/stretchr/testify v1.9.0
)
Expand Down Expand Up @@ -35,10 +35,10 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/a-h/templ v0.2.747 h1:D0dQ2lxC3W7Dxl6fxQ/1zZHBQslSkTSvl5FxP/CfdKg=
github.com/a-h/templ v0.2.747/go.mod h1:69ObQIbrcuwPCU32ohNaWce3Cb7qM5GMiqN1K+2yop4=
github.com/a-h/templ v0.2.771 h1:4KH5ykNigYGGpCe0fRJ7/hzwz72k3qFqIiiLLJskbSo=
github.com/a-h/templ v0.2.771/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
Expand Down Expand Up @@ -70,16 +70,16 @@ github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZ
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
20 changes: 20 additions & 0 deletions internal/status/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package status

import (
"runtime"
"soarca-gui/models/status"
"soarca-gui/utils"
"time"
)

var internalStatus = status.Status{Uptime: status.Uptime{Since: time.Now(), Milliseconds: 0},
Mode: utils.GetEnv("LOG_MODE", "production"),
Runtime: runtime.GOOS}

func SetVersion(version string) {
internalStatus.Version = version
}

func GetVersion() string {
return internalStatus.Version
}
16 changes: 16 additions & 0 deletions models/status/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package status

import "time"

type Uptime struct {
Since time.Time `json:"since"`
Milliseconds uint64 `json:"milliseconds"`
}

type Status struct {
Version string `json:"version"`
Runtime string `json:"runtime"`
Mode string `json:"mode"`
Time time.Time `json:"time"`
Uptime Uptime `json:"uptime"`
}
8 changes: 6 additions & 2 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"

"soarca-gui/internal/status"
"soarca-gui/routes"
"soarca-gui/utils"

Expand All @@ -11,18 +12,21 @@ import (
)

var (
Version string
Buildtime string
Version string = "dev"
Buildtime string = ""
)

// @title SOARCA-GUI
// @version 0.0.1
func main() {
fmt.Println("Version: ", Version)
fmt.Println("Buildtime ", Buildtime)
errenv := godotenv.Load(".env")

if errenv != nil {
fmt.Println("Failed to read env variable, but will continue")
}
status.SetVersion(Version)

app := gin.Default()
routes.Setup(app)
Expand Down
7 changes: 5 additions & 2 deletions views/components/navbar/navbar.templ
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package navbar

import "soarca-gui/views/components/icons"
import (
"soarca-gui/internal/status"
"soarca-gui/views/components/icons"
)

const (
soarcaLogoUrlPath = "/public/assets/icons/soarca-logo.svg"
Expand All @@ -24,7 +27,7 @@ templ Navsidebar(title string, homeLink string, version string, documentationUrl
@icons.NewIcon("book").InsertIcon("mr-3")
Documentation
</span>
<span class="break-normal italic">GUI Version: { version }</span>
<span class="text-xs break-normal italic">Version: { status.GetVersion() }</span>
</a>
</aside>
}

0 comments on commit 7f5d021

Please sign in to comment.