From aa7c3eb23c31fa6051ee0caaebea47c8225d55a4 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 29 Apr 2023 01:11:04 -0500 Subject: add endpoint.go --- db/db.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'db/db.go') diff --git a/db/db.go b/db/db.go index 4824a6d..d9faff3 100644 --- a/db/db.go +++ b/db/db.go @@ -2,6 +2,7 @@ package db import ( "os" + "time" "io/fs" "errors" "database/sql" @@ -19,11 +20,13 @@ type User struct { type Session struct { Id string - UserId string + UserId int + Created time.Time + Modified time.Time } type Endpoint struct { - Id string + Id int Name string Path string Address string @@ -45,6 +48,7 @@ type Model interface { CreateSession(user User) (Session, error) DeleteSession(session Session) error CheckSession(session Session) (bool, error) + CleanSessions(maxIdle time.Duration) error AllSessions() ([]Session, error) CreateEndpoint(name, path, address string) (Endpoint, error) @@ -52,6 +56,7 @@ type Model interface { GetEndpointByName(name string) (Endpoint, error) GetEndpointByPath(path string) (Endpoint, error) GetEndpointByAddress(address string) (Endpoint, error) + AllEndpoints() ([]Endpoint, error) } @@ -100,7 +105,7 @@ func (p *Phlox) Create(filename string) error { insert into schema values(0); create table users (userid integer not null primary key, username string, passwordhash string, salt string); - create table sessions (sessionid string not null primary key, userid integer, foreign key(userid) references users(userid)); + create table sessions (sessionid string not null primary key, userid integer, created string, modified string, foreign key(userid) references users(userid)); create table endpoints (endpointid integer not null primary key, name string, path string, address string); `) if err != nil { -- cgit v1.2.1