17func (s *Server) ListenAndServe() {
18 if s.Opts.TLSKeyFile != "" || s.Opts.TLSCertFile != "" {
25func (s *Server) ServeHTTP() {
26 httpAddress := s.Opts.HttpAddress
29 i := strings.Index(httpAddress, "://")
31 scheme = httpAddress[0:i]
34 var networkType string
42 slice := strings.SplitN(httpAddress, "//", 2)
43 listenAddr := slice[len(slice)-1]
45 listener, err := net.Listen(networkType, listenAddr)
47 log.Fatalf("FATAL: listen (%s, %s) failed - %s", networkType, listenAddr, err)
49 log.Printf("HTTP: listening on %s", listenAddr)
51 server := &http.Server{Handler: s.Handler}
52 err = server.Serve(listener)
53 if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
54 log.Printf("ERROR: http.Serve() - %s", err)
57 log.Printf("HTTP: closing %s", listener.Addr())
60func (s *Server) ServeHTTPS() {
61 addr := s.Opts.HttpsAddress
62 config := &tls.Config{
63 MinVersion: tls.VersionTLS12,
64 MaxVersion: tls.VersionTLS12,
66 if config.NextProtos == nil {
67 config.NextProtos = []string{"http/1.1"}
71 config.Certificates = make([]tls.Certificate, 1)
72 config.Certificates[0], err = tls.LoadX509KeyPair(s.Opts.TLSCertFile, s.Opts.TLSKeyFile)
74 log.Fatalf("FATAL: loading tls config (%s, %s) failed - %s", s.Opts.TLSCertFile, s.Opts.TLSKeyFile, err)
77 ln, err := net.Listen("tcp", addr)
79 log.Fatalf("FATAL: listen (%s) failed - %s", addr, err)
81 log.Printf("HTTPS: listening on %s", ln.Addr())
83 tlsListener := tls.NewListener(tcpKeepAliveListener{ln.(*net.TCPListener)}, config)
84 srv := &http.Server{Handler: s.Handler}
85 err = srv.Serve(tlsListener)
87 if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
88 log.Printf("ERROR: https.Serve() - %s", err)
91 log.Printf("HTTPS: closing %s", tlsListener.Addr())
94// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted
95// connections. It's used by ListenAndServe and ListenAndServeTLS so
96// dead TCP connections (e.g. closing laptop mid-download) eventually
98type tcpKeepAliveListener struct {
102func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
103 tc, err := ln.AcceptTCP()
107 tc.SetKeepAlive(true)
108 tc.SetKeepAlivePeriod(3 * time.Minute)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list