In a Google Go application what is the easiest way to check if the current process is running as an administrator?
The short answer is to use user.Current
. HOWEVER...
You will need to find a way to, given the user.User
struct, figure out whether the user is root. You'll have to figure that one out on your own. More importantly, you should not use this for security purposes. Figuring out whether the current user is root without being lied to by the person running the program is very tricky. For example, a naive implementation of this on Linux with a setuid binary would be vulnerable to the user using LD_PRELOAD to trick the binary into thinking it was running as root. Make sure that you either, a) understand the exact semantics of this and are convinced there is no way to circumvent it by the user (and if you choose this route, you should probably just see if others have figured it out), or, b) do not make any security-critical decisions based on this information.