source

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MIT Imports: 7 Imported by: 12

README

source Go license codecov Go version PkgGoDev

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

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

安装

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 CurrentLocation added in v0.1.2

func CurrentLocation() (path string, line int)

CurrentLocation 获取调用者当前的位置信息

func CurrentPath

func CurrentPath(path string) string

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

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

func DumpGoSource

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

DumpGoSource 输出 Go 源码到 path

会对源代码作格式化。

func Stack added in v0.2.0

func Stack(skip int, msg ...interface{}) string

Stack 返回调用者的堆栈信息

skip 需要忽略的内容。

  • 1 表示 Stack 自身;
  • 2 表示 Stack 的调用者,以此类推;

msg 表示需要输出的额外信息;

Types

This section is empty.

Jump to

Keyboard shortcuts

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