728x90
전 회사에서 쓰던 Golang framework Fiber를 공부하려고 한다.
express와 비슷해서 찍먹 수준으로 해봤는데, 조금씩 공부해보려고 한다.
당시 go 버전이 1.12였는데, 지금은 1.17이다.
내가 당시 개발했던 기능이 버전에 큰 영향이 있을 것 같진 않을 것 같다.
먼저 fiber를 다운로드.
go get -u github.com/gofiber/fiber/v2
예전엔 잘됐는데,
cannot find package "github.com/gofiber/fiber/v2" in any of:
c:\go\src\github.com\gofiber\fiber\v2 (from $GOROOT)
C:\Users\Administrator\go\src\github.com\gofiber\fiber\v2 (from $GOPATH)
이런 에러가 발생한다.
그래서 찾아보니,
go mod init github.com/your/repo
먼저 해주고 다시 다운로드하니 잘 됐다.
- go.mode 파일
module fiber
go 1.17
require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/gofiber/fiber/v2 v2.36.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.38.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
)
- main.go 파일
package main
import (
"log"
"github.com/gofiber/fiber/v2"
)
func main() {
app := fiber.New()
app.Get("/ping", func(c *fiber.Ctx) error {
return c.SendString("Pingpong by fiber\n")
})
log.Fatal(app.Listen(":3000"))
}
- F5로 실행하면(vscode)
잘된다.
브라우저를 실행하여 localhost:3000/ping에 접속하면
Pingpong by fiber 라는 문구가 뜬다.
728x90
'개발 > Go' 카테고리의 다른 글
[Fiber] Fiber 기본 (0) | 2022.11.04 |
---|---|
[Fiber] Go로 DB Connect하기(MariaDB) (0) | 2022.08.13 |
[Go] 기초 - 채널 (0) | 2022.08.04 |
[Go] 기초 - 루틴(goroutine) (0) | 2022.08.02 |
[Go] 기초 - defer&panic (0) | 2022.08.01 |