Example #1
0
func main() {
	var err error
	var dumpPath string
	var noHeaders bool
	var printRow_arg printRow_arg
	var channelsNum int

	getopt.StringVar(&dumpPath, 'i', "dump-path")
	getopt.StringVar(&printRow_arg.outputPath, 'o', "output-path").SetOptional()
	getopt.BoolVar(&noHeaders, 'n', "no-headers").SetOptional()
	getopt.IntVar(&channelsNum, 'c', "force-channels-num").SetOptional()
	getopt.BoolVar(&printRow_arg.binaryOutput, 'b', "binary-output").SetOptional()
	getopt.BoolVar(&printRow_arg.insertParseTime, 't', "insert-parse-time").SetOptional()

	getopt.Parse()
	if getopt.NArgs() > 0 || dumpPath == "" {
		getopt.Usage()
		os.Exit(-2)
	}
	switch printRow_arg.outputPath {
	/*		case "":
			now              := time.Now()
			year, month, day := now.Date()
			hour, min,   sec := now.Clock()
			printRow_arg.outputPath = fmt.Sprintf("%v_%v-%02v-%02v_%02v:%02v:%02v.csv", h.DeviceName, year, int(month), day, hour, min, sec)
			break*/
	case "", "-":
		printRow_arg.outputPath = "/dev/stdout"
		printRow_arg.outputFile = os.Stdout
		break
	default:
		printRow_arg.outputFile, err = os.Open(printRow_arg.outputPath)
		panic(fmt.Errorf("Not supported yet"))
	}

	if err != nil {
		fmt.Printf("Cannot open output file: %v", err.Error())
		os.Exit(-1)
	}
	//if (printRow_arg.binaryOutput) {
	//	err = binary.Write(printRow_arg.outputFile, binary.LittleEndian, printRow_arg)
	//}

	err = voltloggerParser.ParseVoltloggerDump(dumpPath, noHeaders, channelsNum, handleHeader, printRow, &printRow_arg)
	if err != nil {
		fmt.Printf("Cannot parse the dump: %v\n", err.Error())
		os.Exit(-1)
	}
	printRow_arg.outputFile.Close()

	fmt.Printf("%v %v\n", dumpPath, printRow_arg)
}
Example #2
0
func main() {
	var (
		debug       bool
		justVersion bool
		c           = proxy.Config{ListenAddr: defaultListenAddr}
	)

	c.Version = version
	getopt.BoolVarLong(&debug, "debug", 'd', "log debugging information")
	getopt.BoolVarLong(&justVersion, "version", 0, "print version and exit")
	getopt.StringVar(&c.ListenAddr, 'H', fmt.Sprintf("address on which to listen (default %s)", defaultListenAddr))
	getopt.BoolVarLong(&c.NoDefaultIPAM, "no-default-ipam", 0, "do not automatically allocate addresses for containers without a WEAVE_CIDR")
	getopt.StringVarLong(&c.TLSConfig.CACert, "tlscacert", 0, "Trust certs signed only by this CA")
	getopt.StringVarLong(&c.TLSConfig.Cert, "tlscert", 0, "Path to TLS certificate file")
	getopt.BoolVarLong(&c.TLSConfig.Enabled, "tls", 0, "Use TLS; implied by --tlsverify")
	getopt.StringVarLong(&c.TLSConfig.Key, "tlskey", 0, "Path to TLS key file")
	getopt.BoolVarLong(&c.TLSConfig.Verify, "tlsverify", 0, "Use TLS and verify the remote")
	getopt.BoolVarLong(&c.WithDNS, "with-dns", 'w', "instruct created containers to always use weaveDNS as their nameserver")
	getopt.BoolVarLong(&c.WithoutDNS, "without-dns", 0, "instruct created containers to never use weaveDNS as their nameserver")
	getopt.Parse()

	if justVersion {
		fmt.Printf("weave proxy %s\n", version)
		os.Exit(0)
	}

	if c.WithDNS && c.WithoutDNS {
		Error.Fatalf("Cannot use both '--with-dns' and '--without-dns' flags")
	}

	if debug {
		InitDefaultLogging(true)
	}

	Info.Println("weave proxy", version)
	Info.Println("Command line arguments:", strings.Join(os.Args[1:], " "))

	protoAddrParts := strings.SplitN(c.ListenAddr, "://", 2)
	if len(protoAddrParts) == 2 {
		if protoAddrParts[0] != "tcp" {
			Error.Fatalf("Invalid protocol format: %q", protoAddrParts[0])
		}
		c.ListenAddr = protoAddrParts[1]
	} else {
		c.ListenAddr = protoAddrParts[0]
	}

	p, err := proxy.NewProxy(c)
	if err != nil {
		Error.Fatalf("Could not start proxy: %s", err)
	}

	if err := p.ListenAndServe(); err != nil {
		Error.Fatalf("Could not listen on %s: %s", p.ListenAddr, err)
	}
}