-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.go
60 lines (46 loc) · 1.12 KB
/
methods.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"encoding/json"
"fmt"
ps "github.com/mitchellh/go-ps"
"github.com/StackExchange/wmi"
)
type ProcessList struct {
Id int `json:"id"`
Name string `json:"name"`
}
type OperatingSystem struct {
Name string
}
func getProcessList() interface{} {
response := make([]ProcessList,40)
processList, err := ps.Processes()
if err != nil {
fmt.Println("ps.Processes() Failed, are you using windows?")
return "response"
}
for x := range processList {
var process ps.Process
process = processList[x]
// Push only 40 items in the list
if x <40{
response[x] = ProcessList{Id:process.Pid(), Name:process.Executable()};
}
}
fmt.Println(response)
res, err := json.Marshal(&response)
fmt.Println(string(res))
if err != nil {
fmt.Println(err.Error())
}
return string(res)
}
func getOSinfo () string{
var osInfo []OperatingSystem
err := wmi.Query("Select * from Win32_OperatingSystem", &osInfo)
if err != nil {
fmt.Printf(err.Error())
return err.Error()
}
return (osInfo[0].Name)
}