-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (34 loc) · 912 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
package main
import (
"github.com/troke12/gopi/handlers"
"log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/goccy/go-json"
"github.com/rollbar/rollbar-go"
)
func main() {
// Rollbar
rollbar.SetToken(os.Getenv("ROLLBAR_TOKEN"))
//Add config for connecting to CF IP
app := fiber.New(fiber.Config{
ProxyHeader: "CF-Connecting-IP",
JSONEncoder: json.Marshal,
JSONDecoder: json.Unmarshal,
//EnableTrustedProxyCheck: true,
//TrustedProxies: []string{"0.0.0.0"},
})
// Test route
//app.Get("/test", handlers.GetUserIPTest)
// Main route
app.Get("/", handlers.GetCurrentIP)
rollbar.WrapAndWait(handlers.GetCurrentIP)
// Getting country
app.Get("/:ip/country", handlers.GetCountry)
rollbar.WrapAndWait(handlers.GetCountry)
// Request another IP
app.Get("/:ip", handlers.GetAnotherIP)
rollbar.WrapAndWait(handlers.GetAnotherIP)
// Port
log.Fatal(app.Listen(os.Getenv("PORT")))
}