1
0

More than 3 years have passed since last update.

Goのnetパッケージを理解する~1日目~

Last updated at Posted at 2020-12-23

12/27更新

Goのnetパッケージを理解する~2日目~書きました

はじめに

Goのパッケージの中でも、苦手意識しかないパッケージの一つであるnetパッケージの勉強をしていきます。

netパッケージとは

netパッケージは、TCP/IP、UDP、ドメイン名解決、UNIXドメインソケットを含むUnixネットワークソケットへのポータブルインタフェースを提供します。

引用:http://golang.jp/pkg/net

とりあえずサーバの起動

main.go
package main

import (
    "fmt"
    "net/http"
)

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

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello World")
}

これで、8080番ポートにアクセスすると、Hello Worldと出力されるはずです

一旦、ここまでで、

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0