There is a server that keeps information about logged-in users. You need to write a program to get the name of the last user who logged in. For this, you need to make a GET request to http://127.0.0.1:8080/last-login. Output the response body as a string and don't forget to convert the answer to the string type!
Making HTTP requests
HTTP GET
Report a typo
Sample Input 1:
OliverSample Output 1:
OliverWrite a program in Go
package main
import (
"fmt"
"io"
"net/http"
"time"
)
func main() {
// Write your code here
}
// DO NOT MODIFY the contents of the init() or must() functions!
func init() {
const timeout = 5 * time.Second
var response string
fmt.Scan(&response)
go func() {
http.HandleFunc("/last-login", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, response)
})
must(http.ListenAndServe(":8080", nil))
}()
time.Sleep(timeout)
}
// DO NOT delete or modify the must() function; it is a helper to check for errors!
func must(err error) {
if err != nil {
panic(err)
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.