diff options
author | Paolo Borelli <pborelli@gnome.org> | 2015-07-31 08:50:11 +0200 |
---|---|---|
committer | Paolo Borelli <pborelli@gnome.org> | 2015-08-15 10:05:12 +0200 |
commit | 0d38794c7f9b25b2e602cb0d2f686e74cd1ab1cb (patch) | |
tree | 5ebac231c18bbce2ee1ba5f8e244b26cf198b46d /modules/user | |
parent | b35d7eee31e8a33e314d54514854efaeee9d46b1 (diff) | |
download | gitea-0d38794c7f9b25b2e602cb0d2f686e74cd1ab1cb.tar.gz gitea-0d38794c7f9b25b2e602cb0d2f686e74cd1ab1cb.zip |
Factor out function to get the current user
The same logic was duplicated in three places. Factor it
out so that we can add further fallbacks in a single place.
Diffstat (limited to 'modules/user')
-rw-r--r-- | modules/user/user.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/user/user.go b/modules/user/user.go new file mode 100644 index 0000000000..8a2557f327 --- /dev/null +++ b/modules/user/user.go @@ -0,0 +1,18 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package user + +import ( + "os" +) + +func CurrentUsername() string { + curUserName := os.Getenv("USER") + if len(curUserName) > 0 { + return curUserName + } + + return os.Getenv("USERNAME") +} |