func doMain() error { if err := logging.EnableFileLogging(); err != nil { return err } // Schedule cleanup actions handleSignals() addExitFunc(func() { if err := logging.Close(); err != nil { log.Debugf("Error closing log: %v", err) } }) addExitFunc(quitSystray) i18nInit() if showui { if err := configureSystemTray(); err != nil { return err } } // Run below in separate goroutine as config.Init() can potentially block when Lantern runs // for the first time. User can still quit Lantern through systray menu when it happens. go func() { if *proxyAll { // If proxyall flag was supplied, force proxying of all settings.SetProxyAll(true) } listenAddr := *addr if listenAddr == "" { listenAddr = "localhost:8787" } err := flashlight.Run( listenAddr, "localhost:8788", *configdir, *stickyConfig, settings.GetProxyAll, flagsAsMap(), beforeStart, afterStart, onConfigUpdate, exit) if err != nil { exit(err) return } }() return waitForExit() }
func run(configDir string) { err := os.MkdirAll(configDir, 0755) if os.IsExist(err) { log.Errorf("Unable to create configDir at %v: %v", configDir, err) return } flashlight.Run("localhost:0", // listen for HTTP on random address "localhost:0", // listen for SOCKS on random address configDir, // place to store lantern configuration false, // don't make config sticky func() bool { return true }, // proxy all requests make(map[string]interface{}), // no special configuration flags func(cfg *config.Config) bool { return true }, // beforeStart() func(cfg *config.Config) {}, // afterStart() func(cfg *config.Config) {}, // onConfigUpdate func(err error) {}, // onError ) }