Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Last active May 2, 2017 03:35
Show Gist options
  • Select an option

  • Save narenaryan/7df1355501c71149fa53be0d9751f594 to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/7df1355501c71149fa53be0d9751f594 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"html"
"log"
"net/http"
"os"
"time"
)
func main() {
f, err := os.OpenFile("app.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
fmt.Printf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
log.Printf("%q", r.UserAgent())
})
s := &http.Server{
Addr: ":8000",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(s.ListenAndServe())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment