From 0d38794c7f9b25b2e602cb0d2f686e74cd1ab1cb Mon Sep 17 00:00:00 2001 From: Paolo Borelli Date: Fri, 31 Jul 2015 08:50:11 +0200 Subject: 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. --- modules/user/user.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 modules/user/user.go (limited to 'modules/user') 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") +} -- cgit v1.2.3