2 ms·
Others have pointed out that os/user.Lookup is a platform-independent way to resolve this, but additionally you don’t _need_ to link against glibc to use it. I
by catlifeonmars 3mo ago
Others have pointed out that os/user.Lookup is a platform-independent way to resolve this, but additionally you don’t _need_ to link against glibc to use it.
If you are writing go, you usually want to set CGO_ENABLED=0 by default, to avoid inadvertently introducing nonportable code. In this way, only the pure Go implementations are used and there is no need to link (statically or dynamically) against a libc implementation to compile and run your programs.
- dchest 3mo agoWith CGO disabled, it only reads /etc/passwd, while the glibc getpwnam(3) can query LDAP etc.
- catlifeonmars 3mo agoThat’s not the use case of the tailscale daemon though, which was using getent passwd. To clarify: I’m not against CGO, just introducing a glibc dependency by default. I would only introduce it when I needed it.