一个请求后如何停止HTTP服务功能

To authenticate a user with a 3rd party service I need to listen and wait on a localport so I get a token by that service.

How is it possible to exit a server in go after one request?

As far as I'm aware it's only possible with listenAndServer to that forever, but on for just one single request

Thanks to @mkopriva I was able to do it.

It's actually pretty simple, just create a server object manually and then call s.Close() in your handle function

s := &http.Server{
    Addr: "localhost:8085",
}
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
    //do sth
    s.Close()
})
s.ListenAndServe()
//do sth else