Add redis connection test before start
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/pr/release Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pull_request_closed/release Pipeline was successful
ci/woodpecker/pull_request_closed/build Pipeline was successful

This commit is contained in:
Ada 2024-02-21 14:22:40 +01:00
parent 04dad7d5af
commit 130a5ee345
Signed by: ada
GPG key ID: 6A7F898157C6DE6E
3 changed files with 21 additions and 0 deletions

View file

@ -32,6 +32,15 @@ func ConnectDB(dbConfig *redis.Options) *redis.Client {
return localDb
}
// Ping test connection to Redis database
func Ping(db *redis.Client) error {
status := db.Ping(ctx)
if status.String() != "ping: PONG" {
return &PingError{}
}
return nil
}
func (config DBConfig) InsertPaste(key string, content string, secret string, ttl time.Duration) {
type dbSchema struct {
content string

View file

@ -0,0 +1,7 @@
package database
type PingError struct{}
func (m *PingError) Error() string {
return "Connection to redis not work"
}

View file

@ -2,6 +2,7 @@ package main
import (
"embed"
"log"
"git.gnous.eu/gnouseu/plakken/internal/config"
"git.gnous.eu/gnouseu/plakken/internal/database"
@ -19,6 +20,10 @@ func main() {
initConfig := config.GetConfig()
dbConfig := database.InitDB(initConfig.RedisAddress, initConfig.RedisUser, initConfig.RedisPassword, initConfig.RedisDB)
db := database.ConnectDB(dbConfig)
err := database.Ping(db)
if err != nil {
log.Fatal(err)
}
serverConfig := httpServer.ServerConfig{
HTTPServer: httpServer.Config(initConfig.ListenAddress),