Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to run Go application on Apache

I have written some code in Go which calculates the request processing time, using my own handler that I am wrapping around the original handler. But I want to run that code on Apache web-server. How can I do that?

my code:

package main

import ("fmt"
    "net/http"
    //"log"
    "github.com/gorilla/mux"
   "time"
    //"net/http/fcgi"
   "io/ioutil"
)

 func timer(h http.HandlerFunc) (http.HandlerFunc){
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        startTime := time.Now()  //request time
        h.ServeHTTP(w, r)        //original function called.
        duration := time.Now().Sub(startTime)       //calculation of response    time.
        fmt.Println(duration)   
    })
}

func main(){
    r := mux.NewRouter()
    r.HandleFunc("/", timer())
    http.Handle("/",r)
    http.ListenAndServe(":8080",r)
}

also which HAndlefunc() should I pass to the handlefunc in main. I created a small function called foo and passed it as an argument to timer() in main, and when I listened to the 8080 port it printed foo and gave me time on the console, but I want it to do that for the dynamic request for a full fledged web application and on apache.

Comments