Merge pull request #1 from ProjectSegfault/akis-stuff

add a form example
This commit is contained in:
Odyssey346 2022-07-29 14:46:12 +02:00 committed by GitHub
commit cf8af15bf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 0 deletions

12
main.go
View File

@ -12,6 +12,7 @@ import (
type StaticThingy struct { type StaticThingy struct {
Port string Port string
HCaptchaSiteKey string
} }
var port string var port string
@ -22,6 +23,7 @@ func main() {
otherthings.CheckEnv() otherthings.CheckEnv()
log.Println("[HTTP] Starting server") log.Println("[HTTP] Starting server")
port := os.Getenv("SEGFAUTILITIES_PORT") port := os.Getenv("SEGFAUTILITIES_PORT")
hcaptcha_site_key := os.Getenv("SEGFAUTILITIES_PORT")
tmpl := template.Must(template.ParseFiles("static/index.html")) tmpl := template.Must(template.ParseFiles("static/index.html"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := StaticThingy{ data := StaticThingy{
@ -29,6 +31,16 @@ func main() {
} }
tmpl.Execute(w, data) tmpl.Execute(w, data)
}) })
tmpl_form := template.Must(template.ParseFiles("static/form.html"))
http.HandleFunc("/form/", func(w http.ResponseWriter, r *http.Request) {
data := StaticThingy{
Port: port,
HCaptchaSiteKey: hcaptcha_site_key,
}
tmpl_form.Execute(w, data)
})
http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "welcome to hell") io.WriteString(w, "welcome to hell")
}) })

57
static/form.html Normal file
View File

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Segfautilites form implementation example</title>
<style>
body {
background-color: #252525;
color: #fff;
font-family: 'JetBrains Mono', 'JetBrainsMono Nerd Font', monospace
}
a {
color: #00d4aa;
}
a:hover {
color: #4beacb;
}
</style>
<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
</head>
<body>
<form
action="/api/form"
method="POST"
>
<div class="meta">
<input
type="text"
name="email"
placeholder="Your email"
required
/>
<select id="commentType" name="commentType" required>
<option value="" selected disabled>Select a type of comment</option>
<option value="Feedback">Feedback</option>
<option value="Suggestion">Suggestion</option>
<option value="Question">Question</option>
<option value="Bug">Bug</option>
</select>
</div>
<textarea
id="comment"
name="message"
rows="4"
cols="25"
required
placeholder="Your message"
></textarea>
<div class="h-captcha" data-sitekey="{{.HCaptchaSiteKey}}"></div>
<input type="submit" value="Submit" />
</form>
</body>
</html>

View File

@ -1,5 +1,9 @@
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Segfautilites</title>
<style> <style>
body { body {
background-color: #252525; background-color: #252525;
@ -19,4 +23,5 @@
<body> <body>
<h1>Welcome to Segfautilities</h1> <h1>Welcome to Segfautilities</h1>
<h3>Running at port {{.Port}} | <a href="https://github.com/ProjectSegfault/segfautilities/" target="_blank">GitHub</a></h3> <h3>Running at port {{.Port}} | <a href="https://github.com/ProjectSegfault/segfautilities/" target="_blank">GitHub</a></h3>
<h3><a href="/form">Click here for an example form implementation</a></h3>
</body> </body>