Golang ile Gemini Servisi Yazma Rehberi
Golang kullanarak Gemini protokolü ile çalışan basit bir servis kodu örneği ve yapılandırması hakkında detaylı bilgi ve örnek kod.
Soru 1
Kullanıcı
golang ile gemini ile ilgili bir servis kodu yaz
YZ Asistanı
go package main
import ( "bufio" "fmt" "net" "os" )
func handleConnection(conn net.Conn) { defer conn.Close()
scanner := bufio.NewScanner(conn)
if scanner.Scan() {
request := scanner.Text()
fmt.Printf(\"Received request: %s\n\", request)
response := \"20 text/gemini\n# Welcome to Gemini Server\nThis is a simple Gemini server written in Go.\"
conn.Write([]byte(response))
}
}
func main() { ln, err := net.Listen("tcp", ":1965") if err != nil { fmt.Fprintf(os.Stderr, "Error starting server: %v\n", err) os.Exit(1) } defer ln.Close()
fmt.Println(\"Gemini server is running on port 1965\")
for {
conn, err := ln.Accept()
if err != nil {
fmt.Fprintf(os.Stderr, \"Error accepting connection: %v\n\", err)
continue
}
go handleConnection(conn)
}
}
