瀏覽代碼

First commit

litpooh 3 年之前
當前提交
79478ddf15
共有 5 個文件被更改,包括 49 次插入0 次删除
  1. 二進制
      .DS_Store
  2. 二進制
      files/dog.jpeg
  3. 12 0
      files/index.html
  4. 9 0
      files/test.html
  5. 28 0
      folder.go

二進制
.DS_Store


二進制
files/dog.jpeg


+ 12 - 0
files/index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>Example</title>
+    </head>
+    <body>
+        <p>INDEX</p>
+    </body>
+    <form action="./create.html" method="get">
+        <input type="submit" value="Create a file">
+    </form>
+</html>

+ 9 - 0
files/test.html

@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>Test</title>
+    </head>
+    <body>
+        <p>This is an example of a simple HTML page with one paragraph.</p>
+    </body>
+</html>

+ 28 - 0
folder.go

@@ -0,0 +1,28 @@
+package main
+
+import (
+	"fmt"
+	"net/http"
+)
+
+func createHandler(rw http.ResponseWriter, req *http.Request) {
+	if req.Method == "GET" {
+		fmt.Fprintf(rw, "You requested the create-file function.")
+
+	} else {
+		responseText := fmt.Sprintf("Method %s is not supported.", req.Method)
+		http.Error(rw, responseText, http.StatusNotFound)
+		return
+	}
+}
+
+func main() {
+	port := "8000"
+	httpFileServer := http.FileServer(http.Dir("./files"))
+	http.Handle("/", httpFileServer)
+
+	fmt.Printf("Listening http://localhost:%s\n", port)
+	if error := http.ListenAndServe(":"+port, nil); error != nil {
+		fmt.Printf("Error: %s\n", error)
+	}
+}