-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhantomServer.go
More file actions
58 lines (45 loc) · 1.18 KB
/
PhantomServer.go
File metadata and controls
58 lines (45 loc) · 1.18 KB
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
package main
import (
"bufio"
"os"
"runtime"
"strings"
"github.com/SakthiMahendran/PhantomServer/statuslogger"
"github.com/SakthiMahendran/PhantomServer/webserver"
)
// initialize a buffered reader to read input from stdin
var reader = bufio.NewReader(os.Stdin)
// set the GOMAXPROCS to 4 if it's less than 4
func init() {
if runtime.GOMAXPROCS(-1) < 4 {
runtime.GOMAXPROCS(4)
}
}
func main() {
//initialize status logger
sl := statuslogger.NewStatusLogger()
//initialize http server with the status logger
hs := webserver.NewHttpServer(&sl)
//initialize a command executor with the http server and status logger
cmdExe := NewCmdExe(&hs, &sl)
//log that the server is ready to use
sl.LogInfo("Ready to use...")
//loop for reading commands from stdin and executing them
for {
//print a new line
sl.NewLine()
//prompt for user input
os.Stdout.WriteString("Enter your command: ")
cmd := readln()
//execute the command if it's not empty
if cmd != "" {
cmdExe.exe(cmd)
}
}
}
// function to read a line from the buffered reader and return the trimmed string
func readln() string {
line, _ := reader.ReadString('\n')
line = strings.TrimSpace(line)
return line
}