Golang

Golang debug console 문제

느리지만 꾸준하게 2021. 12. 16. 11:23

Golang으로 api 만들기 실습 진행중 디버그 콘솔창에 문제가 생김

코드는 아래와 같다.

package main

import (
	"fmt"
	"net/http"
)

type fooHandler struct{}

func (f *fooHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "Hello Foo!")
}

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprint(w, "Hello World")
	})

	http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello Bar!")
	})

	http.Handle("/foo", &fooHandler{})

	http.ListenAndServe(":3000", nil)
}

위 코드에서 HandleFunc는 Go http 패키지가 동작하는 방식, Go htpp 패키지를 사용해서  웹서버를 만들려면 HandleFunc 형태로 사용하면 된다.

 

코드를 실행하니 아래와 같이 진행되면서 localhost 쪽에 잘못된 응답이 전송되었다고 나옴.

해결중,,,,

Starting: C:\Users\kjh\go\bin\dlv-dap.exe dap --check-go-version=false --listen=127.0.0.1:63634 from c:\Users\kjh\go\src\web1
DAP server listening at: 127.0.0.1:63634
Type 'dlv help' for list of commands.
Process 4540 has exited with status 0
Detaching
dlv dap (18064) exited with code: 0
페이지가 작동하지 않습니다.
localhost에서 잘못된 응답을 전송했습니다.
ERR_INVALID_HTTP_RESPONSE

 

https://grepper.tistory.com/39

 

Go 언어 - [6장] (웹 어플리케이션 작성)

※ 디스커버리 Go 언어 라는 책 내용을 전반적으로 다루지만 책 리뷰보다는 좀 더 간단하게 정리해보겠습니다. 6. 웹 어플리케이션 작성 이번 장에서는 간단한 웹 앱을 만들어보겠습니다. 6.1 Hello

grepper.tistory.com

이 블로그에서 참고해서 8080 localhost에 hello world를 출력하는 것은 가능한데,,,

 

 

 

 

 

이유를 알아냈다. reactnodebird에서 사용한 mysql port 3000번이랑 충돌이 생겨서 그렇다...

하..

 

 

 

 

 

<출처  Tucker Programming: Go로 만드는 웹>

https://www.youtube.com/watch?v=vOW0j6hd-Rg&list=PLy-g2fnSzUTDALoERcKDniql16SAaQYHF&index=2 

 

 

 

 

'Golang' 카테고리의 다른 글

Maps & Structs  (0) 2021.12.12
Arrays & Slices  (0) 2021.12.12
Pointers  (0) 2021.12.12
if & switch  (0) 2021.12.12
for&range&args  (0) 2021.12.12