Sobes.tech
Middle+

Milliseid pakette tead Go-s võrgu tööks?

sobes.tech AI

Vastus AI-lt

In Go, the following packages are commonly used for network programming:

  • net — the basic package for network programming, contains types and functions for working with TCP, UDP, IP, etc.
  • net/http — for creating HTTP clients and servers.
  • net/url — for parsing and constructing URLs.
  • net/smtp — for sending emails via SMTP.
  • net/rpc — for implementing remote procedure calls.
  • golang.org/x/net/websocket — for working with WebSocket (external package).

Example of a simple HTTP server:

package main

import (
    "net/http"
    "log"
)

func handler(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Hello, network!"))
}

func main() {
    http.HandleFunc("/", handler)
    log.Fatal(http.ListenAndServe(":8080", nil))
}