45 lines
888 B
Go
45 lines
888 B
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"strconv"
|
|
"github.com/davecgh/go-spew/spew"
|
|
"code.osinet.fr/fgm/gache/storage"
|
|
)
|
|
|
|
// Listen on all interfaces by default.
|
|
const DEFAULT_HOST = "";
|
|
const DEFAULT_PORT = 11211;
|
|
|
|
func serve(connection net.Conn) {
|
|
fmt.Printf("Handling connection on %s from %s\n", connection.LocalAddr(), connection.RemoteAddr())
|
|
fmt.Fprintln(connection, "Welcome to the echo server!")
|
|
io.Copy(connection, connection)
|
|
}
|
|
|
|
func storer(store storage.Storage) {
|
|
|
|
}
|
|
|
|
func main() {
|
|
var storage storage.Storage = storage.NewNullStorage()
|
|
storer(storage)
|
|
|
|
sock, err := net.Listen("tcp", DEFAULT_HOST + ":" + strconv.Itoa(DEFAULT_PORT))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
addr := sock.Addr()
|
|
spew.Dump(addr)
|
|
fmt.Printf("Beginning to listen on %s\n", addr)
|
|
for {
|
|
conn, err := sock.Accept()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
go serve(conn)
|
|
}
|
|
}
|