created setup
This commit is contained in:
45
internal/session/session.go
Normal file
45
internal/session/session.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
petname "github.com/dustinkirkland/golang-petname"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Name string
|
||||
PublicKey string
|
||||
PrivateKey string
|
||||
}
|
||||
|
||||
var lastSessionId int = 0
|
||||
var sessionStorage []Session = []Session{}
|
||||
var nameToSession map[string]*Session = make(map[string]*Session)
|
||||
|
||||
type Session struct {
|
||||
id int
|
||||
Name string
|
||||
Users []User
|
||||
}
|
||||
|
||||
func NewSession() Session {
|
||||
sessionName := petname.Generate(3, "-")
|
||||
|
||||
s := Session{
|
||||
id: lastSessionId,
|
||||
Name: sessionName,
|
||||
Users: []User{},
|
||||
}
|
||||
|
||||
sessionStorage = append(sessionStorage, s)
|
||||
nameToSession[sessionName] = &s
|
||||
lastSessionId++
|
||||
|
||||
fmt.Println(sessionName)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func GetSession(name string) *Session {
|
||||
return nameToSession[name]
|
||||
}
|
||||
Reference in New Issue
Block a user