Last active
May 2, 2017 03:35
-
-
Save narenaryan/7df1355501c71149fa53be0d9751f594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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