Skip to content

Instantly share code, notes, and snippets.

@iamjjanga-ouo
Last active March 19, 2021 08:28
Show Gist options
  • Save iamjjanga-ouo/9dc3799bb9b38f59656e6289a2d330b8 to your computer and use it in GitHub Desktop.
Save iamjjanga-ouo/9dc3799bb9b38f59656e6289a2d330b8 to your computer and use it in GitHub Desktop.
GoWeb: echo: echo, echo.GET(), echo.Logger
// Golang with Echo - starting Echo
// echo
// - echo는 엄청 큰 struct이다.
// - e := echo 여기서 e는 echo구조체를 가리키는 pointer
// e.GET(path, handleFunc, ...)
// - HandleFunc(context) 현재 request의 context이다. -> interface
// e.Logger.Print() / e.Logger.Fatal()
// Logger defines the logging interface.
// GET:localhost:8080/ -> 200(OK)와 Well, Hello there~! 출력
// GET:localhost:8080/hello -> 404(Not Found)
// POST:localhost:8080/ -> 405(Method not allowed)
package main
import (
"net/http"
"github.com/labstack/echo"
)
func main() {
e := echo.New()
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Well, Hello there~!") // http.StatusOK는 200을 의미
})
// err := e.Start(":8080")
e.Logger.Print("Listening on port 8080")
e.Logger.Fatal(e.Start(":8080"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment