Browse Source

wireguard: add support for optional Name comment

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head
Alejandro Mery 1 year ago
parent
commit
3b43e0c9ea
  1. 6
      pkg/wireguard/config.go

6
pkg/wireguard/config.go

@ -23,12 +23,16 @@ var configTemplate = template.Must(template.New("config").Funcs(template.FuncMap
return strings.Join(s, sep)
},
}).Parse(`[Interface]
{{if .Interface.Name}}# Name: {{.Interface.Name}}
{{end -}}
Address = {{.Interface.Address}}
PrivateKey = {{.Interface.PrivateKey}}
ListenPort = {{.Interface.ListenPort}}
{{- range .Peer }}
[Peer]
{{if .Name}}# Name: {{.Name}}
{{end -}}
PublicKey = {{.PublicKey}}
Endpoint = {{.Endpoint}}
AllowedIPs = {{ PrefixJoin .AllowedIPs ", "}}
@ -64,6 +68,7 @@ func (f *Config) WriteTo(w io.Writer) (int64, error) {
// InterfaceConfig represents the [Interface] section
type InterfaceConfig struct {
Name string
Address netip.Addr
PrivateKey PrivateKey
ListenPort uint16
@ -71,6 +76,7 @@ type InterfaceConfig struct {
// PeerConfig represents a [Peer] section
type PeerConfig struct {
Name string
PublicKey PublicKey
Endpoint EndpointAddress
AllowedIPs []netip.Prefix

Loading…
Cancel
Save