echoweb

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package echoweb hosts the first adapter from github.com/goforj/web to Echo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnwrapContext

func UnwrapContext(ctx web.Context) (*echo.Context, bool)

UnwrapContext returns the underlying Echo context when the web.Context came from this adapter. @group Adapter Example: adapter := echoweb.New()

adapter.Router().GET("/healthz", func(c web.Context) error {
	_, ok := echoweb.UnwrapContext(c)
	fmt.Println(ok)
	return c.NoContent(http.StatusOK)
})

rr := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "/healthz", nil) adapter.ServeHTTP(rr, req)

// true

func UnwrapWebSocketConn

func UnwrapWebSocketConn(conn web.WebSocketConn) (*websocket.Conn, bool)

UnwrapWebSocketConn returns the underlying gorilla websocket connection. @group Adapter Example: _, ok := echoweb.UnwrapWebSocketConn(nil) fmt.Println(ok)

// false

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter owns an Echo engine while exposing the app-facing web.Router contract.

func New

func New() *Adapter

New creates a new Echo-backed web adapter. @group Adapter Example: adapter := echoweb.New() fmt.Println(adapter.Router() != nil, adapter.Echo() != nil)

// true true

func Wrap

func Wrap(engine *echo.Echo) *Adapter

Wrap exposes an existing Echo engine through the web.Router contract. @group Adapter Example: adapter := echoweb.Wrap(nil) fmt.Println(adapter.Echo() != nil)

// true

func (*Adapter) Echo

func (a *Adapter) Echo() *echo.Echo

Echo returns the underlying Echo engine. @group Adapter Example: adapter := echoweb.New() fmt.Println(adapter.Echo() != nil)

// true

func (*Adapter) Router

func (a *Adapter) Router() web.Router

Router returns the app-facing router contract. @group Adapter Example: adapter := echoweb.New() fmt.Println(adapter.Router() != nil)

// true

func (*Adapter) ServeHTTP

func (a *Adapter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP exposes the adapter as a standard http.Handler. @group Adapter Example: adapter := echoweb.New() adapter.Router().GET("/healthz", func(c web.Context) error { return c.NoContent(http.StatusOK) }) rr := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "/healthz", nil) adapter.ServeHTTP(rr, req) fmt.Println(rr.Code)

// 204

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server owns adapter bootstrap plus HTTP lifecycle management.

func NewServer

func NewServer(config ServerConfig) (*Server, error)

NewServer creates an Echo-backed server from web route groups and mounts. @group Adapter Example:

server, err := echoweb.NewServer(echoweb.ServerConfig{
	RouteGroups: []web.RouteGroup{
		web.NewRouteGroup("/api", []web.Route{
			web.NewRoute(http.MethodGet, "/healthz", func(c web.Context) error { return c.NoContent(http.StatusOK) }),
		}),
	},
})

fmt.Println(err == nil, server.Router() != nil)

// true true

func (*Server) Router

func (s *Server) Router() web.Router

Router exposes the app-facing router contract. @group Adapter Example: server, _ := echoweb.NewServer(echoweb.ServerConfig{}) fmt.Println(server.Router() != nil)

// true

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve starts the server and gracefully shuts it down when ctx is cancelled. @group Adapter Example: server, _ := echoweb.NewServer(echoweb.ServerConfig{Addr: "127.0.0.1:0"}) ctx, cancel := context.WithCancel(context.Background()) cancel() fmt.Println(server.Serve(ctx) == nil)

// true

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP exposes the server as an http.Handler for tests and local probing. @group Adapter Example:

server, _ := echoweb.NewServer(echoweb.ServerConfig{
	RouteGroups: []web.RouteGroup{
		web.NewRouteGroup("/api", []web.Route{
			web.NewRoute(http.MethodGet, "/healthz", func(c web.Context) error { return c.NoContent(http.StatusOK) }),
		}),
	},
})

rr := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "/api/healthz", nil) server.ServeHTTP(rr, req) fmt.Println(rr.Code)

// 204

type ServerConfig

type ServerConfig struct {
	Addr            string
	RouteGroups     []web.RouteGroup
	Mounts          []web.RouterMount
	ShutdownTimeout time.Duration
}

ServerConfig configures an Echo-backed web server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL