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.
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. |
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.
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.
seems so, that was copied from the other funcs:
go-systemd/activation/listeners.go
Line 48 in 4b765dd
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