go_network_listener

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

README

go-network-listener

A simple network listener for Go.

package main

import (
	go_network_listener "github.com/jc-lab/go-network-listener"
	"log"
	"os"
	"os/signal"
	"syscall"
)

func main() {
	listener, err := go_network_listener.NewListener(nil)
	if err != nil {
		log.Fatalf("new failed: %+v", err)
	}

	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

	go func() {
		_ = <-sigs
		log.Printf("CLOSE")
		listener.Close()
	}()

	for {
		event, ok := <-listener.Chan()
		if !ok {
			break
		}
		log.Printf("EVENT: %+v", event)
	}
}

License

Apache 2.0 License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfSpec

type AfSpec int
const (
	AfUnspecific AfSpec = 0
	AfInet4      AfSpec = 1
	AfInet6      AfSpec = 2
)

type Event

type Event struct {
	Type EventType
}

type EventType

type EventType int
const (
	EventTypeAdd EventType = iota
	EventTypeRemove
	EventTypeModify
)

type Listener

type Listener interface {
	io.Closer
	Chan() chan *Event
}

func NewListener

func NewListener(options *Options) (Listener, error)

type Options

type Options struct {
	AfSpec AfSpec
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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