Compare commits
No commits in common. "bfc14ce7170d1fa0335bc46bd602d986b9cfc2d8" and "dc7631ede28ec281758af37ff95ffa8996517b29" have entirely different histories.
bfc14ce717
...
dc7631ede2
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.5 KiB |
|
@ -1,17 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta name="charset" content="utf-8" />
|
||||
<title>barcodes</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.png" />
|
||||
<!-- CSS and JS Inclusions -->
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="author" content="Frederick Boniface" />
|
||||
<meta name="description" content="Easily create a variety of barcodes" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ template "title" }}</h1>
|
||||
{{ template "body" . }}
|
||||
</body>
|
||||
</html>
|
|
@ -1,5 +1,12 @@
|
|||
{{ define "title" }}API Documentation{{ end }}
|
||||
{{ define "body" }}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>API Documentation</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>API Requests</h1>
|
||||
|
||||
<p>API Requests can be made by making a POST request to /generate</p>
|
||||
|
||||
<p>The request body should be JSON similar to the below</p>
|
||||
|
@ -30,4 +37,5 @@
|
|||
<p><code>content</code> should be the value you wish the barcode to display. This should be a string and may not accept all characters - that is dependent on the barcode type.</p>
|
||||
|
||||
<p>The response will be a PNG image</p>
|
||||
{{ end }}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
|
@ -23,14 +22,11 @@ func helpTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
BarcodeOptions: barcodeOptions,
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles("templates/base.html", "templates/help.html")
|
||||
tmpl := template.Must(template.New("help.html").ParseFiles("templates/help.html"))
|
||||
|
||||
err := tmpl.Execute(w, data)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing templates: ", err)
|
||||
http.Error(w, "Unable to parse templates", 500)
|
||||
}
|
||||
err = tmpl.Execute(w, data)
|
||||
if err != nil {
|
||||
fmt.Println("Error rendering templates: ", err)
|
||||
http.Error(w, "Unable to render templates", 500)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func mainHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("Request URL: ", r.URL.Path)
|
||||
requestFile := strings.TrimRight(r.URL.Path, "/")
|
||||
requestFile = strings.TrimRight(requestFile, ".html")
|
||||
fmt.Println("Template File: ", requestFile)
|
||||
}
|
|
@ -6,10 +6,9 @@ import (
|
|||
)
|
||||
|
||||
func StartServer() {
|
||||
// What I want to do here is server from /static
|
||||
// if the resource exists, else try to render from /templates
|
||||
// if the template exists. Else return 404.
|
||||
http.HandleFunc("/", mainHandler)
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Barcodes")
|
||||
})
|
||||
|
||||
http.HandleFunc("/help", helpTemplate)
|
||||
|
||||
|
|
Loading…
Reference in New Issue