Labstack/echo: Difference between revisions
Jump to navigation
Jump to search
Line 13: | Line 13: | ||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
go get github.com/labstack/echo/v4@v4.11.4 | go get github.com/labstack/echo/v4@v4.11.4 | ||
</syntaxhighlight> | |||
=Server= | |||
<syntaxhighlight lang='go'> | |||
package main | |||
import ( | |||
"net/http" | |||
"github.com/labstack/echo/v4" | |||
"github.com/labstack/echo/v4/middleware" | |||
) | |||
func hello(c echo.Context) error { | |||
return c.String(http.StatusOK, "hello!") | |||
} | |||
func main() { | |||
s := echo.New() | |||
// Middleware | |||
s.Use(middleware.Logger()) | |||
s.Use(middleware.Recover()) | |||
// Routes | |||
s.GET("/", hello) | |||
// Start server | |||
s.Logger.Fatal(s.Start(":30000")) | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=Registering Handlers Generated by oapi-codegen from an OpenAPI Specification= | =Registering Handlers Generated by oapi-codegen from an OpenAPI Specification= |
Revision as of 20:51, 26 January 2024
External
Internal
Overview
Install Dependencies
From the root directory of your module, execute:
go get github.com/labstack/echo/v4@v4.11.4
Server
package main
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func hello(c echo.Context) error {
return c.String(http.StatusOK, "hello!")
}
func main() {
s := echo.New()
// Middleware
s.Use(middleware.Logger())
s.Use(middleware.Recover())
// Routes
s.GET("/", hello)
// Start server
s.Logger.Fatal(s.Start(":30000"))
}