Standard library / net/http
http.Server.ListenAndServeTLS()
Serves HTTPS on the server address. Returns ErrServerClosed for a previously closed server; successful TLS serving is demonstrated separately. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (srv *Server) ListenAndServeTLS(certFile, keyFile string) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| certFile | string | Input value of the declared type; see the usage example. |
| keyFile | string | Input value of the declared type; see the usage example. |
Return Value
error
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "errors" "fmt" "net/http")
func main() { s := &http.Server{Addr: "127.0.0.1:0"} check(s.Close()) fmt.Println(errors.Is(s.ListenAndServeTLS("", ""), http.ErrServerClosed))}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}