반응형

 

 

% Tucker의 Go 언어 프로그래밍중 발췌

package main

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

func barHandler(w http.ResponseWriter, r *http.Request) {
values := r.URL.Query()  
name := values.Get("name" 
if name == "" {
name = "World"
}
id, _ := strconv.Atoi(values.Get("id")) 
fmt.Fprintf(w, "Hello %s! id:%d", name, id)
}

func main() {
mux := http.NewServeMux()  
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello World" 
})
mux.HandleFunc("/bar", barHandler)
mux.Handle("/static", http.FileServer(http.Dir("static")))  

http.ListenAndServe(":3000", mux)  
}
반응형

+ Recent posts