mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-25 00:11:35 +00:00
Allow setting default config path and AdminListen
at compile time
By providing the following items to `LDFLAGS`: * `-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultConfig=/path/to/config` * '-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultAdminListen=unix://path/to/sock' Closes #818.
This commit is contained in:
parent
0abfe78858
commit
217ac39e77
@ -4,6 +4,9 @@ import "github.com/yggdrasil-network/yggdrasil-go/src/config"
|
|||||||
|
|
||||||
type MulticastInterfaceConfig = config.MulticastInterfaceConfig
|
type MulticastInterfaceConfig = config.MulticastInterfaceConfig
|
||||||
|
|
||||||
|
var defaultConfig = "" // LDFLAGS='-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultConfig=/path/to/config
|
||||||
|
var defaultAdminListen = "" // LDFLAGS='-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultAdminListen=unix://path/to/sock'
|
||||||
|
|
||||||
// Defines which parameters are expected by default for configuration on a
|
// Defines which parameters are expected by default for configuration on a
|
||||||
// specific platform. These values are populated in the relevant defaults_*.go
|
// specific platform. These values are populated in the relevant defaults_*.go
|
||||||
// for the platform being targeted. They must be set.
|
// for the platform being targeted. They must be set.
|
||||||
@ -23,21 +26,34 @@ type platformDefaultParameters struct {
|
|||||||
DefaultIfName string
|
DefaultIfName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDefaults() platformDefaultParameters {
|
||||||
|
defaults := getDefaults()
|
||||||
|
if defaultConfig != "" {
|
||||||
|
defaults.DefaultConfigFile = defaultConfig
|
||||||
|
}
|
||||||
|
if defaultAdminListen != "" {
|
||||||
|
defaults.DefaultAdminListen = defaultAdminListen
|
||||||
|
}
|
||||||
|
return defaults
|
||||||
|
}
|
||||||
|
|
||||||
// Generates default configuration and returns a pointer to the resulting
|
// Generates default configuration and returns a pointer to the resulting
|
||||||
// NodeConfig. This is used when outputting the -genconf parameter and also when
|
// NodeConfig. This is used when outputting the -genconf parameter and also when
|
||||||
// using -autoconf.
|
// using -autoconf.
|
||||||
func GenerateConfig() *config.NodeConfig {
|
func GenerateConfig() *config.NodeConfig {
|
||||||
|
// Get the defaults for the platform.
|
||||||
|
defaults := GetDefaults()
|
||||||
// Create a node configuration and populate it.
|
// Create a node configuration and populate it.
|
||||||
cfg := new(config.NodeConfig)
|
cfg := new(config.NodeConfig)
|
||||||
cfg.NewKeys()
|
cfg.NewKeys()
|
||||||
cfg.Listen = []string{}
|
cfg.Listen = []string{}
|
||||||
cfg.AdminListen = GetDefaults().DefaultAdminListen
|
cfg.AdminListen = defaults.DefaultAdminListen
|
||||||
cfg.Peers = []string{}
|
cfg.Peers = []string{}
|
||||||
cfg.InterfacePeers = map[string][]string{}
|
cfg.InterfacePeers = map[string][]string{}
|
||||||
cfg.AllowedPublicKeys = []string{}
|
cfg.AllowedPublicKeys = []string{}
|
||||||
cfg.MulticastInterfaces = GetDefaults().DefaultMulticastInterfaces
|
cfg.MulticastInterfaces = defaults.DefaultMulticastInterfaces
|
||||||
cfg.IfName = GetDefaults().DefaultIfName
|
cfg.IfName = defaults.DefaultIfName
|
||||||
cfg.IfMTU = GetDefaults().DefaultIfMTU
|
cfg.IfMTU = defaults.DefaultIfMTU
|
||||||
cfg.NodeInfoPrivacy = false
|
cfg.NodeInfoPrivacy = false
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
|
@ -5,7 +5,7 @@ package defaults
|
|||||||
|
|
||||||
// Sane defaults for the macOS/Darwin platform. The "default" options may be
|
// Sane defaults for the macOS/Darwin platform. The "default" options may be
|
||||||
// may be replaced by the running configuration.
|
// may be replaced by the running configuration.
|
||||||
func GetDefaults() platformDefaultParameters {
|
func getDefaults() platformDefaultParameters {
|
||||||
return platformDefaultParameters{
|
return platformDefaultParameters{
|
||||||
// Admin
|
// Admin
|
||||||
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
|
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
|
||||||
|
@ -5,7 +5,7 @@ package defaults
|
|||||||
|
|
||||||
// Sane defaults for the BSD platforms. The "default" options may be
|
// Sane defaults for the BSD platforms. The "default" options may be
|
||||||
// may be replaced by the running configuration.
|
// may be replaced by the running configuration.
|
||||||
func GetDefaults() platformDefaultParameters {
|
func getDefaults() platformDefaultParameters {
|
||||||
return platformDefaultParameters{
|
return platformDefaultParameters{
|
||||||
// Admin
|
// Admin
|
||||||
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
|
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
|
||||||
|
@ -5,7 +5,7 @@ package defaults
|
|||||||
|
|
||||||
// Sane defaults for the Linux platform. The "default" options may be
|
// Sane defaults for the Linux platform. The "default" options may be
|
||||||
// may be replaced by the running configuration.
|
// may be replaced by the running configuration.
|
||||||
func GetDefaults() platformDefaultParameters {
|
func getDefaults() platformDefaultParameters {
|
||||||
return platformDefaultParameters{
|
return platformDefaultParameters{
|
||||||
// Admin
|
// Admin
|
||||||
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
|
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
|
||||||
|
@ -5,7 +5,7 @@ package defaults
|
|||||||
|
|
||||||
// Sane defaults for the BSD platforms. The "default" options may be
|
// Sane defaults for the BSD platforms. The "default" options may be
|
||||||
// may be replaced by the running configuration.
|
// may be replaced by the running configuration.
|
||||||
func GetDefaults() platformDefaultParameters {
|
func getDefaults() platformDefaultParameters {
|
||||||
return platformDefaultParameters{
|
return platformDefaultParameters{
|
||||||
// Admin
|
// Admin
|
||||||
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
|
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
|
||||||
|
@ -5,7 +5,7 @@ package defaults
|
|||||||
|
|
||||||
// Sane defaults for the other platforms. The "default" options may be
|
// Sane defaults for the other platforms. The "default" options may be
|
||||||
// may be replaced by the running configuration.
|
// may be replaced by the running configuration.
|
||||||
func GetDefaults() platformDefaultParameters {
|
func getDefaults() platformDefaultParameters {
|
||||||
return platformDefaultParameters{
|
return platformDefaultParameters{
|
||||||
// Admin
|
// Admin
|
||||||
DefaultAdminListen: "tcp://localhost:9001",
|
DefaultAdminListen: "tcp://localhost:9001",
|
||||||
|
@ -5,7 +5,7 @@ package defaults
|
|||||||
|
|
||||||
// Sane defaults for the Windows platform. The "default" options may be
|
// Sane defaults for the Windows platform. The "default" options may be
|
||||||
// may be replaced by the running configuration.
|
// may be replaced by the running configuration.
|
||||||
func GetDefaults() platformDefaultParameters {
|
func getDefaults() platformDefaultParameters {
|
||||||
return platformDefaultParameters{
|
return platformDefaultParameters{
|
||||||
// Admin
|
// Admin
|
||||||
DefaultAdminListen: "tcp://localhost:9001",
|
DefaultAdminListen: "tcp://localhost:9001",
|
||||||
|
Loading…
Reference in New Issue
Block a user