kok202
[2019.03.08] Go lang (서버 제작)

2019. 3. 8. 11:04[공부] 영상/GoLanguage

간단한 웹서버 제작

package main

import "fmt"
import "net/http"

func indexHandler(writer http.ResponseWriter, reader *http.Request) {
    fmt.Fprintf(writer, "<h1>index page</h1>")
}

func aboutHandler(writer http.ResponseWriter, reader *http.Request) {
    fmt.Fprintf(writer, "<h2>about page</h2>")
}

func main() {
    http.HandleFunc("/", indexHandler)
    http.HandleFunc("/index", indexHandler)
    http.HandleFunc("/about", aboutHandler)
    http.ListenAndServe(":8000", nil)
}


http://localhost:8000/

http://localhost:8000/index

http://localhost:8000/about