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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
http://localhost:3000
/ready
/redis/ready
/sqlite/ready
/sql/ready
/sql/create/user/table
```


Expand Down
Binary file modified bin/main
Binary file not shown.
63 changes: 63 additions & 0 deletions src/handlers/sql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package handlers

import (
"GoRedis/src/services"
"GoRedis/src/utils"
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
)

func sqlRouteError(err string, w http.ResponseWriter) {
log.Println(utils.TextRed(err))
errResponse := &utils.HTTPResponse{Message: err, Status: http.StatusBadRequest}
errResponseJson, _ := json.Marshal(errResponse)
fmt.Fprint(w, string(errResponseJson))
}

func SQLReadyHandler(w http.ResponseWriter, r *http.Request) {
route := utils.SQLReadyRoute + " "

if r.Method == "GET" {
db, err := services.CreateSQLInstance()

if err != nil {
sqlRouteError(err.Error(), w)
return
}
defer db.Close()

response := &utils.HTTPResponse{Message: "SQLite is ready", Status: http.StatusOK}
responseJson, _ := json.Marshal(response)
log.Print(utils.TextGreen(route + strconv.Itoa(response.Status)))
fmt.Fprint(w, string(responseJson))
return
}

log.Print(utils.TextRed(route + strconv.Itoa(http.StatusMethodNotAllowed)))
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}

func SQLCreateUserTableHandler(w http.ResponseWriter, r *http.Request) {
route := utils.SQLCreateUserTableRoute + " "

if r.Method == "GET" {
err := services.CreateSQLUserTable()

if err != nil {
sqlRouteError(err.Error(), w)
return
}

response := &utils.HTTPResponse{Message: "Successfully created the user table.", Status: http.StatusOK}
responseJson, _ := json.Marshal(response)
log.Print(utils.TextGreen(route + strconv.Itoa(response.Status)))
fmt.Fprint(w, string(responseJson))
return
}

log.Print(utils.TextRed(route + strconv.Itoa(http.StatusMethodNotAllowed)))
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
}
30 changes: 0 additions & 30 deletions src/handlers/sqlite.go

This file was deleted.

3 changes: 2 additions & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func main() {
// * These are all the server routes.
http.HandleFunc("/ready", handlers.ReadyHandler)
http.HandleFunc("/redis/ready", handlers.RedisReadyHandler)
http.HandleFunc("/sqlite/ready", handlers.SQLiteReadyHandler)
http.HandleFunc("/sql/ready", handlers.SQLReadyHandler)
http.HandleFunc("/sql/create/user/table", handlers.SQLCreateUserTableHandler)

// * You can setup the server here.
s := &http.Server{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func CreateSQLInstance() (*sql.DB, error) {
return db, nil
}

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

if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions src/utils/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package utils

const (
ReadyRoute = "/ready"
RedisReadyRoute = "/redis/ready"
SQLReadyRoute = "/database/ready"
ReadyRoute = "/ready"
RedisReadyRoute = "/redis/ready"
SQLReadyRoute = "/sql/ready"
SQLCreateUserTableRoute = "/sql/create/user/table"
)