about summary refs log tree commit diff
path: root/src/http.go
blob: f2518f6875380a75dbe8cf211dea784d111bcc9b (plain)
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
package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/gorilla/mux"
)

// setupHTTPServer sets up a http server
func setupHTTPServer() http.Server {
	r := mux.NewRouter()

	r.HandleFunc("/", indexHandler)
	r.HandleFunc("/api/found", apiFoundHandler)

	return http.Server{
		Addr:    fmt.Sprintf("0.0.0.0:%d", httpServerPort),
		Handler: r,
	}
}

// indexHandler handles requests to the / endpoint
func indexHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "%s", "FUZZ!")
}

// httpStartServer starts the http server
func httpStartServer() {

	if httpServerPort != 8080 {
		log.Printf("%s Starting the http server", green("[i]"))

		// setup the http server and start it
		httpServer := setupHTTPServer()
		log.Fatalln(httpServer.ListenAndServe())

		log.Printf("%s Done starting the http server", boldGreen("[+]"))
	} else {
		return
	}
}

// handle requests to the /api/found endpoint
func apiFoundHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
}