Go Fiber 패키지로 간단한 HTTP Get요청 API 만들기

 

Fiber 공식 GitHub 링크 : https://github.com/gofiber/fiber

1. go mod 초기화 (위 예제의 패키지 이름은 fiber_http 이다.)

$ go mod init fiber_http



2. fiber 패키지 설치

$ go get -u github.com/gofiber/fiber/v3





3. main.go 작성

package main

import (
  "fmt"
  "log"

  "github.com/gofiber/fiber/v3"
)

func main() {
  fmt.Println("Go Fiber 패키지로 간단한 HTTP Get 요청 API 만들기")

  // Initialize a new Fiber app
  app := fiber.New()

  // Define a route for the GET method on the root path '/'
  app.Get("/", func(c fiber.Ctx) error {
    // Send a string response to the client
    return c.SendString("Hello, World 👋!")
  })

  // Start the server on port 3000
  log.Fatal(app.Listen(":3000"))

}


4. 패키지 실행하기 - 빌드

$ go build


5. 패키지 실행하기 - go exe 파일

$ ./[실행파일]





댓글

이 블로그의 인기 게시물

Lesson 12_1 프로퍼티 노드(Property Node)

DAQ로 전압 측정하기-2

Lesson 12_2 참조를 이용한 프로퍼티노드(Property Node)