haruprojectの日記(技術モノ)

日々の技術的な取り組みアウトプット用

go言語でnet/httpでWEBサーバをたてる

続き。

routetest.go

package main

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

func hello(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello World!")
}

func main() {
	http.HandleFunc("/", hello)
	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
$ go run routetest.go

http://localhost:9090/helloでアクセス

f:id:haruproject:20160215210754p:plain

終わり。

haruproject.hateblo.jp
haruproject.hateblo.jp