1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package main
- import (
- "fmt"
- "io"
- "log"
- "net/http"
- "regexp"
- "time"
- )
- func main() {
- http.HandleFunc("/id", idFunc)
- http.HandleFunc("/info", infoFunk)
- http.HandleFunc("/status", statusFunk)
- err := http.ListenAndServe(":8080", nil)
- if err != nil {
- log.Fatal("ListenAndServe: ", err)
- }
- }
- func idFunc(w http.ResponseWriter, r *http.Request) {
- fmt.Fprintf(w, "Pop US 792")
- }
- func infoFunk(w http.ResponseWriter, r *http.Request) {
- w.WriteHeader(http.StatusOK)
- fmt.Fprintf(w, "status: OK")
- }
- func statusFunk(w http.ResponseWriter, r *http.Request) {
- fmt.Fprintf(w, "Popova Uliana\n")
- response, error := http.Get("https://api.ipify.org/?format=text")
- if error != nil {
- fmt.Println(error)
- }
- body, error := io.ReadAll(response.Body)
- if error != nil {
- fmt.Println(error)
- }
- response.Body.Close()
- regex := regexp.MustCompile("[.].*[.]")
- out := regex.ReplaceAllString(string(body), ".***.***.")
- fmt.Fprint(w, "IP: ", out, "\n")
- now := time.Now()
- fmt.Fprintf(w, now.Format("2006-01-02 3:4:5 pm"))
- }
|