-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (52 loc) · 1.48 KB
/
main.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
61
62
63
64
65
66
package main
import (
"github.com/reiver/go-telnet"
"github.com/reiver/go-telnet/telsh"
"log"
"os"
)
var (
host string
port string
shellHandler *telsh.ShellHandler = telsh.NewShellHandler()
version string
)
func main() {
host = os.Getenv("LISTEN_ADDR")
port = os.Getenv("LISTEN_PORT")
version = os.Getenv("PROJECT_VERSION")
log.Printf(" starting bbs-go telnet service (" + version + ")...")
// override defaults
shellHandler.Prompt = "$ "
shellHandler.ExitMessage = "\n\rGoodbye!\n\r"
shellHandler.WelcomeMessage = `
__ __
/ /_ / /_ _____ ____ ____
/ __ \/ __ \/ ___/_____/ __ \/ __ \
/ /_/ / /_/ (__ )_____/ /_/ / /_/ /
/_.___/_.___/____/ \__, /\____/
/____/
savla-dev bbs-go telnet service (` + version + `)
telnet ` + host + ` ` + port + `
`
log.Printf(shellHandler.WelcomeMessage)
// loop over commands from commands.go
for _, cmd := range cmds {
commandProducer := telsh.ProducerFunc(cmd.producer)
shellHandler.Register(cmd.name, telsh.ProducerFunc(commandProducer))
}
helpCommandProducer := telsh.ProducerFunc(helpProducer)
shellHandler.Register("help", telsh.ProducerFunc(helpCommandProducer))
//shellHandler.Register("help", telsh.Help(shellHandler))
// construct a server
server := &telnet.Server{
//Addr: host + ":" + port,
Addr: ":" + port,
Handler: shellHandler,
Logger: logger{},
}
// serve the telnet service
if err := server.ListenAndServe(); nil != err {
panic(err)
}
}