lansrv

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 13 Imported by: 0

README

LanSrv

This is a simple wrapper for zeroconf. There are two major functions:

  • running an mDNS server that advertises all local services
    • Example: $ lansrv -dir /etc/systemd/system # scans systemd service files
  • a scanning tool to find all services on the local network.
    • Example: $ lansrv -scan

Why?

I wanted a way to automatically cluster NATS so each service in my home automation system just has to communicate with the local NATS instance. With LanSrv I just need to add the following section to the systemd service file that defines the NATS service:

[LanSrv]
Name=nats-node
Port=4222
Protocol=nats

Other nodes that want to cluster can then be run with the following command:

lansrv -scan -service nats-node | xargs nats-server -routes

Documentation

Overview

Package lansrv: These functions are built to work with systemd.

Index

Constants

View Source
const (
	Protocol  LanAdFormatPart = marker + "pro" + marker
	Address                   = marker + "addr" + marker
	Port                      = marker + "port" + marker
	Path                      = marker + "path" + marker
	AdService                 = marker + "svc" + marker
)

Variables

View Source
var Service = "LanSrv"

Functions

func GatherServiceConfigs

func GatherServiceConfigs(dir string) (configFiles []string)

GatherServiceConfigs accepts @arg dir which it will walk recusively and collect an array of file names that contain a lansrv config. Lansrv is built to work with systemd so any file ending with `.service` will be included in the array.

func ServicesLookup

func ServicesLookup(ctx context.Context, localhost bool) (map[string][]LanAd, error)

ServicesLookup returns a map containing hostnames along with a list of LanAds published on that host.

func StartMdnsServer

func StartMdnsServer(ads []LanAd, port int) (*zeroconf.Server, error)

Types

type Broadcast added in v1.2.0

type Broadcast struct {
	Name string
}

type Discover added in v1.2.0

type Discover struct {
	Localhost bool
	Timeout   time.Duration
}

type LanAd

type LanAd struct {
	Service  string
	Address  net.IP `json:"-"`
	Port     int
	Path     string
	Protocol string
}

func ParseServiceFiles

func ParseServiceFiles(configFiles []string) []LanAd

ParseServiceConfigs takes @arg configs (list of filenames), tries to parse them as ini files and returns all non-nil results for lansrv configurations containing at least a Name and a Port.

func (*LanAd) EqualTo added in v1.0.1

func (ad *LanAd) EqualTo(other *LanAd) bool

func (*LanAd) FromMap

func (ad *LanAd) FromMap(adMap map[string]string) error

func (*LanAd) FromString

func (ad *LanAd) FromString(adStr string)

FromString takes a string formatted {{protocol}}://{{service name}}:{{port}}/{{path}}

func (*LanAd) ToFormattedString added in v1.1.0

func (ad *LanAd) ToFormattedString(format string) string

type LanAdFormatPart added in v1.1.0

type LanAdFormatPart = string

type LanAdsDiscovery added in v1.2.0

type LanAdsDiscovery struct {
	Ads map[string][]LanAd
	Err error
}

type ZeroConfActor added in v1.2.0

type ZeroConfActor struct {
	Ads []LanAd
	// contains filtered or unexported fields
}

func (*ZeroConfActor) Receive added in v1.2.0

func (state *ZeroConfActor) Receive(actorCtx actor.Context)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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