Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Get Information of the Current User

user.Current() returns information of the current (real) user. If the code is run by a non-root user named some_user on Linux, then information of some_user is returned. However, if some_user has sudo access and run the code using sudo, then the real user user is root and the information of root is returned.

&{1000 1000 dclong dclong /home/dclong}
dclong
1000
1000

Test An User’s Access to a Path

Use unix.Access

true
permission denied
true

Use os.OpenFile + os.IsPermission

This way only works on files. Please refer to Golang : Test file read write permission example for detailed discussions.

<nil> open /home: is a directory