sourceinfo

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

package sourceinfo is a helper around runtime Caller which simplifies fetching source information using frames.

Index

Constants

View Source
const (
	DefaultCallDepth int = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SourceInfoType

type SourceInfoType int

This enum indicates the source information format

const (
	// Source information won't be retrieved
	NoSourceInfo SourceInfoType = iota
	// Full file name and line number
	FullFileAndLine
	// Full file name and line number with function name
	FullFileAndLineWithFunc
	// Short file name and line number
	ShortFileAndLine
	// Short file name and line number with function name
	ShortFileAndLineWithFunc
)

type SourceInformation

type SourceInformation struct {
	File     string `json:"file" yaml:"file"`
	Function string `json:"function,omitempty" yaml:"function,omitempty"`
	Line     int    `json:"line" yaml:"line"`
}

This structure contains the information about the source code.

func GetSourceInformation

func GetSourceInformation(callDepth int, sourceInfoType SourceInfoType) (sourceInfo *SourceInformation)

This method gets the source information based on the type passed. Passing sourceinfo.NoSourceInfo will cause this function to return a nil pointer. If any error is encountered or if this function could not retrieve the source information then the returned pointer will be nil.

func (*SourceInformation) String

func (s *SourceInformation) String() string

This function prints the source information in the format

file:line(function):

Jump to

Keyboard shortcuts

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