-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e90044
commit 20dc76d
Showing
11 changed files
with
19,425 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/harisheoran/my-chat-client | ||
|
||
go 1.23.3 | ||
|
||
require github.com/gorilla/mux v1.8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= | ||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
func main() { | ||
mainRouter := mux.NewRouter() | ||
|
||
mainRouter.HandleFunc("/v1/health", healthHandler) | ||
mainRouter.HandleFunc("/v1/chat", homeHandler) | ||
mainRouter.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./ui/static")))) | ||
|
||
log.Println("client listening on port 5000") | ||
err := http.ListenAndServe(":5000", mainRouter) | ||
if err != nil { | ||
log.Fatal("Unable to start the server", err) | ||
} | ||
} | ||
|
||
func healthHandler(w http.ResponseWriter, request *http.Request) { | ||
fmt.Fprintf(w, "my-chat-system client health is OK!") | ||
} | ||
|
||
func homeHandler(w http.ResponseWriter, request *http.Request) { | ||
uiTemplates := "ui/main.html" | ||
templates, err := template.ParseFiles(uiTemplates) | ||
if err != nil { | ||
log.Println("ERROR: parsing the template files", err) | ||
} | ||
templates.Execute(w, nil) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Bootstrap demo</title> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> | ||
<link rel='stylesheet' href='/static/css/main.css'> | ||
</head> | ||
<body> | ||
<section> | ||
<div class="container py-5"> | ||
|
||
<div class="row"> | ||
|
||
<div class="col-md-6 col-lg-5 col-xl-4 mb-4 mb-md-0"> | ||
|
||
<h5 class="font-weight-bold mb-3 text-center text-lg-start">My Chat System</h5> | ||
|
||
<div class="card"> | ||
<div class="card-body"> | ||
|
||
<ul class="list-unstyled mb-0"> | ||
<li class="p-2 border-bottom bg-body-tertiary"> | ||
<a href="#!" class="d-flex justify-content-between"> | ||
<div class="d-flex flex-row"> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-8.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-center me-3 shadow-1-strong" width="60"> | ||
<div class="pt-1"> | ||
<p class="fw-bold mb-0">Common Room</p> | ||
<p class="small text-muted">Hello, Are you there?</p> | ||
</div> | ||
</div> | ||
<div class="pt-1"> | ||
<p class="small text-muted mb-1">Just now</p> | ||
<span class="badge bg-danger float-end">1</span> | ||
</div> | ||
</a> | ||
</li> | ||
<li class="p-2 border-bottom"> | ||
<a href="#!" class="d-flex justify-content-between"> | ||
<div class="d-flex flex-row"> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-1.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-center me-3 shadow-1-strong" width="60"> | ||
<div class="pt-1"> | ||
<p class="fw-bold mb-0">Danny Smith</p> | ||
<p class="small text-muted">Lorem ipsum dolor sit.</p> | ||
</div> | ||
</div> | ||
<div class="pt-1"> | ||
<p class="small text-muted mb-1">5 mins ago</p> | ||
</div> | ||
</a> | ||
</li> | ||
<li class="p-2 border-bottom"> | ||
<a href="#!" class="d-flex justify-content-between"> | ||
<div class="d-flex flex-row"> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-2.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-center me-3 shadow-1-strong" width="60"> | ||
<div class="pt-1"> | ||
<p class="fw-bold mb-0">Alex Steward</p> | ||
<p class="small text-muted">Lorem ipsum dolor sit.</p> | ||
</div> | ||
</div> | ||
<div class="pt-1"> | ||
<p class="small text-muted mb-1">Yesterday</p> | ||
</div> | ||
</a> | ||
</li> | ||
<li class="p-2 border-bottom"> | ||
<a href="#!" class="d-flex justify-content-between"> | ||
<div class="d-flex flex-row"> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-3.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-center me-3 shadow-1-strong" width="60"> | ||
<div class="pt-1"> | ||
<p class="fw-bold mb-0">Ashley Olsen</p> | ||
<p class="small text-muted">Lorem ipsum dolor sit.</p> | ||
</div> | ||
</div> | ||
<div class="pt-1"> | ||
<p class="small text-muted mb-1">Yesterday</p> | ||
</div> | ||
</a> | ||
</li> | ||
<li class="p-2 border-bottom"> | ||
<a href="#!" class="d-flex justify-content-between"> | ||
<div class="d-flex flex-row"> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-4.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-center me-3 shadow-1-strong" width="60"> | ||
<div class="pt-1"> | ||
<p class="fw-bold mb-0">Kate Moss</p> | ||
<p class="small text-muted">Lorem ipsum dolor sit.</p> | ||
</div> | ||
</div> | ||
<div class="pt-1"> | ||
<p class="small text-muted mb-1">Yesterday</p> | ||
</div> | ||
</a> | ||
</li> | ||
<li class="p-2 border-bottom"> | ||
<a href="#!" class="d-flex justify-content-between"> | ||
<div class="d-flex flex-row"> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-5.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-center me-3 shadow-1-strong" width="60"> | ||
<div class="pt-1"> | ||
<p class="fw-bold mb-0">Lara Croft</p> | ||
<p class="small text-muted">Lorem ipsum dolor sit.</p> | ||
</div> | ||
</div> | ||
<div class="pt-1"> | ||
<p class="small text-muted mb-1">Yesterday</p> | ||
</div> | ||
</a> | ||
</li> | ||
<li class="p-2"> | ||
<a href="#!" class="d-flex justify-content-between"> | ||
<div class="d-flex flex-row"> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-6.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-center me-3 shadow-1-strong" width="60"> | ||
<div class="pt-1"> | ||
<p class="fw-bold mb-0">Brad Pitt</p> | ||
<p class="small text-muted">Lorem ipsum dolor sit.</p> | ||
</div> | ||
</div> | ||
<div class="pt-1"> | ||
<p class="small text-muted mb-1">5 mins ago</p> | ||
<span class="text-muted float-end"><i class="fas fa-check" aria-hidden="true"></i></span> | ||
</div> | ||
</a> | ||
</li> | ||
</ul> | ||
|
||
</div> | ||
</div> | ||
|
||
</div> | ||
|
||
<div class="col-md-6 col-lg-7 col-xl-8"> | ||
|
||
<ul class="list-unstyled"> | ||
<li class="d-flex justify-content-between mb-4"> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-6.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-start me-3 shadow-1-strong" width="60"> | ||
<div class="card"> | ||
<div class="card-header d-flex justify-content-between p-3"> | ||
<p class="fw-bold mb-0">Brad Pitt</p> | ||
<p class="text-muted small mb-0"><i class="far fa-clock"></i> 12 mins ago</p> | ||
</div> | ||
<div class="card-body"> | ||
<p class="mb-0"> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut | ||
labore et dolore magna aliqua. | ||
</p> | ||
</div> | ||
</div> | ||
</li> | ||
<li class="d-flex justify-content-between mb-4"> | ||
<div class="card w-100"> | ||
<div class="card-header d-flex justify-content-between p-3"> | ||
<p class="fw-bold mb-0">Lara Croft</p> | ||
<p class="text-muted small mb-0"><i class="far fa-clock"></i> 13 mins ago</p> | ||
</div> | ||
<div class="card-body"> | ||
<p class="mb-0"> | ||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque | ||
laudantium. | ||
</p> | ||
</div> | ||
</div> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-5.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-start ms-3 shadow-1-strong" width="60"> | ||
</li> | ||
<li class="d-flex justify-content-between mb-4"> | ||
<img src="https://mdbcdn.b-cdn.net/img/Photos/Avatars/avatar-6.webp" alt="avatar" | ||
class="rounded-circle d-flex align-self-start me-3 shadow-1-strong" width="60"> | ||
<div class="card"> | ||
<div class="card-header d-flex justify-content-between p-3"> | ||
<p class="fw-bold mb-0">Brad Pitt</p> | ||
<p class="text-muted small mb-0"><i class="far fa-clock"></i> 10 mins ago</p> | ||
</div> | ||
<div class="card-body"> | ||
<p class="mb-0"> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut | ||
labore et dolore magna aliqua. | ||
</p> | ||
</div> | ||
</div> | ||
</li> | ||
|
||
<!-- chat form --> | ||
<li class="bg-white mb-3"> | ||
<div data-mdb-input-init class="form-outline"> | ||
<textarea class="form-control bg-body-tertiary" id="textAreaExample2" rows="4"></textarea> | ||
<label class="form-label" for="textAreaExample2">Message</label> | ||
</div> | ||
</li> | ||
<button type="button" data-mdb-button-init data-mdb-ripple-init class="btn btn-info btn-rounded float-end">Send</button> | ||
</ul> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
</div> | ||
</section> | ||
|
||
|
||
|
||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>my chat system</title> | ||
<script type="text/javascript"> | ||
window.onload = function () { | ||
var conn; | ||
var msg = document.getElementById("msg"); | ||
var log = document.getElementById("log"); | ||
|
||
function appendLog(item) { | ||
var doScroll = | ||
log.scrollTop > log.scrollHeight - log.clientHeight - 1; | ||
log.appendChild(item); | ||
if (doScroll) { | ||
log.scrollTop = log.scrollHeight - log.clientHeight; | ||
} | ||
} | ||
|
||
document.getElementById("form").onsubmit = function () { | ||
if (!conn) { | ||
return false; | ||
} | ||
if (!msg.value) { | ||
return false; | ||
} | ||
conn.send(msg.value); | ||
msg.value = ""; | ||
return false; | ||
}; | ||
|
||
if (window["WebSocket"]) { | ||
conn = new WebSocket("ws://13.203.105.149:1316/v1/chat"); | ||
|
||
conn.onopen = function () { | ||
console.log("WebSocket connection established."); | ||
}; | ||
|
||
conn.onerror = function (error) { | ||
console.error("WebSocket error:", error); | ||
}; | ||
conn.onclose = function (evt) { | ||
var item = document.createElement("div"); | ||
item.innerHTML = "<b>Connection closed.</b>"; | ||
appendLog(item); | ||
}; | ||
conn.onmessage = function (evt) { | ||
var messages = evt.data.split("\n"); | ||
for (var i = 0; i < messages.length; i++) { | ||
var item = document.createElement("div"); | ||
item.innerText = messages[i]; | ||
appendLog(item); | ||
} | ||
}; | ||
} else { | ||
var item = document.createElement("div"); | ||
item.innerHTML = | ||
"<b>Your browser does not support WebSockets.</b>"; | ||
appendLog(item); | ||
} | ||
}; | ||
</script> | ||
<style type="text/css"> | ||
html { | ||
overflow: hidden; | ||
} | ||
|
||
body { | ||
overflow: hidden; | ||
padding: 0; | ||
margin: 0; | ||
width: 100%; | ||
height: 100%; | ||
background: gray; | ||
} | ||
|
||
#log { | ||
background: white; | ||
margin: 0; | ||
padding: 0.5em 0.5em 0.5em 0.5em; | ||
position: absolute; | ||
top: 0.5em; | ||
left: 0.5em; | ||
right: 0.5em; | ||
bottom: 3em; | ||
overflow: auto; | ||
} | ||
|
||
#form { | ||
padding: 0 0.5em 0 0.5em; | ||
margin: 0; | ||
position: absolute; | ||
bottom: 1em; | ||
left: 0px; | ||
width: 100%; | ||
overflow: hidden; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="log"></div> | ||
<form id="form"> | ||
<input type="submit" value="Send" /> | ||
<input type="text" id="msg" size="64" autofocus /> | ||
</form> | ||
</body> | ||
</html> |
Oops, something went wrong.