Add StartConfig.Listener so server with custom Listener is easier to create by aldas · Pull Request #2920 · labstack/echo · GitHub
Skip to content

Add StartConfig.Listener so server with custom Listener is easier to create#2920

Merged
aldas merged 1 commit into
labstack:masterfrom
aldas:start_config_listener
Mar 19, 2026
Merged

Add StartConfig.Listener so server with custom Listener is easier to create#2920
aldas merged 1 commit into
labstack:masterfrom
aldas:start_config_listener

Conversation

@aldas

@aldas aldas commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Add StartConfig.Listener so server with custom Listener is easier to create

relates to #2918 (comment)
#1942

Example:

package main

import (
	"context"
	"net"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/labstack/echo/v5"
)

func main() {
	e := echo.New()

	ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
	defer cancel()

	lc := net.ListenConfig{
		KeepAlive: 15 * time.Second,
		//Control:   nil,
		//KeepAliveConfig: net.KeepAliveConfig{
		//	Enable:   false,
		//	Idle:     0,
		//	Interval: 0,
		//	Count:    0,
		//},
	}
	l, err := lc.Listen(ctx, "tcp", ":8080")
	if err != nil {
		e.Logger.Error("failed to create listener", "error", err)
		return
	}
	defer l.Close()

	sc := echo.StartConfig{
		Listener: l,
	}
	if err := sc.Start(ctx, e); err != nil {
		e.Logger.Error("failed to run server", "error", err)
	}
}

@codecov

codecov Bot commented Mar 19, 2026

Copy link
Copy Markdown

@aldas aldas merged commit 675712d into labstack:master Mar 19, 2026
10 checks passed
@aldas aldas deleted the start_config_listener branch March 19, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant