Implement IP echo
This commit is contained in:
33
main.go
33
main.go
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Error *log.Logger
|
||||
func init() {
|
||||
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
|
||||
// logFile, err := os.Create("main.log")
|
||||
// if err != nil {
|
||||
// log.Printf("Error creating log file: %v", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
logger := io.MultiWriter(os.Stdout)
|
||||
log.SetOutput(logger)
|
||||
|
||||
Error = log.New(io.MultiWriter(os.Stderr, os.Stdout),
|
||||
fmt.Sprintf("%sERROR:%s ", "\033[0;101m", "\033[0m"),
|
||||
log.Lmicroseconds|log.Lshortfile)
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, r.RemoteAddr)
|
||||
})
|
||||
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
Reference in New Issue
Block a user