-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (39 loc) · 829 Bytes
/
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
package main
import (
"encoding/json"
"fmt"
"net/http"
)
/*Metodo sin uso, alternartiva a la implementacion chi*/
func start() {
http.HandleFunc("/api/analyce", func(w http.ResponseWriter, r *http.Request) {
url := r.FormValue("url")
out := ApiAnalyce(url)
old, err0 := Get(url)
if !err0 {
out = Compare(out, old)
}
tmp, err := json.Marshal(&out)
if err != nil {
return
}
data := string(tmp)
Insert(url, data)
fmt.Fprint(w, data)
})
http.HandleFunc("/api/list", func(w http.ResponseWriter, r *http.Request) {
list, _ := GetAll()
type items struct {
Items []string
}
out_json, err := json.Marshal(items{Items: list})
if err != nil {
fmt.Println(err)
}
w.Write([]byte(fmt.Sprintf("%v", string(out_json))))
})
http.ListenAndServe(":8090", nil)
}
func main() {
Rutes()
}