-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
101 lines (80 loc) · 1.89 KB
/
main.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// package file_validation_package
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"reflect"
s "github.com/transybao1393/go-bigcache/services"
)
type FileStruct struct {
ContentDisposition map[string]string
ContentType string
}
type BCRequestStruct struct {
name string
value string
}
func rootHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.Error(w, "404 not found.", http.StatusNotFound)
return
}
switch r.Method {
case "GET":
http.ServeFile(w, r, "form.html")
case "POST":
if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ParseForm() err: %v", err)
return
}
name := r.FormValue("name")
occupation := r.FormValue("occupation")
//- file handler
r.ParseMultipartForm(32 << 20)
file, handler, err := r.FormFile("filename")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
fmt.Fprintf(w, "file header %v", handler.Header)
fmt.Fprintf(w, "%s is a %s\n", name, occupation)
default:
fmt.Fprintf(w, "Sorry, only GET and POST methods are supported.")
}
}
func bigCacheHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/bc" {
http.Error(w, "404 not found.", http.StatusNotFound)
return
}
switch r.Method {
case "GET":
fmt.Println("124")
//- get bigcache by name
case "POST":
var bcr BCRequestStruct
fmt.Println("body", r.Body)
// dec := json.NewDecoder(r.Body)
// dec.DisallowUnknownFields()
err := json.NewDecoder(r.Body).Decode(&bcr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Fprintf(w, "bigcache request body: %+v", bcr)
}
}
func main() {
//- load env file
config, error := s.LoadConfig(".")
if error != nil {
log.Fatal("cannot load config:", error)
}
fmt.Println("config", reflect.TypeOf(config))
fmt.Println("type of verbose", reflect.TypeOf(config.Verbose))
//- fasthttp
s.FHExecute()
}