forked from sundowndev/phoneinfoga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.go
149 lines (129 loc) · 3.91 KB
/
controllers.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
149
package api
import (
"github.com/gin-gonic/gin"
"gopkg.in/sundowndev/phoneinfoga.v2/config"
"gopkg.in/sundowndev/phoneinfoga.v2/scanners"
)
type scanResultResponse struct {
JSONResponse
Result interface{} `json:"result"`
}
type getAllNumbersResponse struct {
JSONResponse
Numbers []scanners.Number `json:"numbers"`
}
type healthResponse struct {
Success bool `json:"success"`
Version string `json:"version"`
Commit string `json:"commit"`
}
// @ID getAllNumbers
// @Tags Numbers
// @Summary Fetch all previously scanned numbers.
// @Description This route is actually not used yet.
// @Deprecated
// @Produce json
// @Success 200 {object} getAllNumbersResponse
// @Router /numbers [get]
func getAllNumbers(c *gin.Context) {
c.JSON(200, getAllNumbersResponse{
JSONResponse: JSONResponse{Success: true},
Numbers: []scanners.Number{},
})
}
// @ID validate
// @Tags Numbers
// @Summary Check if a number is valid and possible.
// @Produce json
// @Success 200 {object} JSONResponse
// @Success 400 {object} JSONResponse
// @Router /numbers/{number}/validate [get]
// @Param number path string true "Input phone number" validate(required)
func validate(c *gin.Context) {
c.JSON(200, successResponse("The number is valid"))
}
// @ID localScan
// @Tags Numbers
// @Summary Perform a scan using local phone number library.
// @Produce json
// @Success 200 {object} scanResultResponse{result=scanners.Number}
// @Success 400 {object} JSONResponse
// @Router /numbers/{number}/scan/local [get]
// @Param number path string true "Input phone number" validate(required)
func localScan(c *gin.Context) {
result, _ := c.Get("number")
c.JSON(200, scanResultResponse{
JSONResponse: JSONResponse{Success: true},
Result: result.(*scanners.Number),
})
}
// @ID numverifyScan
// @Tags Numbers
// @Summary Perform a scan using Numverify's API.
// @Produce json
// @Success 200 {object} scanResultResponse{result=scanners.NumverifyScannerResponse}
// @Success 400 {object} JSONResponse
// @Router /numbers/{number}/scan/numverify [get]
// @Param number path string true "Input phone number" validate(required)
func numverifyScan(c *gin.Context) {
number, _ := c.Get("number")
result, err := scanners.NumverifyScan(number.(*scanners.Number))
if err != nil {
c.JSON(500, errorResponse())
return
}
c.JSON(200, scanResultResponse{
JSONResponse: JSONResponse{Success: true},
Result: result,
})
}
// @ID googleSearchScan
// @Tags Numbers
// @Summary Perform a scan using Google Search engine.
// @Produce json
// @Success 200 {object} scanResultResponse{result=scanners.GoogleSearchResponse}
// @Success 400 {object} JSONResponse
// @Router /numbers/{number}/scan/googlesearch [get]
// @Param number path string true "Input phone number" validate(required)
func googleSearchScan(c *gin.Context) {
number, _ := c.Get("number")
result := scanners.GoogleSearchScan(number.(*scanners.Number))
c.JSON(200, scanResultResponse{
JSONResponse: JSONResponse{Success: true},
Result: result,
})
}
// @ID ovhScan
// @Tags Numbers
// @Summary Perform a scan using OVH's API.
// @Produce json
// @Success 200 {object} scanResultResponse{result=scanners.OVHScannerResponse}
// @Success 400 {object} JSONResponse
// @Router /numbers/{number}/scan/ovh [get]
// @Param number path string true "Input phone number" validate(required)
func ovhScan(c *gin.Context) {
number, _ := c.Get("number")
result, err := scanners.OVHScan(number.(*scanners.Number))
if err != nil {
c.JSON(500, errorResponse())
return
}
c.JSON(200, scanResultResponse{
JSONResponse: JSONResponse{Success: true},
Result: result,
})
}
// @ID healthCheck
// @Tags default
// @Summary Check if service is healthy.
// @Produce json
// @Success 200 {object} healthResponse
// @Success 500 {object} JSONResponse
// @Router / [get]
func healthHandler(c *gin.Context) {
c.JSON(200, healthResponse{
Success: true,
Version: config.Version,
Commit: config.Commit,
})
}