Use gin-gonic instead of httprouter
This commit is contained in:
parent
7c719d9fd5
commit
a203cdc36a
22 changed files with 1631 additions and 1355 deletions
27
session.go
27
session.go
|
|
@ -6,42 +6,43 @@ import (
|
|||
)
|
||||
|
||||
type Session struct {
|
||||
Id []byte `json:"id"`
|
||||
Id []byte `json:"id"`
|
||||
IdUser *int64 `json:"login"`
|
||||
Time time.Time `json:"time"`
|
||||
Time time.Time `json:"time"`
|
||||
}
|
||||
|
||||
func getSession(id []byte) (s Session, err error) {
|
||||
func getSession(id []byte) (s *Session, err error) {
|
||||
s = new(Session)
|
||||
err = DBQueryRow("SELECT id_session, id_user, time FROM user_sessions WHERE id_session=?", id).Scan(&s.Id, &s.IdUser, &s.Time)
|
||||
return
|
||||
}
|
||||
|
||||
func NewSession() (Session, error) {
|
||||
func NewSession() (*Session, error) {
|
||||
session_id := make([]byte, 255)
|
||||
if _, err := rand.Read(session_id); err != nil {
|
||||
return Session{}, err
|
||||
return nil, err
|
||||
} else if _, err := DBExec("INSERT INTO user_sessions (id_session, time) VALUES (?, ?)", session_id, time.Now()); err != nil {
|
||||
return Session{}, err
|
||||
return nil, err
|
||||
} else {
|
||||
return Session{session_id, nil, time.Now()}, nil
|
||||
return &Session{session_id, nil, time.Now()}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (user User) NewSession() (Session, error) {
|
||||
func (user User) NewSession() (*Session, error) {
|
||||
session_id := make([]byte, 255)
|
||||
if _, err := rand.Read(session_id); err != nil {
|
||||
return Session{}, err
|
||||
return nil, err
|
||||
} else if _, err := DBExec("INSERT INTO user_sessions (id_session, id_user, time) VALUES (?, ?, ?)", session_id, user.Id, time.Now()); err != nil {
|
||||
return Session{}, err
|
||||
return nil, err
|
||||
} else {
|
||||
return Session{session_id, &user.Id, time.Now()}, nil
|
||||
return &Session{session_id, &user.Id, time.Now()}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s Session) SetUser(user User) (Session, error) {
|
||||
func (s Session) SetUser(user *User) (*Session, error) {
|
||||
s.IdUser = &user.Id
|
||||
_, err := s.Update()
|
||||
return s, err
|
||||
return &s, err
|
||||
}
|
||||
|
||||
func (s Session) Update() (int64, error) {
|
||||
|
|
|
|||
Reference in a new issue