Skip to content

Commit 3f79bb4

Browse files
Added struct for user session
1 parent 8b350d5 commit 3f79bb4

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# backend environment configs
22
app:
3+
name: laclm
34
version: v1.1
4-
debug_mode: true
5+
debug_mode: true
6+
session_timeout: 24
57

68
# backend server deployment configs
79
server:

config/app.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type App struct {
55
Name string `yaml:"name,omitempty"`
66
Version string `yaml:"version,omitempty"`
77
DebugMode bool `yaml:"debug_mode,omitempty"`
8+
SessionTimeout int `yaml:"session_timeout,omitempty"`
89
}
910

1011
/* normalization function */
@@ -22,5 +23,9 @@ func (a *App) Normalize() error {
2223
we want production to be true
2324
*/
2425

26+
if a.SessionTimeout == 0 {
27+
a.SessionTimeout = 24
28+
}
29+
2530
return nil
2631
}

internal/health/handler.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"net/http"
66

77
"go.uber.org/zap"
8-
// "github.com/PythonHacker24/linux-acl-management-backend/internal/models"
98
)
109

1110
/* health handler provides status check on the backend server */

internal/session/model.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package session
2+
3+
import (
4+
"container/list"
5+
"sync"
6+
"time"
7+
)
8+
9+
/* session struct for a user */
10+
type Session struct {
11+
Username string
12+
CurrentWorkingDir string
13+
Expiry time.Time
14+
Timer *time.Timer
15+
TransactionQueue *list.List
16+
Mutex sync.Mutex
17+
}

internal/session/session.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
package session
22

3+
import (
4+
"container/list"
5+
"time"
6+
7+
"github.com/PythonHacker24/linux-acl-management-backend/config"
8+
)
9+
10+
/* for creating a session for user */
311
func CreateSession(username string) {
12+
session := Session{
13+
Username: username,
14+
Expiry: time.Now().Add(time.Duration(config.BackendConfig.AppInfo.SessionTimeout) * time.Hour),
15+
Timer: time.AfterFunc(time.Duration(config.BackendConfig.AppInfo.SessionTimeout)*time.Hour,
16+
func() { ExpireSession(username) },
17+
),
18+
TransactionQueue: list.New(),
19+
CurrentWorkingDir: ".",
20+
}
21+
22+
}
23+
24+
/* for expiring a session */
25+
func ExpireSession(username string) {
426

527
}

0 commit comments

Comments
 (0)