You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
}
The text was updated successfully, but these errors were encountered:
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)
})
}
The text was updated successfully, but these errors were encountered: