本文整理汇总了Golang中fmt.Printf函数的典型用法代码示例。如果您正苦于以下问题:Golang Printf函数的具体用法?Golang Printf怎么用?Golang Printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了Printf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: processAmqp

// Process messages from the AMQP queues
func processAmqp(username, amqpAddress string) {

    // Open the queue and then begin processing messages
    // If we drop out of the processing function, wait
    // a little while and try again
    for {
        fmt.Printf("######################################################################################################\n")
        fmt.Printf("UTM-API service (%s) REST interface opening %s...\n", globals.LogTag, amqpAddress)

        q, err := OpenQueue(username, amqpAddress)

        if err == nil {
            defer q.Close()

            fmt.Printf("%s [server] --> connection opened.\n", globals.LogTag)

            downlinkMessages = q.Downlink

            // The meat is in here
            processDatagrams(q)

        } else {
            globals.Dbg.PrintfTrace("%s [server] --> error opening AMQP queue (%s).\n", globals.LogTag, err.Error())
        }

        amqpRetryCount++
        globals.Dbg.PrintfTrace("%s [server] --> waiting before trying again...\n", globals.LogTag)
        time.Sleep(time.Second * 10)
    }
}

开发者ID:mmanjoura,项目名称:utm,代码行数:31,代码来源:server.go

示例2: handlePacket

func handlePacket(buffer []byte) {
    parser := rfc5424.NewParser(buffer)
    err := parser.Parse()

    if err != nil {
        fmt.Printf("Error reading syslog message %s", err)
        return
    }

    log := parser.Dump()
    log["@timestamp"] = log["timestamp"]
    log["facility_label"] = FACILITY_LABELS[(log["facility"]).(int)]
    log["severity_label"] = SEVERITY_LABELS[(log["severity"]).(int)]
    log["type"] = "syslog"

    now := time.Now()
    index := "logstash-" + now.Format("2006.01.02")

    _, err = elasticSearch.Index(true, index, "logs", "", log)
    if err != nil {
        fmt.Printf("Error indexing message %s", err)
        return
    }
    fmt.Println("Logged")
}

开发者ID:postfix,项目名称:logflume,代码行数:25,代码来源:logflume.go

示例3: main

func main() {
    n := 0
    if len(os.Args) > 1 {
        n, _ = strconv.Atoi(os.Args[1])
    }
    minDepth := 4
    maxDepth := minDepth + 2
    if maxDepth < n {
        maxDepth = n
    }
    stretchDepth := maxDepth + 1

    check := create(0, stretchDepth).Check()
    fmt.Printf("stretch tree of depth %d\t check: %d\n", stretchDepth, check)

    longLivedTree := create(0, maxDepth)

    for depth := minDepth; depth <= maxDepth; depth += 2 {
        iterations := 1 << uint(maxDepth-depth+minDepth)
        check = 0

        for i := 1; i <= iterations; i++ {
            check += create(i, depth).Check()
            check += create(-i, depth).Check()
        }
        fmt.Printf("%d\t trees of depth %d\t check: %d\n", 2*iterations, depth, check)
    }

    fmt.Printf("long lived tree of depth %d\t check: %d\n", maxDepth, longLivedTree.Check())
}

开发者ID:MasayukiNagamachi,项目名称:naive-bench,代码行数:30,代码来源:binarytrees.go

示例4: TestCalibrateThreshold

func TestCalibrateThreshold(t *testing.T) {
    if !*calibrate {
        t.Log("not calibrating, use -calibrate to do so.")
        return
    }

    lower := int(1e3)   // math/big is faster at this size.
    upper := int(300e3) // FFT is faster at this size.

    big, fft := measureMul(lower)
    lowerX := float64(big) / float64(fft)
    fmt.Printf("speedup at size %d: %.2f\n", lower, lowerX)
    big, fft = measureMul(upper)
    upperX := float64(big) / float64(fft)
    fmt.Printf("speedup at size %d: %.2f\n", upper, upperX)
    for {
        mid := (lower + upper) / 2
        big, fft := measureMul(mid)
        X := float64(big) / float64(fft)
        fmt.Printf("speedup at size %d: %.2f\n", mid, X)
        switch {
        case X < 0.98:
            lower = mid
            lowerX = X
        case X > 1.02:
            upper = mid
            upperX = X
        default:
            fmt.Printf("speedup at size %d: %.2f\n", lower, lowerX)
            fmt.Printf("speedup at size %d: %.2f\n", upper, upperX)
            return
        }
    }
}

开发者ID:remyoudompheng,项目名称:bigfft,代码行数:34,代码来源:calibrate_test.go

示例5: TestChan3

func TestChan3() {
    fmt.Println("@@@@@@@@@@@@ TestChan 3")

    fmt.Printf("cpu num: %d\n", runtime.NumCPU()) // 8核cpu

    // 虽然goroutine是并发执行的,但是它们并不是并行运行的。如果不告诉Go额外的东西,同
    // 一时刻只会有一个goroutine执行。利用runtime.GOMAXPROCS(n)可以设置goroutine
    // 并行执行的数量。GOMAXPROCS 设置了同时运行的CPU 的最大数量,并返回之前的设置。
    val := runtime.GOMAXPROCS(runtime.NumCPU() * 4)
    fmt.Printf("last goroutine num: %d\n", val) // 8个

    fmt.Printf("goroutine num: %d\n", runtime.NumGoroutine()) // 4个goroutine同时运行

    var ch1 chan int = make(chan int, 0)
    var ch2 chan int = make(chan int, 0)
    var ch3 chan int = make(chan int, 0)

    go write(ch1, 22)
    go write(ch2, 33)
    go write(ch3, 44)
    go read(ch1)
    go read(ch2)
    go read(ch3)

    fmt.Printf("goroutine num: %d\n", runtime.NumGoroutine()) // 10个goroutine同时运行
    sleep("TestChan3", 3)
}

开发者ID:47045039,项目名称:GoSnippet,代码行数:27,代码来源:tch.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng