当前位置: 首页>>代码示例>>Golang>>正文


Golang runtime.Func类代码示例

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


在下文中一共展示了Func类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
开发者ID:hpcloud,项目名称:gosteno,代码行数:31,代码来源:record.go

示例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
}
开发者ID:cloudfoundry-attic,项目名称:gonatsd,代码行数:29,代码来源:record.go

示例3: 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
}
开发者ID:boumenot,项目名称:packer,代码行数:13,代码来源:approvals.go

示例4: Trace

func (this *Trace) Trace(level int) *Trace {
	var ok bool
	var pc uintptr
	var fn *runtime.Func
	var buf []byte
	var tmp []string
	var i int

	this.Record = r.NewRecord()
	if level == 0 {
		level = STEP_BACK
	}
	buf = make([]byte, 1<<16)
	pc, this.Record.FileNameLong, this.Record.FileLine, ok = runtime.Caller(level)
	if ok == true {
		fn = runtime.FuncForPC(pc)
		if fn != nil {
			this.Record.Function = fn.Name()
		}
		i = runtime.Stack(buf, true)
		this.Record.CallStack = string(buf[:i])

		tmp = strings.Split(this.Record.Function, packageSeparator)
		if len(tmp) > 1 {
			this.Record.Package += strings.Join(tmp[:len(tmp)-1], packageSeparator)
			this.Record.Function = tmp[len(tmp)-1]
		}
		tmp = strings.SplitN(this.Record.Function, `.`, 2)
		if len(tmp) == 2 {
			if this.Record.Package != "" {
				this.Record.Package += packageSeparator
			}
			this.Record.Package += tmp[0]
			this.Record.Function = tmp[1]
		}

		// Filename short
		tmp = strings.Split(this.Record.FileNameLong, packageSeparator)
		if len(tmp) > 0 {
			this.Record.FileNameShort = tmp[len(tmp)-1]
		}

		// Module name
		tmp = strings.Split(this.Record.Package, packageSeparator)
		if len(tmp) > 0 {
			this.Record.Module = tmp[len(tmp)-1]
		}
	}
	return this
}
开发者ID:webdeskltd,项目名称:log,代码行数:50,代码来源:trace.go

示例5: packageAndName

func packageAndName(fn *runtime.Func) (string, string) {
	name := fn.Name()
	pkg := ""

	// we first remove the path prefix if there is one.
	if lastslash := strings.LastIndex(name, "/"); lastslash >= 0 {
		pkg += name[:lastslash] + "/"
		name = name[lastslash+1:]
	}
	if period := strings.Index(name, "."); period >= 0 {
		pkg += name[:period]
		name = name[period+1:]
	}

	return pkg, name
}
开发者ID:leobcn,项目名称:health,代码行数:16,代码来源:frame.go

示例6: shortFuncName

/* "FuncName" or "Receiver.MethodName" */
func shortFuncName(f *runtime.Func) string {
	// f.Name() is like one of these:
	// - "github.com/palantir/shield/package.FuncName"
	// - "github.com/palantir/shield/package.Receiver.MethodName"
	// - "github.com/palantir/shield/package.(*PtrReceiver).MethodName"
	longName := f.Name()

	withoutPath := longName[strings.LastIndex(longName, "/")+1:]
	withoutPackage := withoutPath[strings.Index(withoutPath, ".")+1:]

	shortName := withoutPackage
	shortName = strings.Replace(shortName, "(", "", 1)
	shortName = strings.Replace(shortName, "*", "", 1)
	shortName = strings.Replace(shortName, ")", "", 1)

	return shortName
}
开发者ID:palantir,项目名称:stacktrace,代码行数:18,代码来源:stacktrace.go

示例7: 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)
}
开发者ID:dolab,项目名称:httpmitm,代码行数:56,代码来源:transport.go

示例8: Trace

func (t *trace) Trace(level int) *trace {
	var ok bool
	var pc uintptr
	var fn *runtime.Func
	var buf []byte
	var tmp []string
	var i int

	if level == 0 {
		level = traceStepBack
	}
	buf = make([]byte, 1<<16)
	pc, t.File, t.Line, ok = runtime.Caller(level)
	if ok == true {
		fn = runtime.FuncForPC(pc)
		if fn != nil {
			t.Function = fn.Name()
		}
		i = runtime.Stack(buf, true)
		t.Stack = string(buf[:i])

		tmp = strings.Split(t.Function, packageSeparator)
		if len(tmp) > 1 {
			t.Package += strings.Join(tmp[:len(tmp)-1], packageSeparator)
			t.Function = tmp[len(tmp)-1]
		}
		tmp = strings.SplitN(t.Function, `.`, 2)
		if len(tmp) == 2 {
			if t.Package != "" {
				t.Package += packageSeparator
			}
			t.Package += tmp[0]
			t.Function = tmp[1]
		}

	}
	return t
}
开发者ID:webdeskltd,项目名称:debug,代码行数:38,代码来源:trace.go

示例9: packageAndName

func packageAndName(fn *runtime.Func) (string, string) {
	name := fn.Name()
	pkg := ""

	// The name includes the path name to the package, which is unnecessary
	// since the file name is already included.  Plus, it has center dots.
	// That is, we see
	//  runtime/debug.*T·ptrmethod
	// and want
	//  *T.ptrmethod
	// Since the package path might contains dots (e.g. code.google.com/...),
	// we first remove the path prefix if there is one.
	if lastslash := strings.LastIndex(name, "/"); lastslash >= 0 {
		pkg += name[:lastslash] + "/"
		name = name[lastslash+1:]
	}
	if period := strings.Index(name, "."); period >= 0 {
		pkg += name[:period]
		name = name[period+1:]
	}

	name = strings.Replace(name, "·", ".", -1)
	return pkg, name
}
开发者ID:dessoya,项目名称:space_craft,代码行数:24,代码来源:utils.go

示例10: isTestRunner

func isTestRunner(f *runtime.Func) bool {
	return f != nil && f.Name() == "testing.tRunner"
}
开发者ID:boumenot,项目名称:packer,代码行数:3,代码来源:approvals.go


注:本文中的runtime.Func类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。