backend need to be rewrited to go
legacy code in archive folder
This commit is contained in:
parent
51a73350ae
commit
39c1b7d2d0
38
cmd/admin_backend/main.go
Normal file
38
cmd/admin_backend/main.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"admin_dashboard_backend/pkg/handlers"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
configFile, err := os.ReadFile("config.json")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error loading config.json file:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var config struct {
|
||||||
|
Port json.Number `json:"serverPort"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(configFile, &config); err != nil {
|
||||||
|
log.Fatal("Error parsing config.json:", err)
|
||||||
|
}
|
||||||
|
port := config.Port.String()
|
||||||
|
if port == "" {
|
||||||
|
port = "84" // default port
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define routes
|
||||||
|
http.HandleFunc("/welcome", handlers.HandlersWelcome)
|
||||||
|
|
||||||
|
// Start server
|
||||||
|
fmt.Printf("Server is running on port %s...\n", port)
|
||||||
|
if err := http.ListenAndServe(":"+port, nil); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
24
pkg/handlers/welcome.go
Normal file
24
pkg/handlers/welcome.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandlersWelcome(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodGet {
|
||||||
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response := Response{
|
||||||
|
Message: "Welcome to the API!",
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user