Skip to content
Snippets Groups Projects
main.go 816 B
Newer Older
package main

import (
Gabriel Zachmann's avatar
Gabriel Zachmann committed
	log "github.com/sirupsen/logrus"
Gabriel Zachmann's avatar
Gabriel Zachmann committed
	"github.com/zachmann/mytoken/internal/server/config"
	"github.com/zachmann/mytoken/internal/server/db"
	loggerUtils "github.com/zachmann/mytoken/internal/server/utils/logger"
)

func main() {
	config.Load()
Gabriel Zachmann's avatar
Gabriel Zachmann committed
	loggerUtils.Init()
	if err := db.Connect(); err != nil {
Gabriel Zachmann's avatar
Gabriel Zachmann committed
		log.WithError(err).Fatal()
	deleteExpiredTransferCodes()
	deleteExpiredAuthInfo()
}

func deleteExpiredTransferCodes() {
	if _, err := db.DB().Exec(`DELETE FROM ProxyTokens WHERE id = ANY(SELECT id FROM TransferCodesAttributes WHERE expires_at < CURRENT_TIMESTAMP())`); err != nil {
Gabriel Zachmann's avatar
Gabriel Zachmann committed
		log.WithError(err).Error()
	}
}

func deleteExpiredAuthInfo() {
	if _, err := db.DB().Exec(`DELETE FROM AuthInfo WHERE expires_at < CURRENT_TIMESTAMP()`); err != nil {
Gabriel Zachmann's avatar
Gabriel Zachmann committed
		log.WithError(err).Error()