mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-04 12:03:43 +02:00
src/server.go: make tcp message function a "real" function instead of a inline one.
This commit is contained in:
parent
ef13af4eb7
commit
a310cb041d
1 changed files with 58 additions and 53 deletions
|
|
@ -109,33 +109,10 @@ func argv_listen_addr() string {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
// main
|
// onTcpMessage callback function
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
func main() {
|
|
||||||
|
|
||||||
// Command line parsing
|
func onTcpMessage(c *tcp_server.Client, args string) {
|
||||||
getopt.FlagLong(&pidFile, "pid", 'p', "Path to pid file", "file")
|
|
||||||
getopt.Parse()
|
|
||||||
|
|
||||||
log.Info("Process is starting with PID: %d", pid.Get())
|
|
||||||
|
|
||||||
if len(pidFile) > 0 {
|
|
||||||
log.Info("Writing pidfile: %s", pidFile)
|
|
||||||
_, err := pid.Save(pidFile)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Failed to write pidfile: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server := tcp_server.New(argv_listen_addr())
|
|
||||||
|
|
||||||
// TCP Client connect.
|
|
||||||
server.OnNewClient(func(c *tcp_server.Client) {
|
|
||||||
//fmt.Println("# Client connected")
|
|
||||||
});
|
|
||||||
|
|
||||||
// TCP Client sends message.
|
|
||||||
server.OnNewMessage(func(c *tcp_server.Client, args string) {
|
|
||||||
params := eosapi.ReqParams{}
|
params := eosapi.ReqParams{}
|
||||||
var block_time int = 10
|
var block_time int = 10
|
||||||
var version string = "v1"
|
var version string = "v1"
|
||||||
|
|
@ -187,8 +164,36 @@ func main() {
|
||||||
// Report status to HAproxy
|
// Report status to HAproxy
|
||||||
c.Send(fmt.Sprintln(status))
|
c.Send(fmt.Sprintln(status))
|
||||||
c.Close()
|
c.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// main
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
// Command line parsing
|
||||||
|
getopt.FlagLong(&pidFile, "pid", 'p', "Path to pid file", "file")
|
||||||
|
getopt.Parse()
|
||||||
|
|
||||||
|
log.Info("Process is starting with PID: %d", pid.Get())
|
||||||
|
|
||||||
|
if len(pidFile) > 0 {
|
||||||
|
log.Info("Writing pidfile: %s", pidFile)
|
||||||
|
_, err := pid.Save(pidFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Failed to write pidfile: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server := tcp_server.New(argv_listen_addr())
|
||||||
|
|
||||||
|
// TCP Client connect.
|
||||||
|
server.OnNewClient(func(c *tcp_server.Client) {
|
||||||
|
//fmt.Println("# Client connected")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TCP Client sends message.
|
||||||
|
server.OnNewMessage(onTcpMessage);
|
||||||
|
|
||||||
// TCP Client disconnect.
|
// TCP Client disconnect.
|
||||||
server.OnClientConnectionClosed(func(c *tcp_server.Client, err error) {
|
server.OnClientConnectionClosed(func(c *tcp_server.Client, err error) {
|
||||||
//fmt.Println("# Client disconnected")
|
//fmt.Println("# Client disconnected")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue