| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
- mutex
 - range
 - tcp
 - FOR
 - c++
 - package
 - Golang
 - window
 - Callback
 - install
 - JavaScript
 - 영화
 - json
 - go언어
 - 책
 - File
 - API
 - windows
 - GO 언어
 - Python
 - go
 - Sync
 - Linux
 - channel
 - bitcoin
 - 리뷰
 - http
 - C
 - Close
 - write
 
- Today
 
- Total
 
목록ListenAndServe (3)
Code Habit
Go언어는 "net/http" 패키지를 통해 편리하게 HTTP서버를 만들 수 있다. func ListenAndServe(addr string, handler Handler) error : 웹 서버를 시작한다. func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) : 경로별로 요청을 처리할 핸들러 함수 등록 type Employee struct { No int Age int Name string } func MakeWebHandler() http.Handler { mux := http.NewServeMux() mux.HandleFunc("/Employee", EmployeeHandler) return mux } func Employ..
앞에서 포스팅한 "net/http" 패키지로 http 서버 구현 후 Get/Post 요청을 구분하여 처리하는 예제이다. 예제 - 서버 // main.go package main import ( "fmt" "io/ioutil" "net/http" ) func handler(rw http.ResponseWriter, req *http.Request) { fmt.Println("Method : ", req.Method) fmt.Println("URL : ", req.URL) fmt.Println("Header : ", req.Header) b, _ := ioutil.ReadAll(req.Body) defer req.Body.Close() fmt.Println("Body : ", string(b)) switch..
golang은 "net/http" 패키지를 통해 간편하게 http 서버를 만들 수 있다. 다음은 서버를 구현하는데 필요한 함수이다. func ListenAndServe(addr string, handler Handler) error : HTTP 연결을 받고, 요청에 응답 func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) : 경로별로 요청을 처리할 핸들러 함수 등록 사용예제 // main.go package main import ( "net/http" ) func main() { http.HandleFunc("/hello", func(res http.ResponseWriter, req *http.Request) { res.Wri..