eeProxy/socks/manager_options.go
2018-12-25 02:52:34 -05:00

52 lines
1,015 B
Go

package tunmanager
import (
"fmt"
"strconv"
)
//Option is a Manager option
type Option func(*Manager) error
//SetHost sets the host of the client's SAM bridge
func SetHost(s string) func(*Manager) error {
return func(c *Manager) error {
c.samhost = s
return nil
}
}
//SetDataDir sets the directory to save per-site keys
func SetDataDir(s string) func(*Manager) error {
return func(c *Manager) error {
c.datadir = s
return nil
}
}
//SetPort sets the port of the client's SAM bridge
func SetPort(v string) func(*Manager) error {
return func(c *Manager) error {
port, err := strconv.Atoi(v)
if err != nil {
return fmt.Errorf("Invalid port; non-number.")
}
if port < 65536 && port > -1 {
c.samport = v
return nil
}
return fmt.Errorf("Invalid port.")
}
}
//SetSAMOpts sets the SAM options
func SetSAMOpts(s []string) func(*Manager) error {
return func(c *Manager) error {
for _, i := range s {
if i != "" {
c.samopts = append(c.samopts, i)
}
}
return nil
}
}