Optimize code

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao
2019-01-07 17:51:17 +08:00
parent 6d8dead8ca
commit bd6bab1c0c
2 changed files with 5 additions and 3 deletions
+1 -1
View File
@@ -105,7 +105,7 @@ func serveCmd(br *Broker, w http.ResponseWriter, r *http.Request) {
return
}
token = UniqueId()
token = UniqueId("cmd")
commands[token] = &commandStatus{
t: time.AfterFunc(30*time.Second, func() {
+4 -2
View File
@@ -63,12 +63,14 @@ func allowOrigin(w http.ResponseWriter) {
var hsMutex sync.Mutex
var httpSessions = make(map[string]*HttpSession)
func UniqueId() string {
func UniqueId(extra string) string {
b := make([]byte, 48)
io.ReadFull(rand.Reader, b)
h := md5.New()
h.Write([]byte(base64.URLEncoding.EncodeToString(b)))
h.Write([]byte(extra))
return hex.EncodeToString(h.Sum(nil))
}
@@ -194,7 +196,7 @@ func main() {
password := r.PostFormValue("password")
if httpLogin(cfg, username, password) {
sid := UniqueId()
sid := UniqueId("http")
cookie := http.Cookie{
Name: "sid",
Value: sid,