-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (31 loc) · 772 Bytes
/
Copy pathmain.go
File metadata and controls
41 lines (31 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
mux := http.NewServeMux()
// any path we not define will go to here
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Println("have request /")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
if r.Method == http.MethodOptions {
return
}
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
fmt.Fprintf(w, "Server Work")
})
mux.HandleFunc("GET /files", ListFilesHandle)
mux.HandleFunc("POST /files/delete", DeleteFileHandle)
mux.HandleFunc("POST /files/create", CreateDirHandle)
server := &http.Server{
Addr: ":8000",
Handler: mux,
}
log.Fatal(server.ListenAndServe())
}