add cli for debug
This commit is contained in:
parent
05fb58e438
commit
899b888d82
5 changed files with 61 additions and 36 deletions
44
server/services/cli/cli.go
Normal file
44
server/services/cli/cli.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"recipe-manager/services/logger"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
log_inst = logger.GetInstance()
|
||||
disable_cli = false
|
||||
debug = logger.GetDbgState()
|
||||
)
|
||||
|
||||
func CommandLineListener() {
|
||||
debug = logger.GetDbgState()
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
for !disable_cli {
|
||||
input, _ := reader.ReadString('\n')
|
||||
input = strings.TrimSpace(input)
|
||||
|
||||
switch input {
|
||||
case "debug":
|
||||
logger.EnableDebug(!logger.GetDbgState())
|
||||
debug = logger.GetDbgState()
|
||||
// log_inst.Info("Debug mode enable from cli", zap.Bool("enable", logger.GetDbgState()))
|
||||
case "ctl":
|
||||
if debug {
|
||||
log_inst.Debug("CMD > ", zap.String("CMD", input))
|
||||
}
|
||||
default:
|
||||
if debug {
|
||||
// log_inst.Debug("CMD > ", zap.String("CMD", input))
|
||||
|
||||
// Add functions here!
|
||||
} else {
|
||||
log_inst.Error("INVALID CMD or CMD DISABLED", zap.String("CMD", input))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue