MBP(はてな)

MacBook Pro,iPhone Xs,React

Go言語でWebサーバー

$ vi web.go
// +build ignore

package main

import (
"fmt"
"log"
"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

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

$ go run web.go

safarihttp://localhost:8080/monkeys を開く

Writing Web Applications - The Go Programming Language

Go言語(net/http)でWebサーバーを作成(1) - Qiita

Goでwebサーバーを立てる3ステップ - Qiita