...

Source file src/golang.conradwood.net/go-easyops/errors/shared/stack.go

Documentation: golang.conradwood.net/go-easyops/errors/shared

     1  package shared
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  var (
     9  	STACK_FILTER = []string{
    10  		"golang.conradwood.net/go-easyops/errors",
    11  		"runtime",
    12  	}
    13  )
    14  
    15  type StackPos struct {
    16  	Filename string
    17  	Function string
    18  	Line     int
    19  }
    20  
    21  func first_non_internal_pos(sp []*StackPos) *StackPos {
    22  	if len(sp) == 0 {
    23  		return nil
    24  	}
    25  	for _, sp := range sp {
    26  		if sp.IsFiltered() {
    27  			continue
    28  		}
    29  		return sp
    30  	}
    31  	return sp[0]
    32  }
    33  
    34  func (sp *StackPos) String() string {
    35  	if sp == nil {
    36  		return "[no stack]"
    37  	}
    38  	return fmt.Sprintf("%s:%d", sp.Filename, sp.Line)
    39  }
    40  
    41  func (sp *StackPos) IsFiltered() bool {
    42  	for _, s := range STACK_FILTER {
    43  		if strings.Contains(sp.Function, s) {
    44  			return true
    45  		}
    46  	}
    47  	return false
    48  }
    49  

View as plain text