-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (96 loc) · 2.48 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
//whatIDo - by jero98772
package main
import ("fmt"
"net/http"
"html/template"
"jerotools/tools"
"log"
"io/ioutil"
)
type Answer struct {
Text string
isDonde bool
Graph string
}
func Index(rw http.ResponseWriter,r *http.Request){
template, _ := template.ParseFiles("templates/index.html")
template.Execute(rw,nil)
}
func Playgroundpond(rw http.ResponseWriter,r *http.Request){
err := r.ParseForm()
data:=""
state:=false
if err != nil {
log.Fatal(err)
}
if len(r.Form)<=0{
data=""
state=false
}else{
allmaterials:=r.Form["allmaterials"][0]+"\n"
materials:=r.Form["mymaterials"][0]+"\n"
graph:=tools.Str2GraphPond(allmaterials)
mymaterials:=tools.Formatmymaterials(materials)
fmt.Println(graph)
//mymaterials:=tools.Str2arrstr(r.Form["mymaterials"][0]+"\n",",")//change this for support materials and unit structs
data=tools.Whaticanmakepon(graph,mymaterials)
state=true
}
choice:=Answer{Text:data,isDonde:state,Graph:""}
//fmt.Println(choice)
template, _ := template.ParseFiles("templates/playgroundponderate.html")
template.Execute(rw,choice)
}
func Playground(rw http.ResponseWriter,r *http.Request){
err := r.ParseForm()
data:=""
state:=false
if err != nil {
log.Fatal(err)
}
if len(r.Form)<=0{
data=""
state=false
}else{
graph:=tools.Str2Graph(r.Form["allmaterials"][0]+"\n")
mymaterials:=tools.Str2arrstr(r.Form["mymaterials"][0],",")
data=tools.Whaticanmake(graph,mymaterials)
state=true
}
choice:=Answer{Text:data,isDonde:state,Graph:""}
//fmt.Println(choice)
template, _ := template.ParseFiles("templates/playground.html")
template.Execute(rw,choice)
}
func Playonline(rw http.ResponseWriter,r *http.Request){
content, _ := ioutil.ReadFile("data/graph.txt")
err:=r.ParseForm()
data:=""
state:=false
if err != nil {
log.Fatal(err)
}
if len(r.Form)<=0{
data=""
state=false
}else{
graph:=tools.Str2Graph(r.Form["allmaterials"][0]+"\n")
mymaterials:=tools.Str2arrstr(r.Form["mymaterials"][0],",")
data=tools.Whaticanmake(graph,mymaterials)
fmt.Println(data)
state=true
}
choice:=Answer{Text:data,isDonde:state,Graph:string(content)}
//fmt.Println(string(content))
template, _ := template.ParseFiles("templates/playgroundonline.html")
template.Execute(rw,choice)
}
func main(){
http.HandleFunc("/",Index)
http.HandleFunc("/playgroundpond",Playgroundpond)
http.HandleFunc("/playground",Playground)
http.HandleFunc("/playonline",Playonline)
port :="9600"
fmt.Println("run at localhost:"+port)
http.ListenAndServe("0.0.0.0:"+port,nil)
}