Implement endpoint for running WHOIS queries

This commit is contained in:
Sean DuBois 2014-07-10 00:54:26 +00:00
parent c59cb07298
commit 05ec165128
2 changed files with 24 additions and 0 deletions

View file

@ -41,6 +41,9 @@ func main() {
globalHandler(r.PathPrefix("/global").Subrouter(), fail2goConn) globalHandler(r.PathPrefix("/global").Subrouter(), fail2goConn)
jailHandler(r.PathPrefix("/jail").Subrouter(), fail2goConn) jailHandler(r.PathPrefix("/jail").Subrouter(), fail2goConn)
r.HandleFunc("/whois/{object}", func(res http.ResponseWriter, req *http.Request) {
whoisHandler(res, req, fail2goConn)
}).Methods("GET")
http.Handle("/", r) http.Handle("/", r)
fmt.Println(http.ListenAndServe(configuration.Addr, nil)) fmt.Println(http.ListenAndServe(configuration.Addr, nil))

21
whois.go Normal file
View file

@ -0,0 +1,21 @@
package main
import (
"encoding/json"
"github.com/Sean-Der/fail2go"
"github.com/Sean-Der/goWHOIS"
"github.com/gorilla/mux"
"net/http"
)
func whoisHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
goWHOISReq := goWHOIS.NewReq(mux.Vars(req)["object"])
WHOIS, err := goWHOISReq.Raw()
if err != nil {
writeHTTPError(res, err)
return
}
encodedOutput, _ := json.Marshal(map[string]string{"WHOIS": WHOIS})
res.Write(encodedOutput)
}