티스토리 뷰

golang

Fiber APP 시작하기

우주개발자42 2023. 11. 9. 00:29

Fiber Basics

파이버는 웹 개발을 위한 API 구축을 돕는 go 패키지.

이 것은 Node.js의 Express Framework에서 영감을 받아 https://github.com/valyala/fasthttp 위에 구축

node.js로 API를 구축한 경험이 있다면, Fiber in Go로 시작하는 것이 더 쉬울 것으로 보임

 

What are we building?

  1. Create a API server to run local
  2. Connect to database (sqlite3)
  3. Send Get request
  4. Send Post request
type Camping struct {
	Id             uint          	  `json:"id"`
	Title          string         	  `json:"title"`
	Address        string       	  `json:"address"`
	Description    string   	  `json:"description"`
	CreatedAt      time.Time 	  `json:"created_at"`
	UpdatedAt      time.Time 	  `json:"updated_at"`
}

 

Creating the first endpoint

Go mod 명령어로 Go 어플리케이션 설정

새로운 폴더를 만들고 Go 프로젝트를 초기화

fiber package 설치

go mod init <repo_name>
go get -u github.com/gofiber/fiber/v2

 

이제 서버를 구동시켜 보자

package main

import "github.com/gofiber/fiber/v2"

func main() {
    app := fiber.New() // 인스턴스 생성

    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, World 👋!")
    })

    app.Listen(":3000")
}

 

http://localhost:3000 으로 접속하면 "Hello, World 👋!" 화면이 뜨면 성공

'golang' 카테고리의 다른 글

[golang] reduce  (0) 2023.11.10
why go-fiber?  (0) 2023.11.08
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/07   »
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 31
글 보관함