dev/개인 프로젝트

golang - gin - backend 개발 (1)

jeongsu 2022. 1. 12. 17:08

다른 블로그를 보면서 여차저차 golang 과 vscode 환경구축을 완료했다.

 

그리고 gin이라는 golang framework를 사용해서 backend를 구축하려고 한다.

 

우선 gin tutorial https://github.com/gin-gonic/gin

 

GitHub - gin-gonic/gin: Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better perf

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin. - ...

github.com

를 그대로 따라해본다.

 

 

go get -u github.com/gin-gonic/gin

위의 명령어를 치면

src 아래에 download

이게 gopath 의 환경변수를 잘 해줘야지 저기서 다운로드를 받는다. 나도 이것때문에 좀 시간이 걸렸다.

우여곡절끝에 성공했고,

go run .\src\hello.go

 

위 명령어를 치면 웹 서버가 가동된다.

단순하게 localhost:8080/ping 이라는 url에 접속하면 json 형식의 pong이라는 값을 전달해주는 로직이다.