Skip to content
Snippets Groups Projects
Commit bc9e1250 authored by Gabriel Zachmann's avatar Gabriel Zachmann
Browse files

add db garbage collector

parent d2c8e58f
No related branches found
No related tags found
No related merge requests found
package main
import (
"log"
"github.com/zachmann/mytoken/internal/config"
"github.com/zachmann/mytoken/internal/db"
)
func main() {
config.Load()
if err := db.Connect(); err != nil {
log.Fatal(err)
}
deleteExpiredPollingCodes()
deleteExpiredAuthInfo()
}
func deleteExpiredPollingCodes() {
if _, err := db.DB().Exec(`DELETE FROM PollingCodes WHERE expires_at < CURRENT_TIMESTAMP()`); err != nil {
log.Printf("%s", err)
}
}
func deleteExpiredAuthInfo() {
if _, err := db.DB().Exec(`DELETE FROM AuthInfo WHERE expires_at < CURRENT_TIMESTAMP()`); err != nil {
log.Printf("%s", err)
}
}
......@@ -3,7 +3,7 @@ package main
import (
"github.com/zachmann/mytoken/internal/config"
"github.com/zachmann/mytoken/internal/db"
"github.com/zachmann/mytoken/internal/endpoints/configuration"
configurationEndpoint "github.com/zachmann/mytoken/internal/endpoints/configuration"
"github.com/zachmann/mytoken/internal/jws"
"github.com/zachmann/mytoken/internal/oidc/authcode"
"github.com/zachmann/mytoken/internal/server"
......@@ -11,10 +11,9 @@ import (
func main() {
config.Load()
configuration.Init()
configurationEndpoint.Init()
authcode.Init()
err := db.Connect()
if err != nil {
if err := db.Connect(); err != nil {
panic(err)
}
jws.LoadKey()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment