merge_listener_wrapper

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 8 Imported by: 0

README

Caddy Merge Listener Wrapper

Overview

The Caddy Merge Listener Wrapper is a module for the Caddy server that allows merging multiple network listeners. It provides the functionality to aggregate connections from multiple sources into a single listener.

Features

  • Multiple Listener Support: Merge multiple net.Listener instances into a single listener.
  • Flexible Configuration: Supports dynamic configuration of listeners via JSON and Caddyfile.

Getting Started

Prerequisites

Ensure you have Go installed on your system.

Installation

To install the Caddy Merge Listener Wrapper, you will need to build a custom Caddy binary that includes this module. This can be achieved using the xcaddy utility:

  1. Install xcaddy:

    go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
    
  2. Build Caddy with the Merge Listener Wrapper:

    xcaddy build --with github.com/point-c/caddy/module/merge-listener-wrapper
    
  3. Run Your Custom Caddy Build:

    ./caddy run
    
Configuration
JSON Configuration

Edit your Caddy JSON configuration to include the Merge Listener Wrapper. Here's a snippet to get you started:

{
    // Other Caddy configurations...
    "apps": {
        "http": {
            "servers": {
                "example": {
                    "listener_wrappers": [
                        {
                            "wrapper": "multi",
                            "listeners": [
                            	{
                            		"listener": "<listener>",
                            		// ...
                            	},
                               {"wrapper":  "tls"}
                               // ...
                            ]
                        }
                    ]
                    // Other server configurations...
                }
            }
        }
    }
}
Caddyfile Configuration

In your Caddyfile, you can use the Merge Listener Wrapper as follows:

# Caddyfile configuration...
{
    servers :443 {
    	listener_wrappers {
    		multi {
			   <submodule name> <submodule config>
    		}
    		# Important! `tls` must be defined and the last wrapper in the list
    		tls
    	}
    }
}

# Server configuration...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListenerProvider

type ListenerProvider lifecycler.LifeCyclable[func(net.Listener)]

ListenerProvider is implemented by modules in the "caddy.listeners.merge" namespace.

type MergeWrapper

type MergeWrapper struct {
	// ListenerRaw is a slice of JSON-encoded data representing listener configurations.
	// These configurations are used to create the actual net.Listener instances.
	// Listeners should implement [net.Listener] and be in the 'caddy.listeners.merge.listeners' namespace.
	ListenerRaw []json.RawMessage `json:"listeners" caddy:"namespace=caddy.listeners.merge inline_key=listener"`
	// contains filtered or unexported fields
}

MergeWrapper loads multiple [net.Listener]s and aggregates their [net.Conn]s into a single net.Listener. It allows caddy to accept connections from multiple sources.

func (*MergeWrapper) CaddyModule

func (p *MergeWrapper) CaddyModule() caddy.ModuleInfo

CaddyModule implements caddy.Module.

func (*MergeWrapper) Cleanup

func (p *MergeWrapper) Cleanup() (err error)

Cleanup implements caddy.CleanerUpper. All wrapped listeners are closed and the struct is cleared.

func (*MergeWrapper) Provision

func (p *MergeWrapper) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner. It loads the listeners from their configs and asserts them to net.Listener. Any failed assertions will cause a panic.

func (*MergeWrapper) UnmarshalCaddyfile

func (p *MergeWrapper) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler. Must have at least one listener to aggregate with the wrapped listener. `tls` should come specifically after any `merge` directives.

```

 http caddyfile:
	{
	  servers :443 {
	    listener_wrappers {
	      merge {
	        <submodule name> <submodule config>
	      }
	      tls
	    }
	  }
	}

```

func (*MergeWrapper) WrapListener

func (p *MergeWrapper) WrapListener(ls net.Listener) net.Listener

WrapListener implements caddy.ListenerWrapper. The listener passed in is closed by MergeWrapper during cleanup.

Jump to

Keyboard shortcuts

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