-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
88 lines (68 loc) · 2.47 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
package main
import (
"grafos/methods"
"log"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if len(port) == 0 {
port = "8000"
}
staticFiles := http.FileServer(http.Dir("./static"))
jsFiles := http.StripPrefix("/js/", http.FileServer(http.Dir("./js")))
http.Handle("/", staticFiles)
http.Handle("/js/", jsFiles)
http.HandleFunc("/flujomaximo", flujoMaximo)
http.HandleFunc("/floydwarshall", floyWarshall)
http.HandleFunc("/cpm", cpm)
http.HandleFunc("/pert", pert)
http.HandleFunc("/compresion", compresion)
http.HandleFunc("/dijkstra", dijkstra)
http.HandleFunc("/kruskal", kruskal)
log.Printf("http://localhost:%s", port)
log.Panic(http.ListenAndServe(":"+port, methods.GzipHandler(http.DefaultServeMux)))
}
func flujoMaximo(rw http.ResponseWriter, req *http.Request) {
var grafo methods.FlujoMaximo
methods.Deserialize(req.Body, &grafo)
rw.Header().Set("Content-Type", "application/json")
rw.Write(methods.ToBytes(methods.ResuelveFlujoMaximo(grafo)))
}
func floyWarshall(rw http.ResponseWriter, req *http.Request) {
var grafo []methods.Edge
methods.Deserialize(req.Body, &grafo)
rw.Header().Set("Content-Type", "application/json")
rw.Write(methods.ToBytes(methods.ResuelveFloyWarshall(&grafo)))
}
func cpm(rw http.ResponseWriter, req *http.Request) {
var actividades []methods.Edge
methods.Deserialize(req.Body, &actividades)
rw.Header().Set("Content-Type", "application/json")
rw.Write(methods.ToBytes(methods.ResuelveCPM(actividades)))
}
func dijkstra(rw http.ResponseWriter, req *http.Request) {
var actividades methods.Dijkstra
methods.Deserialize(req.Body, &actividades)
rw.Header().Set("Content-Type", "application/json")
rw.Write(methods.ToBytes(methods.ResuelveDijkstra(actividades)))
}
func pert(rw http.ResponseWriter, req *http.Request) {
var actividades []methods.VerticePert
methods.Deserialize(req.Body, &actividades)
rw.Header().Set("Content-Type", "application/json")
rw.Write(methods.ToBytes(methods.ResuelvePERT(actividades)))
}
func compresion(rw http.ResponseWriter, req *http.Request) {
var actividades methods.CompresionData
methods.Deserialize(req.Body, &actividades)
rw.Header().Set("Content-Type", "application/json")
rw.Write(methods.ToBytes(methods.ResuelveCompresion(actividades)))
}
func kruskal(rw http.ResponseWriter, req *http.Request) {
var grafo []methods.Edge
methods.Deserialize(req.Body, &grafo)
rw.Header().Set("Content-Type", "application/json")
rw.Write(methods.ToBytes(methods.ResuelveKruskal(grafo)))
}