-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
148 lines (124 loc) · 3.16 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"GoProjects/wiki/parse"
"html/template"
"net/http"
)
type searchDetails struct {
Start string
End string
Route []string
}
func (d searchDetails) runSearch() []string {
startURL := link.CreateURL(d.Start)
return link.GetRoute(startURL, d.Start, d.End)
}
func main() {
tmpl := template.Must(template.ParseFiles("template.gohtml"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
tmpl.Execute(w, nil)
return
}
details := searchDetails{
Start: r.FormValue("start"),
End: r.FormValue("end"),
}
// do something with details
start := link.CleanPath(details.Start)
startURL := link.CreateURL(start)
startValid := link.IsValidURL(startURL)
end := link.CleanPath(details.End)
endURL := link.CreateURL(end)
endValid := link.IsValidURL(endURL)
success := startValid && endValid
var route []string
if success {
route = details.runSearch()
}
tmpl.Execute(w, struct {
Route []string
Success bool
}{route, success})
})
// http.HandleFunc("/search", func(w http.ResponseWriter, r *http.Request) {
// if r.Method != http.MethodPost {
// tmpl.Execute(w, nil)
// return
// }
// // do something with details
// start := link.CleanPath(details.Start)
// startURL := link.CreateURL(start)
// startValid := link.IsValidURL(startURL)
// end := link.CleanPath(details.End)
// endURL := link.CreateURL(end)
// endValid := link.IsValidURL(endURL)
// success := startValid && endValid
// route := details.runSearch()
// tmpl.Execute(w, struct {
// Route []string
// Success bool
// }{route, success})
// })
http.ListenAndServe(":8080", nil)
}
// import (
// "GoProjects/wiki/parse"
// "bufio"
// "fmt"
// "github.com/gorilla/mux"
// "net/http"
// "os"
// "strings"
// )
// func main() {
// var start string
// var end string
// var startValid = false
// var endValid = false
// var startURL string
// r := mux.NewRouter()
// r.HandleFunc("/main", func(w http.ResponseWriter, r *http.Request) {
// // get the book
// // navigate to the page
// })
// reader := bufio.NewReader(os.Stdin)
// for !startValid {
// fmt.Println("where do you want to start?")
// start, _ = reader.ReadString('\n')
// start = link.CleanPath(start)
// startURL = link.CreateURL(start)
// startValid = link.IsValidURL(startURL)
// if !startValid {
// fmt.Println("Not valid url")
// }
// }
// for !endValid {
// fmt.Println("where do you need to go?")
// end, _ = reader.ReadString('\n')
// end = link.CleanPath(end)
// endURL := link.CreateURL(end)
// endValid = link.IsValidURL(endURL)
// if !endValid {
// fmt.Println("Not valid url")
// }
// }
// startPath := strings.TrimRight(start, "/wiki/")
// endPath := strings.TrimRight(end, "/wiki/")
// endPath = strings.ToLower(endPath)
// // fmt.Println(startPath)
// // fmt.Println(endPath)
// route := link.GetRoute(startURL, startPath, endPath)
// if route != nil {
// fmt.Println("start")
// for num, v := range route {
// num = num + 1
// fmt.Print(num)
// fmt.Print(" = ")
// fmt.Println(v)
// }
// fmt.Println("end")
// } else {
// fmt.Println("was not found")
// }
//}