本文整理汇总了Golang中runtime.Func.FileLine方法的典型用法代码示例。如果您正苦于以下问题:Golang Func.FileLine方法的具体用法?Golang Func.FileLine怎么用?Golang Func.FileLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类runtime.Func
的用法示例。
在下文中一共展示了Func.FileLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewRecord
func NewRecord(s string, l LogLevel, m string, d map[string]interface{}) *Record {
r := &Record{
Timestamp: RecordTimestamp(time.Now().UnixNano()) / 1000000000,
Pid: pid,
Source: s,
Level: l,
Message: m,
Data: d,
}
if config.EnableLOC {
var function *runtime.Func
var file string
var line int
pc := make([]uintptr, 50)
nptrs := runtime.Callers(2, pc)
for i := 0; i < nptrs; i++ {
function = runtime.FuncForPC(pc[i])
file, line = function.FileLine(pc[i])
if !strings.HasSuffix(file, "logger.go") {
break
}
}
r.File = file
r.Line = line
r.Method = function.Name()
}
return r
}
示例2: NewRecord
func NewRecord(level LogLevel, message string, data map[string]string) *Record {
record := new(Record)
record.Timestamp = float64(time.Now().UnixNano()) / 1000000000
record.Message = message
record.Level = level
record.Data = data
if config.EnableLOC {
var function *runtime.Func
var file string
var line int
pc := make([]uintptr, 50)
nptrs := runtime.Callers(2, pc)
for i := 0; i < nptrs; i++ {
function = runtime.FuncForPC(pc[i])
file, line = function.FileLine(pc[i])
if !strings.HasSuffix(file, "logger.go") {
break
}
}
record.File = file
record.Method = function.Name()
record.Line = line
}
return record
}
示例3: UnstubDefaultTransport
// UnstubDefaultTransport restores http.DefaultTransport
func (mitm *MitmTransport) UnstubDefaultTransport() {
mitm.mux.Lock()
defer mitm.mux.Unlock()
if mitm.stubbed {
mitm.stubbed = false
http.DefaultTransport = httpDefaultResponder
}
// is times miss match?
if !mitm.paused {
errlogs := []string{}
for key, response := range mitm.stubs {
for path, mocker := range response.Mocks() {
if !mocker.IsTimesMatched() {
key = strings.Replace(key, MockScheme, mocker.Scheme(), 1)
expected, invoked := mocker.Times()
errlogs = append(errlogs, " Error Trace: %s:%d\n Error: Expected "+key+path+" with "+fmt.Sprintf("%d", expected)+" times, but got "+fmt.Sprintf("%d", invoked)+" times\n\n")
}
}
}
if len(errlogs) > 0 {
pcs := make([]uintptr, 10)
max := runtime.Callers(2, pcs)
var (
pcfunc *runtime.Func
pcfile string
pcline int
)
for i := 0; i < max; i++ {
pcfunc = runtime.FuncForPC(pcs[i] - 1)
if strings.HasPrefix(pcfunc.Name(), "runtime.") {
continue
}
pcfile, pcline = pcfunc.FileLine(pcs[i])
}
// format errlogs
for i, errlog := range errlogs {
errlogs[i] = fmt.Sprintf(errlog, filepath.Base(pcfile), pcline)
}
fmt.Printf("--- FAIL: %s\n%s", pcfunc.Name(), strings.Join(errlogs, "\n"))
mitm.testing.Fail()
}
}
mitm.testing = nil
mitm.stubs = make(map[string]*Responser)
}
示例4: newTestState
func newTestState(pc uintptr, f *runtime.Func) (*testState, error) {
state := &testState{
pc: pc,
fullName: f.Name(),
}
state.fileName, state.fileLine = f.FileLine(pc)
splits := strings.Split(state.fullName, ".")
state.name = splits[len(splits)-1]
return state, nil
}