Skip to content

Commit

Permalink
Re-factor code structures (No feature changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed Jan 4, 2024
1 parent 9c181fb commit f712cc4
Show file tree
Hide file tree
Showing 52 changed files with 164 additions and 111 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
cm-honeybee
cm-honeybee.exe

coverage.out
vendor
.idea/
Expand Down
27 changes: 14 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ SHELL = /bin/bash

MODULE_NAME := "cm-honeybee"
PROJECT_NAME := "github.com/cloud-barista/${MODULE_NAME}"
PKG_LIST := $(shell go list ${PROJECT_NAME}/...)
PKG_LIST := $(shell go list ${PROJECT_NAME}/... 2>&1)

GOPROXY_OPTION := GOPROXY=direct GOSUMDB=off
GO_COMMAND := ${GOPROXY_OPTION} go
GOPATH := $(shell go env GOPATH)

.PHONY: all dependency lint test race coverage coverhtml gofmt update build windows swag swagger clean help
.PHONY: all dependency lint test race coverage coverhtml gofmt update swag swagger build windows clean help

all: build

Expand Down Expand Up @@ -50,28 +50,29 @@ update: ## Update all of module dependencies
@echo Checking dependencies...
@${GO_COMMAND} mod tidy

swag swagger: ## Generate Swagger Documentation
@echo "Running swag..."
@if [ ! -f "${GOPATH}/bin/swag" ] && [ ! -f "$(GOROOT)/bin/swag" ]; then \
${GO_COMMAND} install github.com/swaggo/swag/cmd/swag@latest; \
fi
@swag init -g ./pkg/api/rest/server/server.go --pd -o ./pkg/api/rest/docs/ > /dev/null

build: lint swag ## Build the binary file
@echo Building...
@CGO_ENABLED=0 ${GO_COMMAND} build -o ${MODULE_NAME} main.go
@cd cmd/${MODULE_NAME} && CGO_ENABLED=0 ${GO_COMMAND} build -o ${MODULE_NAME} main.go
@echo Build finished!

windows: lint ## Build the Windows exe binary file
@echo Building for Windows system...
@GOOS=windows CGO_ENABLED=0 ${GO_COMMAND} build -o ${MODULE_NAME}.exe main.go
@cd cmd/${MODULE_NAME} && GOOS=windows CGO_ENABLED=0 ${GO_COMMAND} build -o ${MODULE_NAME}.exe main.go
@echo Build finished!

swag swagger: ## Generate Swagger Documentation
@echo "Running swag..."
@if [ ! -f "${GOPATH}/bin/swag" ] && [ ! -f "$(GOROOT)/bin/swag" ]; then \
${GO_COMMAND} install github.com/swaggo/swag/cmd/swag@latest; \
fi
@swag init --parseDependency > /dev/null

clean: ## Remove previous build
@echo Cleaning build...
@rm -f coverage.out
@rm -f docs/docs.go docs/swagger.*
@${GO_COMMAND} clean
@rm -f pkg/api/rest/docs/docs.go pkg/api/rest/docs/swagger.*
@rm -f cmd/${MODULE_NAME}/conf
@cd cmd/${MODULE_NAME} && ${GO_COMMAND} clean

help: ## Display this help screen
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
3 changes: 3 additions & 0 deletions cmd/cm-honeybee/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cm-honeybee
cm-honeybee.exe
conf
4 changes: 2 additions & 2 deletions main.go → cmd/cm-honeybee/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"github.com/cloud-barista/cm-honeybee/api/echo"
"github.com/cloud-barista/cm-honeybee/common"
"github.com/cloud-barista/cm-honeybee/lib/config"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/server"
"github.com/jollaman999/utils/logger"
"github.com/jollaman999/utils/syscheck"
"log"
Expand Down Expand Up @@ -36,7 +36,7 @@ func init() {

logger.Println(logger.INFO, false, "Agent UUID: "+common.AgentUUID)

echo.Init()
server.Init()
}

func end() {
Expand Down
3 changes: 3 additions & 0 deletions common/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package common
// ModuleName : Name of the module
var ModuleName = "CM-HONEYBEE"

// ShortModuleName : Short name of the module
var ShortModuleName = "HONEYBEE"

// ModuleROOT : Variable name of the module's root path
var ModuleROOT = "CMHONEYBEE_ROOT"
2 changes: 0 additions & 2 deletions docs/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion driver/infra/compute_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package infra
import (
"bufio"
"errors"
"github.com/cloud-barista/cm-honeybee/model/infra"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/infra"
"github.com/jollaman999/utils/cmd"
"github.com/jollaman999/utils/fileutil"
"github.com/shirou/gopsutil/v3/cpu"
Expand Down
2 changes: 1 addition & 1 deletion driver/infra/compute_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package infra
import (
"errors"
"fmt"
"github.com/cloud-barista/cm-honeybee/model/infra"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/infra"
"github.com/jaypipes/ghw"
"github.com/jollaman999/utils/logger"
"github.com/shirou/gopsutil/v3/cpu"
Expand Down
2 changes: 1 addition & 1 deletion driver/infra/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package infra
import (
"github.com/cloud-barista/cm-honeybee/gpu/drm"
"github.com/cloud-barista/cm-honeybee/gpu/nvidia"
"github.com/cloud-barista/cm-honeybee/model/infra"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/infra"
)

func GetGPUInfo() (infra.GPU, error) {
Expand Down
4 changes: 3 additions & 1 deletion driver/infra/infra.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package infra

import "github.com/cloud-barista/cm-honeybee/model/infra"
import (
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/infra"
)

func GetInfraInfo() (*infra.Infra, error) {
var i infra.Infra
Expand Down
2 changes: 1 addition & 1 deletion driver/infra/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package infra
import (
"errors"
"github.com/cloud-barista/cm-honeybee/driver/network"
modelNet "github.com/cloud-barista/cm-honeybee/model/network"
modelNet "github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/jollaman999/utils/logger"
)

Expand Down
2 changes: 1 addition & 1 deletion driver/network/bond_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package network

import (
"bufio"
"github.com/cloud-barista/cm-honeybee/model/network"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/jollaman999/utils/fileutil"
"github.com/shirou/gopsutil/v3/net"
"path/filepath"
Expand Down
2 changes: 1 addition & 1 deletion driver/network/bond_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package network

import (
"github.com/cloud-barista/cm-honeybee/model/network"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/jollaman999/utils/logger"
)

Expand Down
2 changes: 1 addition & 1 deletion driver/network/libvirtNet_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package network
import (
"errors"
"fmt"
"github.com/cloud-barista/cm-honeybee/model/network"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/digitalocean/go-libvirt"
"github.com/digitalocean/go-libvirt/socket/dialers"
"github.com/jollaman999/utils/fileutil"
Expand Down
2 changes: 1 addition & 1 deletion driver/network/libvirtNet_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package network

import (
"github.com/cloud-barista/cm-honeybee/model/network"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/jollaman999/utils/logger"
)

Expand Down
2 changes: 1 addition & 1 deletion driver/network/netfilter_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package network

import (
"github.com/cloud-barista/cm-honeybee/model/network"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/coreos/go-iptables/iptables"
"github.com/jollaman999/utils/logger"
)
Expand Down
2 changes: 1 addition & 1 deletion driver/network/netfilter_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package network

import (
"github.com/cloud-barista/cm-honeybee/model/network"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
)

func GetNetfilterList() (network.Netfilter, error) {
Expand Down
12 changes: 6 additions & 6 deletions driver/network/nic_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package network

import (
"github.com/cloud-barista/cm-honeybee/lib/routes"
"github.com/cloud-barista/cm-honeybee/model/network"
network2 "github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/shirou/gopsutil/v3/net"
)

func GetNICs() ([]network.NIC, error) {
var nics []network.NIC
func GetNICs() ([]network2.NIC, error) {
var nics []network2.NIC

interfaces, err := net.Interfaces()
if err != nil {
Expand All @@ -34,7 +34,7 @@ func GetNICs() ([]network.NIC, error) {
for _, i := range interfaces {
var addresses []string
var gateways []string
var ros []network.Route
var ros []network2.Route

for _, a := range i.Addrs {
addresses = append(addresses, a.Addr)
Expand All @@ -48,15 +48,15 @@ func GetNICs() ([]network.NIC, error) {

for _, route := range allRoutes {
if route.Interface == i.Name {
ros = append(ros, network.Route{
ros = append(ros, network2.Route{
Destination: route.Destination,
Netmask: route.Netmask,
NextHop: route.NextHop,
})
}
}

nics = append(nics, network.NIC{
nics = append(nics, network2.NIC{
Interface: i.Name,
Address: addresses,
Gateway: gateways,
Expand Down
12 changes: 6 additions & 6 deletions driver/network/nic_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ package network

import (
"github.com/cloud-barista/cm-honeybee/lib/routes"
"github.com/cloud-barista/cm-honeybee/model/network"
network2 "github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/shirou/gopsutil/v3/net"
"strings"
)

func GetNICs() ([]network.NIC, error) {
var networkInterfaces []network.NIC
func GetNICs() ([]network2.NIC, error) {
var networkInterfaces []network2.NIC

interfaces, err := net.Interfaces()
if err != nil {
Expand All @@ -36,7 +36,7 @@ func GetNICs() ([]network.NIC, error) {
var addresses []string
var addressesWithoutPrefix []string
var gateways []string
var ros []network.Route
var ros []network2.Route

for _, a := range i.Addrs {
addresses = append(addresses, a.Addr)
Expand All @@ -57,7 +57,7 @@ func GetNICs() ([]network.NIC, error) {
for _, route := range allRoutes {
for _, a := range addressesWithoutPrefix {
if route.Interface == a {
ros = append(ros, network.Route{
ros = append(ros, network2.Route{
Destination: route.Destination,
Netmask: route.Netmask,
NextHop: route.NextHop,
Expand All @@ -66,7 +66,7 @@ func GetNICs() ([]network.NIC, error) {
}
}

networkInterfaces = append(networkInterfaces, network.NIC{
networkInterfaces = append(networkInterfaces, network2.NIC{
Interface: i.Name,
Address: addresses,
Gateway: gateways,
Expand Down
2 changes: 1 addition & 1 deletion driver/network/ovs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/cloud-barista/cm-honeybee/model/network"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/jollaman999/utils/fileutil"
"github.com/jollaman999/utils/logger"
"regexp"
Expand Down
2 changes: 1 addition & 1 deletion driver/network/ovs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package network

import (
"github.com/cloud-barista/cm-honeybee/model/network"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"github.com/jollaman999/utils/logger"
)

Expand Down
2 changes: 1 addition & 1 deletion driver/network/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package network
import (
"errors"
"github.com/cloud-barista/cm-honeybee/lib/routes"
"github.com/cloud-barista/cm-honeybee/model/network"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/network"
"runtime"
)

Expand Down
2 changes: 1 addition & 1 deletion driver/software/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package software

import (
"bufio"
"github.com/cloud-barista/cm-honeybee/model/software"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/software"
"github.com/jollaman999/utils/fileutil"
"github.com/jollaman999/utils/logger"
"io"
Expand Down
2 changes: 1 addition & 1 deletion driver/software/rpm.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package software

import (
"github.com/cloud-barista/cm-honeybee/model/software"
"github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/software"
_ "github.com/glebarez/go-sqlite" // sqlite
"github.com/hashicorp/go-multierror"
rpmdb "github.com/knqyf263/go-rpmdb/pkg"
Expand Down
14 changes: 7 additions & 7 deletions driver/software/software.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package software

import (
"github.com/cloud-barista/cm-honeybee/model/software"
software2 "github.com/cloud-barista/cm-honeybee/pkg/api/rest/model/software"
"github.com/jollaman999/utils/logger"
"github.com/shirou/gopsutil/v3/host"
)

func GetSoftwareInfo() (*software.Software, error) {
deb := make([]software.DEB, 0)
rpm := make([]software.RPM, 0)
func GetSoftwareInfo() (*software2.Software, error) {
deb := make([]software2.DEB, 0)
rpm := make([]software2.RPM, 0)
var err error

h, err := host.Info()
Expand Down Expand Up @@ -40,13 +40,13 @@ func GetSoftwareInfo() (*software.Software, error) {
logger.Println(logger.DEBUG, true, "PODMAN: "+err.Error())
}

sw := software.Software{
sw := software2.Software{
DEB: deb,
RPM: rpm,
Docker: software.Docker{
Docker: software2.Docker{
Containers: dockerContainers,
},
Podman: software.Podman{
Podman: software2.Podman{
Containers: podmanContainers,
},
}
Expand Down
8 changes: 4 additions & 4 deletions api/echo/common.go → pkg/api/rest/common/error.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package echo
package common

import (
"github.com/jollaman999/utils/logger"
"github.com/labstack/echo/v4"
"net/http"
)

func returnErrorMsg(c echo.Context, msg string) error {
func ReturnErrorMsg(c echo.Context, msg string) error {
return c.JSONPretty(http.StatusBadRequest, map[string]string{
"error": msg,
}, " ")
}

func returnInternalError(c echo.Context, err error, reason string) error {
func ReturnInternalError(c echo.Context, err error, reason string) error {
logger.Println(logger.ERROR, true, err.Error())

return returnErrorMsg(c, "Internal error occurred. (Reason: "+reason+", Error: "+err.Error()+")")
return ReturnErrorMsg(c, "Internal error occurred. (Reason: "+reason+", Error: "+err.Error()+")")
}
Loading

0 comments on commit f712cc4

Please sign in to comment.