Initial hello world
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.idea/
|
||||
44
application/index.go
Normal file
44
application/index.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
lp := filepath.Join("application", "layouts", "main.html")
|
||||
fp := filepath.Join("application", "views", "index.html")
|
||||
|
||||
// Return a 404 if the template doesn't exist
|
||||
info, err := os.Stat(fp)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Return a 404 if the request is for a directory
|
||||
if info.IsDir() {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(lp, fp)
|
||||
if err != nil {
|
||||
// Log the detailed error
|
||||
log.Print(err.Error())
|
||||
// Return a generic "Internal Server Error" message
|
||||
http.Error(w, http.StatusText(500), 500)
|
||||
return
|
||||
}
|
||||
|
||||
err = tmpl.ExecuteTemplate(w, "main.html", nil)
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
http.Error(w, http.StatusText(500), 500)
|
||||
}
|
||||
}
|
||||
15
application/layouts/main.html
Normal file
15
application/layouts/main.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Hello, World!</title>
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href="/static/css/bootstrap.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
{{block "content" .}} {{end}}
|
||||
<!-- Bootstrap JS and dependencies -->
|
||||
<script src="/static/js/bootstrap.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
11
application/server.go
Normal file
11
application/server.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetupAppServer() {
|
||||
fs := http.FileServer(http.Dir("./application/static"))
|
||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||
http.HandleFunc("/", index)
|
||||
}
|
||||
10837
application/static/css/bootstrap.css
vendored
Normal file
10837
application/static/css/bootstrap.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5016
application/static/js/bootstrap.js
vendored
Normal file
5016
application/static/js/bootstrap.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10
application/views/index.html
Normal file
10
application/views/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{{define "content"}}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col text-center">
|
||||
<h1 class="mt-5">Hello, World!</h1>
|
||||
<p class="lead">This is a simple Bootstrap 5 "Hello, World!" page.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
96
db/db.go
Normal file
96
db/db.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var (
|
||||
db *sql.DB
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
func InitDB() {
|
||||
once.Do(func() {
|
||||
var err error
|
||||
db, err = sql.Open("sqlite3", "./risklet.db")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
createTables()
|
||||
})
|
||||
}
|
||||
|
||||
func createTables() {
|
||||
companyTable := `
|
||||
CREATE TABLE IF NOT EXISTS Company (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
UUID TEXT NOT NULL,
|
||||
Name TEXT NOT NULL,
|
||||
TaxId TEXT NOT NULL,
|
||||
Email TEXT NOT NULL,
|
||||
Password TEXT NOT NULL
|
||||
);`
|
||||
|
||||
basicProfileTable := `
|
||||
CREATE TABLE IF NOT EXISTS BasicProfile (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
CompanyId INTEGER,
|
||||
Employees TEXT,
|
||||
Revenue TEXT,
|
||||
Applications TEXT,
|
||||
Compliance TEXT,
|
||||
Industry TEXT,
|
||||
ITDependency TEXT,
|
||||
DataSensitivity TEXT,
|
||||
DataVolume TEXT,
|
||||
NetworkSegmentation TEXT,
|
||||
LegacySystems TEXT,
|
||||
IoTIntegration TEXT,
|
||||
RemoteWork TEXT,
|
||||
BYOD TEXT,
|
||||
VPN TEXT,
|
||||
API TEXT,
|
||||
VendorAccess TEXT,
|
||||
InternalDev TEXT,
|
||||
FOREIGN KEY (CompanyId) REFERENCES Company(id)
|
||||
);`
|
||||
|
||||
advancedProfileTable := `
|
||||
CREATE TABLE IF NOT EXISTS AdvancedProfile (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
CompanyId INTEGER,
|
||||
GeographicDistribution TEXT,
|
||||
CustomerConcentration TEXT,
|
||||
ProductServicePortfolio TEXT,
|
||||
OrganizationalCulture TEXT,
|
||||
SupplierDiversity TEXT,
|
||||
TechnologicalInfrastructure TEXT,
|
||||
IntellectualProperty TEXT,
|
||||
ManagementTeamExperience TEXT,
|
||||
FOREIGN KEY (CompanyId) REFERENCES Company(id)
|
||||
);`
|
||||
|
||||
_, err := db.Exec(companyTable)
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating Company table: %v", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec(basicProfileTable)
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating BasicProfile table: %v", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec(advancedProfileTable)
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating AdvancedProfile table: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func GetDB() *sql.DB {
|
||||
return db
|
||||
}
|
||||
6
go.mod
Normal file
6
go.mod
Normal file
@@ -0,0 +1,6 @@
|
||||
module risklet
|
||||
|
||||
go 1.23.2
|
||||
|
||||
require github.com/mattn/go-sqlite3 v1.14.24
|
||||
require github.com/gin-gonic/gin v1.10.0
|
||||
3
go.sum
Normal file
3
go.sum
Normal file
@@ -0,0 +1,3 @@
|
||||
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
|
||||
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
18
main.go
Normal file
18
main.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"risklet/application"
|
||||
"risklet/db"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db.InitDB()
|
||||
application.SetupAppServer()
|
||||
log.Print("Listening on :3000....")
|
||||
err := http.ListenAndServe(":3000", nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
BIN
risklet.db
Normal file
BIN
risklet.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user