-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (59 loc) · 1.77 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
package main
import (
"fmt"
"net/http"
"strings"
"github.com/c-beltran/funfacts/internal/facts/apis"
"github.com/c-beltran/funfacts/internal/facts/http/rest"
"github.com/c-beltran/funfacts/internal/facts/service"
"github.com/gorilla/mux"
)
func main() {
httpClient := http.Client{
Timeout: http.DefaultClient.Timeout,
Transport: http.DefaultTransport,
}
dogAPI := apis.NewClient(&httpClient, "https://dog-api.kinduff.com")
catAPI := apis.NewClient(&httpClient, "https://meowfacts.herokuapp.com")
entertainmentAPI := apis.NewClient(&httpClient, "https://asli-fun-fact-api.herokuapp.com")
trivialAPI := apis.NewClient(&httpClient, "https://uselessfacts.jsph.pl")
//-
restServer := rest.NewServer("/")
rest.Register(restServer, rest.RegisterParams{
Fact: &service.FactSVC{
CFinder: catAPI,
DFinder: dogAPI,
EFinder: entertainmentAPI,
TFinder: trivialAPI,
},
})
// traverses and prints existing routes/endpoints.
err := restServer.Router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
pathTemplate, err := route.GetPathTemplate()
if err == nil {
fmt.Println("ROUTE:", pathTemplate)
}
pathRegexp, err := route.GetPathRegexp()
if err == nil {
fmt.Println("Path regexp:", pathRegexp)
}
queriesTemplates, err := route.GetQueriesTemplates()
if err == nil {
fmt.Println("Queries templates:", strings.Join(queriesTemplates, ","))
}
queriesRegexps, err := route.GetQueriesRegexp()
if err == nil {
fmt.Println("Queries regexps:", strings.Join(queriesRegexps, ","))
}
methods, err := route.GetMethods()
if err == nil {
fmt.Println("Methods:", strings.Join(methods, ","))
}
fmt.Println()
return nil
})
if err != nil {
fmt.Println(err)
}
http.ListenAndServe("0.0.0.0:8080", restServer.Router)
}