-
Notifications
You must be signed in to change notification settings - Fork 18
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
draft: major refactor #90
base: main
Are you sure you want to change the base?
Conversation
return fmt.Sprintf("interrupted with status %d and action %s", e.Interruption.Status, e.Interruption.Action) | ||
} | ||
|
||
func (e *ErrInterrupted) Is(target error) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong. Is
is not meant to see if two errors are the same, instead check error wrapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm playing around with errors.As, apparently that's a shortcut to compare and cast at the same time.
It requires the implementation of Is, and it is working and passing tests
Signed-off-by: Juan Pablo Tosso <[email protected]>
@sts could you help us fix the e2e for this branch? I'm not sure how it works |
const defaultExpire = time.Second * 10 | ||
const defaultEvictionInterval = time.Second * 1 | ||
|
||
func Add(tx types.Transaction, ttl time.Duration) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func Add(tx types.Transaction, ttl time.Duration) { | |
func Set(tx types.Transaction, ttl time.Duration) { |
It will override existing entries with the same ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although you are right, this is transparent, as the ID MUST always be unique, by design
// It should only be called when the server is shutting down | ||
// And the SPOE server is already shutdown | ||
// Otherwise the server might crash | ||
func Shutdown() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func Shutdown() { | |
func RemoveAll() { |
A function called Shutdown would imply that after calling it, prevent the usage of the cache. As everything is manipulating a global variable inside this package, I would expose it with the same name as the called Function
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCache(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please add some newlines between the different stages
"github.com/rs/zerolog" | ||
) | ||
|
||
func New(level string, file string) (*zerolog.Logger, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: A package just for setting up zerolog is kinda overkill. I would prefer it to only be configured inside the main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, originally that was a full logger implementation, but it ended up as a wrapper for zerolog. I'm moving it
url.WriteString(req.Query) | ||
} | ||
tx.ProcessURI(url.String(), req.Method, "HTTP/"+req.Version) | ||
if err := readHeaders(req.Headers, func(key, value string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also love inlining error checks but with newlines its fairly hard to read. Maybe cant you give it the function directly?
tx.ProcessLogging() | ||
tx.Close() | ||
// TODO does remove forces eviction? | ||
cache.Remove(id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if it does force eviction, we maybe want that to prevent the memory filling up
"github.com/negasus/haproxy-spoe-go/message" | ||
) | ||
|
||
func unmarshalMessage(msg *message.Message, out interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please no reflection inside the hotpath, especially when you can hardcode all fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fionera I think the second sentence summarizes your needs. Please refrain from using the first sentence in a public place like this 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it ❤️
|
||
var requestPool = sync.Pool{ | ||
New: func() interface{} { | ||
return &applicationRequest{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return &applicationRequest{ | |
return &applicationRequest{} |
|
||
var responsePool = sync.Pool{ | ||
New: func() interface{} { | ||
return &applicationResponse{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return &applicationResponse{ | |
return &applicationResponse{} |
"strings" | ||
) | ||
|
||
func readHeaders(headers string, callback func(key string, value string)) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just throw this into application.go, as its not complicated/big enough to deserve its own file
New features
TODO: