HOME/Articles/

Golang golang-runtime (snippet)

Article Outline

Go programming example 'golang-runtime'

golang-runtime

Golang beginners example: golang-runtime

package main

import (
    "fmt"
    "log"
    "runtime"
    "time"
)

func Debug(format string, a ...interface{}) {
    _, file, line, _ := runtime.Caller(1)
    info := fmt.Sprintf(format, a...)

    log.Printf("%s:%d %v", file, line, info)
}

func foobar(format string, a ...interface{}) {
    Debug(format, a)
}

func main() {
    foobar("test: %v\n", time.Now())
}