diff pkg/auth/session.go @ 1323:3c914bc670a2

Avoid copying session data while deserializing from store. This involed copying a mutex which would technical be not correct if the mutex would be used at this time, which it is not. go vet was not happy about this even if its not a problem. Not copying the data makes it a bit faster, though.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 24 Nov 2018 17:08:56 +0100
parents 176c42053562
children ea2143adc6d3
line wrap: on
line diff
--- a/pkg/auth/session.go	Sat Nov 24 16:55:40 2018 +0100
+++ b/pkg/auth/session.go	Sat Nov 24 17:08:56 2018 +0100
@@ -90,17 +90,15 @@
 
 func (s *Session) deserialize(r io.Reader) error {
 
-	var session Session
-
 	var n uint32
 	rd := misc.BinReader{Reader: r, Err: nil}
-	rd.ReadBin(&session.ExpiresAt)
-	rd.ReadString(&session.User)
+	rd.ReadBin(&s.ExpiresAt)
+	rd.ReadString(&s.User)
 	rd.ReadBin(&n)
-	session.Roles = make(Roles, n)
+	s.Roles = make(Roles, n)
 
 	for i := uint32(0); n > 0 && i < n; i++ {
-		rd.ReadString(&session.Roles[i])
+		rd.ReadString(&s.Roles[i])
 	}
 
 	if rd.Err != nil {
@@ -121,9 +119,7 @@
 		return err
 	}
 
-	session.access = t
-
-	*s = session
+	s.access = t
 
 	return nil
 }