first commit for loghost

pull/16/head
Richard Liu 7 years ago
parent 8cee77e82e
commit 6a53f6c2b9
  1. 53
      aws-code/loghost/main.go
  2. 3
      benchmark_main.go

@ -0,0 +1,53 @@
package main
import (
"bufio"
"fmt"
"net"
"os"
)
const (
CONN_PORT = "3000"
CONN_TYPE = "tcp"
)
func main() {
// Listen for incoming connections.
l, err := net.Listen(CONN_TYPE, ":"+CONN_PORT)
if err != nil {
fmt.Println("Error listening:", err.Error())
os.Exit(1)
}
// Close the listener when the application closes.
defer l.Close()
fmt.Println("Listening on " + ":" + CONN_PORT)
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
os.Exit(1)
}
// Handle connections in a new goroutine.
go handleRequest(conn)
}
}
// Handles incoming requests.
func handleRequest(conn net.Conn) {
// // Make a buffer to hold incoming data.
// buf := make([]byte, 1024)
// // Read the incoming connection into the buffer.
// reqLen, err := conn.Read(buf)
status, err := bufio.NewReader(conn).ReadString('\n')
if err != nil {
fmt.Println("Error reading:", err.Error())
}
// fmt.Printf("Received %v: %v", reqLen, buf)
fmt.Println(status)
// // Send a response back to person contacting xus.
// conn.Write([]byte("Message received."))
// Close the connection when you're done with it.
conn.Close()
}

@ -87,7 +87,8 @@ func main() {
logFileName := fmt.Sprintf("./%v/%v.log", *logFolder, *port) logFileName := fmt.Sprintf("./%v/%v.log", *logFolder, *port)
h := log.MultiHandler( h := log.MultiHandler(
log.Must.FileHandler(logFileName, log.LogfmtFormat()), log.Must.FileHandler(logFileName, log.LogfmtFormat()),
log.StdoutHandler) log.StdoutHandler,
log.Must.NetHandler("tcp", ":3000", log.JSONFormat()))
// In cases where you just want a stdout logger, use the following one instead. // In cases where you just want a stdout logger, use the following one instead.
// h := log.CallerFileHandler(log.StdoutHandler) // h := log.CallerFileHandler(log.StdoutHandler)
log.Root().SetHandler(h) log.Root().SetHandler(h)

Loading…
Cancel
Save