Skip to content

Instantly share code, notes, and snippets.

@jezman
Created February 28, 2018 09:27
Show Gist options
  • Save jezman/89e74a9fc995766cde08b415ccc0c636 to your computer and use it in GitHub Desktop.
Save jezman/89e74a9fc995766cde08b415ccc0c636 to your computer and use it in GitHub Desktop.
template
package main
import (
"log"
"net/http"
"os"
)
var (
err error
logfile *os.File
Info *log.Logger
Error *log.Logger
)
func someHandler(w http.ResponseWriter, r *http.Request) {
}
func main() {
logfile, err = os.OpenFile("some.log", os.O_RDWR|os.O_APPEND, 0644)
if err != nil {
panic(err)
}
defer logfile.Close()
Info = log.New(logfile, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
Error = log.New(logfile, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
http.HandleFunc("/path", someHandler)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment