func main() { kingpin.Version(VERSION) kingpin.CommandLine.VersionFlag.Short('v') kingpin.CommandLine.HelpFlag.Short('h') kingpin.Parse() if !cfg.Server.Enable && localAddr == "" { kingpin.Usage() return } if !cfg.Debug { log.SetOutputLevel(log.Linfo) } else { log.SetOutputLevel(log.Ldebug) } pURL, err := parseURL(localAddr, cfg.Proto) if err != nil { log.Fatal(err) } if cfg.Server.Enable { _, port, _ := net.SplitHostPort(pURL.Host) if port == "" { port = "80" } addr := net.JoinHostPort("0.0.0.0", port) if cfg.Server.Domain == "" { cfg.Server.Domain = "localhost" //cfg.Server.Addr } fmt.Printf("proxylocal: server listen on %v, domain is %v\n", addr, cfg.Server.Domain) ps := pxlocal.NewProxyServer(cfg.Server.Domain) log.Fatal(http.ListenAndServe(addr, ps)) } // var localAddr = flag.Arg(0) // if !regexp.MustCompile("^(http|https|tcp)://").MatchString(localAddr) { // if _, err := strconv.Atoi(localAddr); err == nil { // only contain port // localAddr = "localhost:" + localAddr // } else { // //localAddr += ":80" // } // localAddr = cfg.Proto + "://" + localAddr // } // pURL, err := url.Parse(localAddr) fmt.Println("proxy URL:", pURL) pxlocal.StartAgent(pURL, cfg.SubDomain, cfg.Server.Addr, cfg.ProxyPort, cfg.Data) }
func main() { args := os.Args argc := len(args) log.SetOutputLevel(log.Linfo) log.SetOutput(os.Stdout) if argc > 1 { cmd := "" params := []string{} option := args[1] if option == "-d" { if argc > 2 { cmd = args[2] if argc > 3 { params = args[3:] } } log.SetOutputLevel(log.Ldebug) } else if option == "-v" { cli.Version() return } else if option == "-h" { cli.Help("help") return } else { cmd = args[1] if argc > 2 { params = args[2:] } } if cmd == "" { fmt.Println("Error: no subcommand specified") return } hit := false for cmdName, cliFunc := range supportedCmds { if cmdName == cmd { cliFunc(cmd, params...) hit = true break } } if !hit { fmt.Println(fmt.Sprintf("Error: unknown cmd `%s'", cmd)) } } else { fmt.Println("Use help or help [cmd1 [cmd2 [cmd3 ...]]] to see supported commands.") } }
func InstallAction(c *cli.Context) { if c.Bool("debug") { log.SetOutputLevel(log.Ldebug) } if len(c.Args()) < 1 { log.Fatal("Need at lease one argument") } // log.Println(GOBIN) pkgName := c.Args().First() // TODO: use myname for now if len(strings.Split(pkgName, "/")) == 1 { pkgName = "gobuild-official/" + pkgName } prompt("Repository %v", pkgName) dest, err := downloadSource(pkgName) if err != nil { log.Fatal(err) } err = deployPackage(pkgName, dest, GOBIN) if err != nil { log.Fatal(err) } prompt("Program [%s] installed", pkgName) }
func wrap(f interface{}) func(*cli.Context) { return func(ctx *cli.Context) { if ctx.GlobalBool("debug") { log.SetOutputLevel(log.Ldebug) } sockPath := filepath.Join(GOSUV_HOME, "gosuv.sock") if err := testConnection("unix", sockPath); err != nil { log.Fatal(err) } conn, err := connect(ctx) if err != nil { log.Fatal(err) } defer conn.Close() programClient := pb.NewProgramClient(conn) gosuvClient := pb.NewGoSuvClient(conn) inj := inject.New() inj.Map(programClient) inj.Map(gosuvClient) inj.Map(ctx) inj.Invoke(f) } }
func init() { if len(gitVersion) > 0 { VERSION = VERSION + "/" + gitVersion } log.SetOutputLevel(log.Ldebug) }
func main() { readConfig() log.SetOutputLevel(log.Ldebug) m.Use(macaron.Renderer()) m.Run(*srvPort) }
func init() { cfg := new(config) in, err := ioutil.ReadFile("config.yaml") if err != nil { log.Fatal(err) } err = goyaml.Unmarshal(in, cfg) if err != nil { log.Fatal(err) } flag.Parse() log.SetOutputLevel(log.Ldebug) if *environment == "development" { opts = &cfg.Development } else { opts = &cfg.Production } fmt.Println("== environment:", *environment, "==") utils.Dump(opts) conf.ACCESS_KEY = opts.AccessKey conf.SECRET_KEY = opts.SecretKey // render html templates from templates directory m.Use(render.Renderer(render.Options{ Layout: "layout", })) InitRouter() }
func main() { flag.Parse() log.SetOutputLevel(*flagdebug) configFileName := filepath.Clean(*flagconfig + "/main.conf") log.Debugf("config file '%s'\n", configFileName) log.Printf("Starting %s\n", VERSION) if *cpuprofile != "" { prof, err := os.Create(*cpuprofile) if err != nil { panic(err.Error()) } pprof.StartCPUProfile(prof) defer func() { log.Println("closing file") prof.Close() }() defer func() { log.Println("stopping profile") pprof.StopCPUProfile() }() } go configWatcher(configFileName) terminate := make(chan os.Signal) signal.Notify(terminate, os.Interrupt) <-terminate log.Printf("signal received, stopping") if *memprofile != "" { f, err := os.Create(*memprofile) if err != nil { log.Fatal(err) } pprof.WriteHeapProfile(f) f.Close() } //os.Exit(0) }
func initLog(logLevel int, logFile string) (err error) { log.Info("init log") log.SetOutputLevel(logLevel) var logFp *os.File if logFile == "stdout" { logFp = os.Stdout } else { var openErr error logFp, openErr = os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if openErr != nil { err = openErr return } } log.SetOutput(logFp) return }
func TestCall(t *testing.T) { log.SetOutputLevel(0) for _, c := range g_moduleCases { code, err := py.Compile(c.exp, "", py.FileInput) if err != nil { t.Fatal("Compile failed:", err) } defer code.Decref() mod, err := py.ExecCodeModule(c.name, code.Obj()) if err != nil { t.Fatal("ExecCodeModule failed:", err) } defer mod.Decref() plg, err := New(mod.Obj(), "Plugin") if err != nil { t.Fatal("NewPlugin failed:", errors.Detail(err)) } ret, err := CallMethod(plg, "init", "_stage") if err != nil { t.Fatal("CallMethod failed:", err) } defer ret.Decref() if ret.String() != c.ret { t.Fatal("CallMethod ret:", ret.String(), c.ret) } tbl, _ := plg.GetAttrString("tbl") if tbl.String() != c.tbl { t.Fatal("mod.GetAttrString('tbl') ret:", tbl.String(), c.tbl) } } }
func main() { var serverMode bool var serverAddr string var proxyPort int var proxyAddr string var subDomain string var domain string var debug bool var defaultServerAddr = os.Getenv("PXL_SERVER_ADDR") if defaultServerAddr == "" { defaultServerAddr = "proxylocal.xyz" } flag.BoolVar(&serverMode, "server", false, "run in server mode") flag.StringVar(&serverAddr, "server-addr", defaultServerAddr, "server address") flag.StringVar(&domain, "server-domain", "", "proxy server domain name, optional") flag.StringVar(&subDomain, "subdomain", "", "proxy subdomain, used for http") flag.BoolVar(&debug, "debug", false, "open debug mode") flag.IntVar(&proxyPort, "port", 0, "proxy server listen port, used for tcp") flag.Usage = func() { fmt.Printf("Usage: %s [OPTIONS] <port | host:port>\n", os.Args[0]) flag.PrintDefaults() } flag.Parse() if !serverMode && len(flag.Args()) != 1 { flag.Usage() return } if !debug { log.SetOutputLevel(log.Linfo) } else { log.SetOutputLevel(log.Ldebug) } if serverMode { _, port, _ := net.SplitHostPort(serverAddr) if port == "" { port = "80" } addr := net.JoinHostPort("0.0.0.0", port) if domain == "" { domain = serverAddr } fmt.Println("proxylocal: server listen on", addr) ps := pxlocal.NewProxyServer(domain) log.Fatal(http.ListenAndServe(addr, ps)) } proxyAddr = flag.Arg(0) if !regexp.MustCompile("^(http|https|tcp)://").MatchString(proxyAddr) { if _, err := strconv.Atoi(proxyAddr); err == nil { // only contain port proxyAddr = "localhost:" + proxyAddr } else { //proxyAddr += ":80" } proxyAddr = "http://" + proxyAddr } pURL, err := url.Parse(proxyAddr) if err != nil { log.Fatal(err) } log.Println("proxy URL:", pURL) pxlocal.StartAgent(pURL, subDomain, serverAddr, proxyPort) }
func main() { kingpin.Version(VERSION) kingpin.CommandLine.VersionFlag.Short('v') kingpin.CommandLine.HelpFlag.Short('h') kingpin.Parse() if !cfg.Server.Enable && localAddr == "" { kingpin.Usage() return } if !cfg.Debug { log.SetOutputLevel(log.Linfo) } else { log.SetOutputLevel(log.Ldebug) } pURL, err := pxlocal.ParseURL(localAddr, pxlocal.URLOpts{DefaultScheme: cfg.Proto}) if err != nil { log.Fatal(err) } if cfg.Server.Enable { _, port, _ := net.SplitHostPort(pURL.Host) if port == "" { port = "80" } addr := net.JoinHostPort("0.0.0.0", port) if cfg.Server.Domain == "" { cfg.Server.Domain = "localhost" //cfg.Server.Addr } fmt.Printf("proxylocal: server listen on %v, domain is %v\n", addr, cfg.Server.Domain) ps := pxlocal.NewProxyServer(cfg.Server.Domain) log.Fatal(http.ListenAndServe(addr, ps)) } client := pxlocal.NewClient(cfg.Server.Addr) fmt.Println("proxy URL:", pURL) failCount := 0 for { px, err := client.RunProxy(pxlocal.ProxyOptions{ Proto: pxlocal.ProxyProtocol(cfg.Proto), Subdomain: cfg.SubDomain, LocalAddr: localAddr, ListenPort: cfg.ProxyPort, }) if err == nil { err = px.Wait() } if err == pxlocal.ErrWebsocketBroken { failCount = 0 fmt.Println("Reconnect after 5 seconds ...") time.Sleep(5 * time.Second) continue } if err == pxlocal.ErrDialTCP { if failCount < 13 { failCount += 1 } wait := 7 + failCount fmt.Printf("Reconnect after %d seconds ...\n", wait) time.Sleep(time.Duration(wait) * time.Second) continue } log.Fatal(err) } }
func init() { log.SetOutputLevel(0) }