-
Notifications
You must be signed in to change notification settings - Fork 328
add FilesWithNames() to activation #448
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
Conversation
|
Thank you for contributing! Would you mind explaining your usecase ? |
|
sure, my program uses socket units with both Listen and ListenDatagram settings, some of which may be used to create TLS listeners, and some of which may not. The existing *WithNames functions assume that all the sockets use the same protocol, and that either all or none will be used to create TLS listeners. |
kolyshkin
left a comment
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.
From what I see, this is just a wrapper on top of Files which converts the returned *os.File slice into a map, where the key is file name and the value is a slice of *os.File corresponding to this name.
Such functionality, if needed, can easily be recreated in software that uses this package and activation.Files, in just a few lines of code. Unless such usage is a very common case, I can hardly see why we should put this method into this repo.
right, these are those few lines of code. there are already funcs in activation that create TCP listeners with TLS configurations for each stream fd and map names to them, which is a much more special case than what |
|
@MayCXC can you please squash your commits, and add a |
0bbfee7 to
a12d14c
Compare
|
@kolyshkin no problem. i also moved the func out of the goos targets. |
kolyshkin
left a comment
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.
lgtm
activation/files.go
Outdated
| current, ok := filesWithNames[f.Name()] | ||
|
|
||
| if !ok { | ||
| current = []*os.File{} | ||
| filesWithNames[f.Name()] = current | ||
| } | ||
|
|
||
| filesWithNames[f.Name()] = append(current, f) |
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 that could be made much simpler with just doing
filesWithNames[f.Name()] = append(filesWithNames[f.Name()], f)
The map lookup returns the zero value nil which is totally fine to append to and will create a new slice and otherwise returns the existing one and appends there so this one line should be enough
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.
seems so, that was copied from the other funcs:
go-systemd/activation/listeners.go
Line 48 in 4b765dd
| current, ok := listeners[f.Name()] |
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.
Opened #498
As map lookup returns nil if no key is found, and append will create a new slice if it's first argument is nil, we can greatly simplify the loop, as suggested in [1]. [1]: coreos#448 (comment) Reported-by: Paul Holzinger <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
|
FYI, this PR is being carried in #497 |
As map lookup returns nil if no key is found, and append will create a new slice if it's first argument is nil, we can greatly simplify the loop, as suggested in [1]. [1]: coreos#448 (comment) Reported-by: Paul Holzinger <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
As map lookup returns nil if no key is found, and append will create a new slice if it's first argument is nil, we can greatly simplify the loop, as suggested in [1]. [1]: #448 (comment) Reported-by: Paul Holzinger <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
I'd like to upstream the function here https://github.com/MayCXC/caddy-systemd-socket-activation/blob/master/networks.go#L25
which is like the
*WithNamesfuncs herego-systemd/activation/listeners.go
Line 42 in 7d375ec