rename newSID to randomID

This commit is contained in:
Krishna Srinivas
2015-09-30 01:03:11 -07:00
parent 4671e01dbf
commit 2b0276bd6c
4 changed files with 36 additions and 16 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ func newSessionV2() *sessionV2 {
s.Header.CommandArgs = nil
s.Header.When = time.Now().UTC()
s.mutex = new(sync.Mutex)
s.SessionID = newSID(8)
s.SessionID = randomID(8)
sessionDataFile, perr := getSessionDataFile(s.SessionID)
fatalIf(perr.Trace(s.SessionID), "Unable to create session data file \""+sessionDataFile+"\".")
-14
View File
@@ -17,11 +17,9 @@
package main
import (
"math/rand"
"os"
"path/filepath"
"strings"
"time"
"github.com/minio/minio/pkg/probe"
)
@@ -63,18 +61,6 @@ func isSessionDirExists() bool {
return true
}
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
// newSID generates a random session id of regular lower case and uppercase english characters
func newSID(n int) string {
rand.Seed(time.Now().UTC().UnixNano())
sid := make([]rune, n)
for i := range sid {
sid[i] = letters[rand.Intn(len(letters))]
}
return string(sid)
}
func getSessionFile(sid string) (string, *probe.Error) {
sessionDir, err := getSessionDir()
if err != nil {
+1 -1
View File
@@ -26,7 +26,7 @@ import (
func (s *TestSuite) TestValidSessionID(c *C) {
validSid := regexp.MustCompile("^[a-zA-Z]+$")
sid := newSID(8)
sid := randomID(8)
c.Assert(len(sid), Equals, 8)
c.Assert(validSid.MatchString(sid), Equals, true)
}
+34
View File
@@ -0,0 +1,34 @@
/*
* Minio Client (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"math/rand"
"time"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
// randomID generates a random id of regular lower case and uppercase english characters
func randomID(n int) string {
rand.Seed(time.Now().UTC().UnixNano())
sid := make([]rune, n)
for i := range sid {
sid[i] = letters[rand.Intn(len(letters))]
}
return string(sid)
}