-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.go
More file actions
37 lines (27 loc) · 668 Bytes
/
api.go
File metadata and controls
37 lines (27 loc) · 668 Bytes
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
package main
import (
"dohunt/pkg/domains"
"encoding/json"
"fmt"
"log"
"os"
"github.com/gofiber/fiber/v2"
)
func startAPI(domainData *map[string]domains.Domain, port int) {
// Pass the engine to the Views
app := fiber.New()
app.Static("/", "./static")
app.Get("/api/domains", func(c *fiber.Ctx) error {
key := c.Query("key")
if key != os.Getenv("DOCHKEY") {
return c.Status(fiber.StatusUnauthorized).SendString("401 Unauthorized")
}
jsonData, err := json.Marshal(*domainData)
if err != nil {
return err
}
c.Set("Content-Type", "application/json")
return c.Send(jsonData)
})
log.Fatal(app.Listen(fmt.Sprintf(":%d", port)))
}