Add basic html pages and css.
This commit is contained in:
parent
ffa70e8f55
commit
b8c985db04
33
main.go
33
main.go
@ -5,8 +5,10 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"net/http"
|
||||
"path"
|
||||
)
|
||||
|
||||
type Result struct {
|
||||
@ -15,10 +17,15 @@ type Result struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Setup handlers
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", getRoot)
|
||||
mux.HandleFunc("/result", getResult)
|
||||
|
||||
// Server static files (css)
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
|
||||
// Setup the server
|
||||
err := http.ListenAndServe(":3333", mux)
|
||||
if errors.Is(err, http.ErrServerClosed) {
|
||||
fmt.Println("server closed")
|
||||
@ -66,10 +73,32 @@ func getResult(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
fmt.Println("got /result request")
|
||||
fmt.Println(result.Message)
|
||||
io.WriteString(w, result.Message)
|
||||
|
||||
// Get the html template and serve it
|
||||
fp := path.Join("templates", "result.html")
|
||||
tmpl, err := template.ParseFiles(fp)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err := tmpl.Execute(w, result); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func getRoot(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("got / request")
|
||||
io.WriteString(w, "This is my website!")
|
||||
|
||||
// Get the html template and serve it
|
||||
fp := path.Join("templates", "index.html")
|
||||
tmpl, err := template.ParseFiles(fp)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err := tmpl.Execute(w, nil); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
29
static/css/index.css
Normal file
29
static/css/index.css
Normal file
@ -0,0 +1,29 @@
|
||||
body{
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #303446;
|
||||
color: #c6d0f5;
|
||||
}
|
||||
|
||||
input[type=text] {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
height: 40px;
|
||||
font-size: 20px;
|
||||
width: 100%;
|
||||
border: none;
|
||||
background-color: #414559;
|
||||
color: #c6d0f5;
|
||||
}
|
||||
|
||||
.main {
|
||||
display: block;
|
||||
margin: auto;
|
||||
text-align: center;
|
||||
width: 50%;
|
||||
}
|
20
templates/index.html
Normal file
20
templates/index.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="stylesheet" href="/static/css/index.css" type="text/css" media="all">
|
||||
<title>Goffy</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="main">
|
||||
<p>Provjerite jeli stranica lazna.</p>
|
||||
<form id="searchform" action="/result?url=" method="get">
|
||||
<input id="search" placeholder="URL stranice" type="text" name="url" autocomplete="off" data-type="query" />
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
21
templates/result.html
Normal file
21
templates/result.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="stylesheet" href="/static/css/index.css" type="text/css" media="all">
|
||||
<title>Goffy</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="main">
|
||||
<p>{{ .Message }}</p>
|
||||
<form id="searchform" action="/result?url=" method="get">
|
||||
<input id="search" placeholder="Unesite novi URL" type="text" name="url" autocomplete="off"
|
||||
data-type="query" />
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user