Skip to content
This repository was archived by the owner on Mar 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed database/database.sql
Empty file.
Binary file added database/sqlite.db
Binary file not shown.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ module GoRedis

go 1.24.4

require github.com/redis/go-redis/v9 v9.11.0
require (
github.com/mattn/go-sqlite3 v1.14.32
github.com/redis/go-redis/v9 v9.11.0
)

require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/mattn/go-sqlite3 v1.14.32 // indirect
)
3 changes: 2 additions & 1 deletion src/handlers/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
)

func ReadyHandler(w http.ResponseWriter, r *http.Request) {
route := utils.ReadyRoute + " "
response := &utils.HTTPResponse{Message: "Server is ready.", Status: 200}
responseJson, _ := json.Marshal(response)

log.Print(utils.TextGreen("/ready " + strconv.Itoa(response.Status)))
log.Print(utils.TextGreen(route + strconv.Itoa(response.Status)))
fmt.Fprint(w, string(responseJson))
}
5 changes: 3 additions & 2 deletions src/handlers/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (

func RedisReadyHandler(w http.ResponseWriter, r *http.Request) {
ctx := context.Background()
route := utils.ReadyRoute + " "
redisClient := services.NewRedisClient()
_, err := redisClient.Ping(ctx).Result()

if err != nil {
log.Print(utils.TextRed("/redis/ready " + strconv.Itoa(500)))
log.Print(utils.TextRed(route + strconv.Itoa(500)))
errorResponse := &utils.HTTPResponse{Message: "Failed redis connection.", Status: 500}
errorResponseJson, _ := json.Marshal(errorResponse)
fmt.Fprint(w, string(errorResponseJson))
Expand All @@ -26,6 +27,6 @@ func RedisReadyHandler(w http.ResponseWriter, r *http.Request) {

response := &utils.HTTPResponse{Message: "Redis is ready.", Status: 200}
responseJson, _ := json.Marshal(response)
log.Print(utils.TextGreen("/redis/ready " + strconv.Itoa(response.Status)))
log.Print(utils.TextGreen(route + strconv.Itoa(response.Status)))
fmt.Fprint(w, string(responseJson))
}
15 changes: 14 additions & 1 deletion src/handlers/sqlite.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handlers

import (
"GoRedis/src/services"
"GoRedis/src/utils"
"encoding/json"
"fmt"
Expand All @@ -10,8 +11,20 @@ import (
)

func SQLiteReadyHandler(w http.ResponseWriter, r *http.Request) {
route := utils.SQLReadyRoute + " "
err := services.SQLCreateTable()

if err != nil {
fmt.Println(utils.TextRed(err.Error()))
errResponse := &utils.HTTPResponse{Message: "Something is wrong", Status: 500}
errResponseJson, _ := json.Marshal(errResponse)
log.Print(utils.TextRed(route + strconv.Itoa(errResponse.Status)))
fmt.Fprint(w, string(errResponseJson))
return
}

response := &utils.HTTPResponse{Message: "SQLite is ready", Status: 200}
responseJson, _ := json.Marshal(response)
log.Print(utils.TextGreen("/sqlite/ready " + strconv.Itoa(response.Status)))
log.Print(utils.TextGreen(route + strconv.Itoa(response.Status)))
fmt.Fprint(w, string(responseJson))
}
44 changes: 44 additions & 0 deletions src/services/sqlite_service.go
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
package services

import (
"GoRedis/src/utils"
"database/sql"
"fmt"

_ "github.com/mattn/go-sqlite3"
)

func CreateSQLInstance() (*sql.DB, error) {
db, err := sql.Open("sqlite3", "database/sqlite.db")

if err != nil {
return nil, err
}

return db, nil
}

func SQLCreateTable() error {
db, err := CreateSQLInstance()

if err != nil {
return err
}

defer db.Close()

createTableStatement := `
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE
);`

_, err = db.Exec(createTableStatement)

if err != nil {
fmt.Println(utils.TextRed(err.Error()))
return err
}

return nil
}
7 changes: 7 additions & 0 deletions src/utils/routes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package utils

const (
ReadyRoute = "/ready"
RedisReadyRoute = "/redis/ready"
SQLReadyRoute = "/database/ready"
)
22 changes: 0 additions & 22 deletions vendor/github.com/cespare/xxhash/v2/LICENSE.txt

This file was deleted.

74 changes: 0 additions & 74 deletions vendor/github.com/cespare/xxhash/v2/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions vendor/github.com/cespare/xxhash/v2/testall.sh

This file was deleted.

Loading