wgconfig

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 3 Imported by: 0

README

wgconfig-go

Test Go Reference

Simple go module that can manipulate Wireguard config files.

Install

go get github.com/pnx/wgconfig-go@latest

Documentation

Documentation can be found over at pkg.go.dev

Author

Henrik Hautakoski - henrik.hautakoski@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Interface Interface
	Peers     Peers
}

func (*Config) AddPeer

func (cfg *Config) AddPeer(p *Peer)

func (*Config) Read

func (cfg *Config) Read(r io.Reader) error

func (*Config) ReadFile

func (cfg *Config) ReadFile(file string) error

func (*Config) Write

func (cfg *Config) Write(w io.Writer) (int64, error)

Write config to file

type Interface

type Interface struct {
	PrivateKey string   `ini:"PrivateKey,omitempty"`
	Address    string   `ini:"Address,omitempty"`
	ListenPort uint     `ini:"ListenPort,omitempty"`
	DNS        []string `ini:"DNS,omitempty"`
	Table      int      `ini:"Table,omitempty"` // Routing table.
	MTU        int      `ini:"MTU,omitempty"`
	PreUp      string   `ini:"PreUp,omitempty"`
	PostUp     string   `ini:"PostUp,omitempty"`
	PreDown    string   `ini:"PreDown,omitempty"`
	PostDown   string   `ini:"PostDown,omitempty"`
}

type Peer

type Peer struct {
	Comment             string `ini:"-"`
	PublicKey           string `ini:"PublicKey,omitempty"`
	AllowedIPs          string `ini:"AllowedIPs,omitempty"`
	Endpoint            string `ini:"Endpoint,omitempty"`
	PersistentKeepalive int    `ini:"PersistentKeepalive,omitempty"`
}

func (Peer) ReflectINIStruct

func (p Peer) ReflectINIStruct(f *ini.File) error

Bit of a hack here. The ini library overwrites sections with the same name when ReflectFrom is used and there is no other way around it (that is known atleast). So, We need to be abit cleaver here and first create a new empty ini.File object and perform ReflectFrom there.

See: https://github.com/go-ini/ini/blob/842b9a946dd3bb45b95001ce6d9ae86f3b3ce921/struct_test.go#L663

type Peers

type Peers []Peer

Slice of peers.

func (*Peers) Add

func (p *Peers) Add(peer *Peer)

Add peers to the list.

func (Peers) ReflectINIStruct

func (peers Peers) ReflectINIStruct(f *ini.File) error

There is a hidden (e.g. not so well documented) "marshal" interface called StructReflector (https://pkg.go.dev/github.com/go-ini/ini#StructReflector) So we can define one for "Peers" (slice of Peer) type here. This way. the ini library is able to marshal our struct.

NOTE: This should really exists in the library already as all this function do is call ReflectINIStruct() on it's elements.

Jump to

Keyboard shortcuts

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