Goã§ãµã¼ãã¼å®è£ ã®ãã¿ã¼ã³
Goè¨èªããããããã
Goã§ã®ãµã¼ãã¼å®è£
ã®æ¹æ³ããããç¨åº¦ãã¿ã¼ã³åãã¦ãã®ã§è¦ãã¦ãããã
ããã§è¨ããµã¼ãã¼ã¯ã¨ã³ã¼ãµã¼ãã¼ãmemcachedã¿ãããªãã¤ãã¹
package main import ( "net"; "fmt"; ) func handler(conn net.Conn) { defer conn.Close(); // 4 buf := make([]byte, 16); l, err := conn.Read(buf); if err == nil { conn.Write(buf[0:l]); } } func main() { sock, err := net.Listen("tcp", "127.0.0.1:1983"); if err != nil { fmt.Printf("error %s", err); return; } // 1 for { // 2 conn, err := sock.Accept(); if err != nil { fmt.Printf("error %s", err); return; } // 3 go handler(conn); } }
1ã§ã«ã¼ããã2ã§Acceptãããã¦3ã§ã³ãã¯ã·ã§ã³ãgoroutineã§åãããhandlerã«æ¸¡ãã
æå¾ã«ãã¸ãã¯ã4ã«æ¸ãã°åºæ¥ä¸ããã
ã¯ã©ã¤ã¢ã³ããåãããã«ããããã ãªã¼ãã®ãããªã¼
åè
GitHub - dustin/gomemcached: A memcached binary protocol toolkit for go.