Skip to content

Commit

Permalink
add system info query system
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyaoi committed Dec 9, 2018
1 parent a1b27e5 commit 9e907a6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
24 changes: 24 additions & 0 deletions cli/daemon.go
Expand Up @@ -68,6 +68,23 @@ func GetRunningSolversByPackageHandler(c *gin.Context) {
c.JSON(http.StatusOK, runningSolversInPackage)
}

// Handle Post Repos Request -> Install Package
type addRepoRequest struct {
RepoType string `json:type`
URL string `json:url`
}
func PostReposHandler(c *gin.Context) {
config := readConfig()
var _addRepoRequest addRepoRequest
c.BindJSON(&_addRepoRequest)
if (_addRepoRequest.RepoType == "git") {
InstallFromGit(_addRepoRequest.URL)
c.JSON(http.StatusOK, config.Repositories)
} else {
c.JSON(http.StatusBadRequest, config.Repositories)
}
}

// Handle Get Request -> Get All Repos
func GetReposHandler(c *gin.Context) {
config := readConfig()
Expand All @@ -81,6 +98,11 @@ func GetRepoMetaHandler(c *gin.Context) {
c.JSON(http.StatusOK, GetMetaInfo(vendor, name))
}

// Handle Get System Information
func GetSystemHandler(c *gin.Context) {
c.JSON(http.StatusOK, getSystemInfo())
}

// Handle Socket Request
func socketHandler(c *gin.Context) {
socketServer.On("connection", func(so socketio.Socket) {
Expand Down Expand Up @@ -144,6 +166,8 @@ func runServer(port string) {
"daemon": "running",
})
})
// System Related Handlers
r.GET("/system", GetSystemHandler)
// Repo Related Routes
r.GET("/repo/meta/:vendor/:name", GetRepoMetaHandler)
r.POST("/repo/running", PostRunningRepoHandler)
Expand Down
13 changes: 1 addition & 12 deletions cli/handler.go
Expand Up @@ -57,21 +57,10 @@ func InstallHandler(c *cli.Context) {
} else {
color.Cyan("Installing to " + localFolder)
}
var repoFolder string
var repo Repository
// Download Codebase
if strings.HasPrefix(remoteURL, "https://github.com") {
repo = CloneFromGit(remoteURL, localFolder)
InstallFromGit(remoteURL)
}
repoFolder = repo.LocalFolder
// Install Dependencies
color.Cyan("Installing Dependencies... please wait patiently")
InstallDependencies(repoFolder)
color.Blue("Generating Runners")
GeneratingRunners(repoFolder)
color.Cyan("Adding to Local Configuration")
config.Repositories = addRepo(config.Repositories, repo)
writeConfig(config)
}

// Handle List
Expand Down
12 changes: 12 additions & 0 deletions cli/repository.go
Expand Up @@ -165,3 +165,15 @@ func GetMetaInfo(Vendor string, Name string) RepositoryMetaInfo {
}
return repositoryMeta
}

// Install Repository from Git
func InstallFromGit(remoteURL string) {
config := readConfig()
var repo Repository
repo = CloneFromGit(remoteURL, config.Local.LocalFolder)
repoFolder := repo.LocalFolder
InstallDependencies(repoFolder)
GeneratingRunners(repoFolder)
config.Repositories = addRepo(config.Repositories, repo)
writeConfig(config)
}
30 changes: 30 additions & 0 deletions cli/system.go
@@ -0,0 +1,30 @@
package main

import (
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/mem"
)

type SystemInfo struct {
CpuName string `json:"cpu"`
Memory uint64 `json:"memory"`
Platform string `json:"platform"`
Os string `json:"os"`
PlatformVersion string `json:"platformVersion"`
}

func getSystemInfo() SystemInfo {
var systemInfo SystemInfo
v, _ := mem.VirtualMemory()
systemInfo.Memory = v.Total
platform, _ := host.Info()
systemInfo.Platform = platform.Platform
systemInfo.PlatformVersion = platform.PlatformVersion
systemInfo.Os = platform.OS

// Handle CPU
cpuInfo, _ := cpu.Info()
systemInfo.CpuName = cpuInfo[0].ModelName
return systemInfo
}

0 comments on commit 9e907a6

Please sign in to comment.