mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-12 07:28:08 -05:00
Co-authored-by: mask-pp <mask-pp@users.noreply.github.com> Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
28 lines
542 B
Go
28 lines
542 B
Go
package utils
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// StartHTTPServer a public http server to be used.
|
|
func StartHTTPServer(address string, handler http.Handler) (*http.Server, error) {
|
|
srv := &http.Server{
|
|
Handler: handler,
|
|
Addr: address,
|
|
ReadTimeout: time.Second * 3,
|
|
WriteTimeout: time.Second * 3,
|
|
IdleTimeout: time.Second * 12,
|
|
}
|
|
errCh := make(chan error, 1)
|
|
go func() {
|
|
errCh <- srv.ListenAndServe()
|
|
}()
|
|
select {
|
|
case err := <-errCh:
|
|
return nil, err
|
|
case <-time.After(time.Second):
|
|
}
|
|
return srv, nil
|
|
}
|