Skip to content

Commit

Permalink
feat: add caller info
Browse files Browse the repository at this point in the history
  • Loading branch information
dwisiswant0 committed May 3, 2023
1 parent d89d58c commit e9af9d7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions teler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"fmt"
"io"
"os"
"path"
"regexp"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -72,7 +74,12 @@ type Teler struct {
// that are used to check whether a request should be whitelisted.
whitelistRegexes []*regexp.Regexp

// cache is an in-memory cache used by Teler middleware to
// store data for a short period of time.
cache *cache.Cache

// caller is the name of the package that called the Teler middleware.
caller string
}

// New constructs a new Teler instance with the supplied options.
Expand All @@ -92,6 +99,12 @@ func New(opts ...Options) *Teler {
threat: &Threat{},
}

// Get the package name of the calling package
_, file, _, ok := runtime.Caller(1)
if ok {
t.caller = path.Base(path.Dir(file))
}

// Set the opt field of the Teler struct to the options
t.opt = o

Expand Down

0 comments on commit e9af9d7

Please sign in to comment.