source

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2020 License: MIT Imports: 8 Imported by: 12

README

source Go license codecov

source 模块提供了一些与源码相关的功能

  • DumpGoSource 输出并格式化 Go 的源代码;
  • CurrentFile 相当于部分语言的 __FILE__
  • CurrentDir 相当于部分语言的 __DIR__
  • CurrentLine 相当于部分语言的 __LINE__
  • CurrentFunction 相当于部分语言的 __FUNCTION__
  • TraceStack 返回调用者的堆栈信息;

安装

go get github.com/issue9/source

文档

PkgGoDev

版权

本项目采用 MIT 开源授权许可证,完整的授权说明可在 LICENSE 文件中找到。

Documentation

Overview

Package source 提供与 go 源码相关的一些操作

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentDir

func CurrentDir() string

CurrentDir 获取`调用者`所在的目录

相当于部分语言的 __DIR__

func CurrentFile

func CurrentFile() string

CurrentFile 获取`调用者`所在的文件

相当于部分语言的 __FILE__

func CurrentFunction

func CurrentFunction() string

CurrentFunction 获取`调用者`所在的函数名

相当于部分语言的 __FUNCTION__

func CurrentLine

func CurrentLine() int

CurrentLine 获取`调用者`所在的行

相当于部分语言的 __LINE__

func CurrentPath

func CurrentPath(path string) string

CurrentPath 获取`调用者`所在目录的路径

类似于部分语言的的 __DIR__ + "/" + path

func DumpGoSource

func DumpGoSource(path string, content []byte) error

DumpGoSource 输出 Go 源码到 path

会对源代码作格式化。

func TraceStack

func TraceStack(level int, msg ...interface{}) (string, error)

TraceStack 返回调用者的堆栈信息

level 表示调用者的级别,1 表示 TraceStack 自身,2 表示调用 TraceStack 的方法,以此类推; msg 表示需要输出的额外信息;

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL