cleaning up, early http server draft
This commit is contained in:
40
http/http.go
Normal file
40
http/http.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"log"
|
||||
)
|
||||
|
||||
type imageTransform struct {
|
||||
image.Image
|
||||
TransformFunc func(image.Image) image.Image
|
||||
}
|
||||
|
||||
func (t imageTransform) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func indexHTML(w http.ResponseWriter, r *http.Request) {
|
||||
f, err := os.Open("index.html")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
log.Fatalln("error opening file:", err)
|
||||
return
|
||||
}
|
||||
_, err := io.Copy(w, f)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
log.Println("copy error:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", indexHTML)
|
||||
http.Handle("POST /upload", imageTransform)
|
||||
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
4
http/index.html
Normal file
4
http/index.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<form action="/upload" method="POST" enctype="multipart/form-data">
|
||||
<input type="file" name="image" accept="image/*" required>
|
||||
<button type="submit">Upload Image</button>
|
||||
</form>
|
||||
Reference in New Issue
Block a user