HTTP GET

Report a typo

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!

Sample Input 1:

Oliver

Sample Output 1:

Oliver
Write 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)
}
}
___

Create a free account to access the full topic