Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readability improvements #44

Open
gfr10598 opened this issue Dec 4, 2019 · 0 comments
Open

Readability improvements #44

gfr10598 opened this issue Dec 4, 2019 · 0 comments
Labels

Comments

@gfr10598
Copy link
Contributor

gfr10598 commented Dec 4, 2019

This is just a few suggestions for improving readability for the Tracer and cachedTest code. It isn't fully fleshed out, so a little more thought is required.

The fact that Trace() and CreateCacheTrace both write files is confusing. It seems like it would be much clearer if there was a function that generates a trace, and a function that creates a file.

If that were the case, then you could replace the channel with a sync.Once, and have a GetData(ip string) that uses once.Do() to create the trace in the cache entry. The you would get the cache entry, call GetData() on the cache entry, then call the function to create the file.

There is some question as to whether we should be saving the original UUID, since that reduces anonymity, but ideally, only the IP address would be needed to create a trace, and only the trace data (without any connection metadata or original UUID) would be stored, which would simplify things further. The ip address would be passed to Trace, and the Connection would only be passed to SaveTrace.

So:
type Tracer interface {
// Just creates the body, not the metadata header.
Trace(ip string) string
}

// Creates the header, appends the body, saves the file.
func SaveTrace(conn Connection, t time.Time, data string) {
...
}

type cachedTest struct {
timeStamp time.Time
uuid string // If we really need the original uuid.
data string
once sync.Once
}

func (ct *cachedTest) getTest(t Tracer, ip string, uuid string) (string, string) {
once.Do(func() {
ct.uuid = uuid // kinda ugly - better ways to do this.
ct.data = t.Trace(ip)
})

return ct.data

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants