Пример #1
0
func Dial(network, addr string) (net.Conn, error) {
	if network != "tcp" {
		panic("only tcp is supported for now")
	}

	host, port, err := net.SplitHostPort(addr)
	if err != nil {
		log.Printf("net.SplitHostPort(%q): %s", addr, err)
		return nil, err
	}

	host, err = lookupHost(host)
	if err != nil {
		log.Printf("lookupHost(%q): %s", host, err)
		return nil, err
	}
	addr = net.JoinHostPort(host, port)

	mDials.WithLabelValues(network).Inc()
	log.Debugf("gophers/net.Dial(%q, %q)", network, addr)
	start := time.Now()
	conn, err := net.DialTimeout(network, addr, config.Default.DialTimeout)
	mDialResults.WithLabelValues(network, errorLabelValue(err)).Inc()
	if err == nil {
		log.Debugf("gophers/net.Dial(%q, %q): connection established (in %s)", network, addr, time.Now().Sub(start))
	} else {
		log.Printf("gophers/net.Dial(%q, %q): %s (in %s)", network, addr, err, time.Now().Sub(start))
	}
	return &Conn{conn}, err
}
Пример #2
0
func extractTestFunctions(scope *types.Scope) []string {
	var tests []string
	for _, name := range scope.Names() {
		if !strings.HasPrefix(name, "Test") {
			continue
		}

		if f, ok := scope.Lookup(name).(*types.Func); ok {
			sig := f.Type().(*types.Signature)

			// basic signature checks
			if sig.Recv() != nil {
				log.Printf("Skipping %q - test function should not be a method", f.String())
				continue
			}
			if sig.Variadic() {
				log.Printf("Skipping %q - test function should not be variadic", f.String())
				continue
			}
			if sig.Results() != nil {
				log.Printf("Skipping %q - test function should not return result", f.String())
				continue
			}

			// check params
			params := sig.Params()
			if params != nil || params.Len() == 1 {
				if named, ok := params.At(0).Type().(*types.Named); ok {
					if named.Obj().Name() == "TestingT" {
						tests = append(tests, f.Name())
						continue
					}
				}
			}

			log.Printf("Skipping %q - test function should have one parameter of type gophers.TestingT", f.String())
		}
	}

	return tests
}
Пример #3
0
func installPackage() {
	// check go env
	if debugF {
		cmd := exec.Command(GoBin, "env")
		b, err := cmd.CombinedOutput()
		log.Printf(strings.Join(cmd.Args, " "))
		log.Printf("\n%s", b)
		if err != nil {
			log.Fatal(err)
		}
	}

	// install package
	args := []string{"install", "-v"}
	cmd := exec.Command(GoBin, args...)
	log.Printf("Running %s", strings.Join(cmd.Args, " "))
	b, err := cmd.CombinedOutput()
	if err != nil {
		log.Printf("%s", b)
		log.Fatal(err)
	}
}
Пример #4
0
func renderTemplate(data *importData, filename string) {
	path := filepath.Join(data.PackageDir, filename)
	f, err := os.Create(path)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	err = mainTemplate.Execute(f, data)
	if err != nil {
		log.Fatal(err)
	}

	args := []string{"-s", "-w", path}
	cmd := exec.Command(GoFmtBin, args...)
	log.Printf("Running %s", strings.Join(cmd.Args, " "))
	b, err := cmd.CombinedOutput()
	if err != nil {
		log.Printf("%s", b)
		log.Fatal(err)
	}

	log.Printf("%s created", path)
}