Moved most of that conditional INI stuff out of the Conf constructor.

This commit is contained in:
idk
2018-08-11 01:16:00 -04:00
parent 6f47089ed7
commit d19b89a383
4 changed files with 45 additions and 19 deletions

View File

@ -501,16 +501,14 @@ func (c *Conf) GetReduceIdleQuantity(arg, def int) int {
return arg
}
// NewI2PTunConf returns a Conf structure from an ini file, for modification
// before starting the tunnel
func NewI2PTunConf(iniFile string) (*Conf, error) {
var err error
var c Conf
c.config = goini.New()
// I2PINILoad loads variables from an ini file into the Conf data structure.
func I2PINILoad(iniFile string, c *Conf) (error) {
var err error
if iniFile != "none" {
c.config = goini.New()
err = c.config.ParseFile(iniFile)
if err != nil {
return nil, err
return err
}
if v, ok := c.config.Get("dir"); ok {
@ -665,9 +663,20 @@ func NewI2PTunConf(iniFile string) (*Conf, error) {
c.AccessList = append(c.AccessList, z)
}
}
return &c, nil
log.Println(c.Print())
}
return nil, nil
return nil
}
// NewI2PTunConf returns a Conf structure from an ini file, for modification
// before starting the tunnel
func NewI2PTunConf(iniFile string) (*Conf, error) {
var err error
var c Conf
if err = I2PINILoad(iniFile, &c); err != nil {
return nil, err
}
return &c, nil
}
// NewSAMForwarderFromConf generates a SAMforwarder from *i2ptunconf.Conf

15
config/tunconf_test.go Normal file
View File

@ -0,0 +1,15 @@
package i2ptunconf
import (
"log"
"testing"
)
func TestConf(t *testing.T) {
log.Println("testing configuration loader")
if config, err := NewI2PTunConf("../etc/sam-forwarder/tunnels.ini"); err != nil {
log.Fatal(err)
}else{
log.Println(config.Print())
}
}