comparison 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
comparison
equal deleted inserted replaced
1322:176c42053562 1323:3c914bc670a2
88 return wr.Err 88 return wr.Err
89 } 89 }
90 90
91 func (s *Session) deserialize(r io.Reader) error { 91 func (s *Session) deserialize(r io.Reader) error {
92 92
93 var session Session
94
95 var n uint32 93 var n uint32
96 rd := misc.BinReader{Reader: r, Err: nil} 94 rd := misc.BinReader{Reader: r, Err: nil}
97 rd.ReadBin(&session.ExpiresAt) 95 rd.ReadBin(&s.ExpiresAt)
98 rd.ReadString(&session.User) 96 rd.ReadString(&s.User)
99 rd.ReadBin(&n) 97 rd.ReadBin(&n)
100 session.Roles = make(Roles, n) 98 s.Roles = make(Roles, n)
101 99
102 for i := uint32(0); n > 0 && i < n; i++ { 100 for i := uint32(0); n > 0 && i < n; i++ {
103 rd.ReadString(&session.Roles[i]) 101 rd.ReadString(&s.Roles[i])
104 } 102 }
105 103
106 if rd.Err != nil { 104 if rd.Err != nil {
107 return rd.Err 105 return rd.Err
108 } 106 }
119 var t time.Time 117 var t time.Time
120 if err := t.UnmarshalText(access); err != nil { 118 if err := t.UnmarshalText(access); err != nil {
121 return err 119 return err
122 } 120 }
123 121
124 session.access = t 122 s.access = t
125
126 *s = session
127 123
128 return nil 124 return nil
129 } 125 }
130 126
131 func (c *Session) touch() { 127 func (c *Session) touch() {