Skip to content

pnx/wgconfig-go

Repository files navigation

wgconfig-go

Test Go Reference

Simple go module that can manipulate Wireguard config files.

Install

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

Example

package main

import (
    "encoding/json"
    "log"
    "os"
    "strings"

    "github.com/pnx/wgconfig-go"
)

func main() {
    var cfg wgconfig.Config
    r := strings.NewReader(`
        [Interface]
        PrivateKey = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
        Address = 10.10.10.4/32
        DNS = 8.8.4.4
        MTU = 1420

        [Peer]
        PublicKey = YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY=
        PresharedKey = ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ=
        AllowedIPs = 0.0.0.0/0
        Endpoint = example.com:51820
        `)

    err := cfg.Read(r)
    if err != nil {
        log.Fatal(err)
    }

    err = json.NewEncoder(os.Stdout).Encode(cfg)
    if err != nil {
        panic(err)
    }
}

Or reading from from a file directly:

err := cfg.ReadFile("/path/to/file.ini")

Documentation

Documentation can be found over at pkg.go.dev

Author

Henrik Hautakoski - henrik.hautakoski@gmail.com

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages