From 32981d6a559057caa26e33005f9b5d39c961b2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Wed, 15 Jan 2020 23:50:09 +0100 Subject: [PATCH] Don't export *log.Logger in Scanner By introducing a lowercase type alias 'logger' for *log.Logger we can now embed 'logger' in Scanner and not export it: % go doc Scanner package symbolyze // import "." type Scanner struct { // Has unexported fields. } --- GetRuntimeAddresses/symbolyze/symbolyze.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/GetRuntimeAddresses/symbolyze/symbolyze.go b/GetRuntimeAddresses/symbolyze/symbolyze.go index c5ea3b3..4dc8afd 100644 --- a/GetRuntimeAddresses/symbolyze/symbolyze.go +++ b/GetRuntimeAddresses/symbolyze/symbolyze.go @@ -28,7 +28,7 @@ type Scanner struct { cache map[string]uint64 // Contains (pathname, offset) observers []Observer // Callbacks - *log.Logger // Embedded logger + logger // Embedded logger // Instead of using a boolean to indicate debugging, we use function // members. This way we can populate them with noop-functions in the @@ -39,6 +39,10 @@ type Scanner struct { err error // error state of the scanner. } +// We use a lowercase type alias for *log.Logger so that we can embedd it in +// Scanner without exporting it. +type logger = *log.Logger + // An Observer is a callback that can be registerd with Scanner.OnFound. It // will be called with a pid and an offset. Observers are called concurrently. // They have to be thread-safe. @@ -54,7 +58,7 @@ func New(symbol, pathglob string) *Scanner { pathglob: pathglob, cache: map[string]uint64{}, - Logger: log.New(os.Stderr, "[symbolyze] ", log.Ltime|log.Lmicroseconds), + logger: log.New(os.Stderr, "[symbolyze] ", log.Ltime|log.Lmicroseconds), // debugging is off per default. debugf: func(string, ...interface{}) {},