4. Package net
• Package net provides a portable interface for
network I/O, including TCP/IP, UDP, domain name
resolution, and Unix domain sockets.
• 比較的低レイヤーの通信を実現
物理層
データリンク層
ネットワーク層 (IP)
トランスポート層(TCP/UDP)
アプリケーション層 (HTTP)
12. http server
• type Server
type Server struct {
Addr string
Handler Handler
ReadTimeout time.Duration
WriteTimeout time.Duration
MaxHeaderBytes int
TLSConfig *tls.Confis
}
13. http server
func ListenAndServe(addr string, handler Handler) error
– 指定したアドレス、ハンドラーを使用してサーバー
を起動
type Handler interface {
ServeHTTP(ResponseWriter, *Request)
}
14. http server demo
type AppHandler struct {
}
func(index *AppHandler) ServeHTTP(w
http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, »hello world »)
}
func main() {
index := new(AppHandler)
http.ListenAndServe(":8080", index)
}
22. type url
type URL struct {
Scheme string
Opaque string // encoded opaque data
User *Userinfo // username and password information
Host string // host or host:port
Path string
RawQuery string // encoded query values, without '?'
Fragment string // fragment for references, without '#'
}
scheme://[userinfo@]host/path[?query][#fragment]