// Start starts the HTTP server in a separate Go routine.
Start starts the HTTP server in a separate Go routine.
// Start starts the HTTP server in a separate Go routine .
func (s *Server) Start() error {
	if !atomic.CompareAndSwapUint32(&s.started, 0, 1) {
		return fmt.Errorf("server already started")
	}
	go func() {
		logger.Infof("listening for requests on [%s]", s.httpServer.Addr)
		var err error
		if s.keyFile != "" && s.certFile != "" {
			err = s.httpServer.ListenAndServeTLS(s.certFile, s.keyFile)
		} else {
			err = s.httpServer.ListenAndServe()
		}
		if err != nil && !errors.Is(err, http.ErrServerClosed) {
			panic(fmt.Sprintf("Failed to start server on [%s]: %s", s.httpServer.Addr, err))
		}
		atomic.StoreUint32(&s.started, 0)
		logger.Infof("server has stopped")
	}()
	return nil
}
func ( s * Server ) Start ( ) error { if ! atomic . CompareAndSwapUint32 ( & s . started , 0 , 1 ) { return fmt . Errorf ( " " ) } go func ( ) { logger . Infof ( " " , s . httpServer . Addr ) var err error if s . keyFile != " " && s . certFile != " " { err = s . httpServer . ListenAndServeTLS ( s . certFile , s . keyFile ) } else { err = s . httpServer . ListenAndServe ( ) } if err != nil && ! errors . Is ( err , http . ErrServerClosed ) { panic ( fmt . Sprintf ( " " , s . httpServer . Addr , err ) ) } atomic . StoreUint32 ( & s . started , 0 ) logger . Infof ( " " ) } ( ) return nil }
Start starts the HTTP server in a separate Go routine.
Start starts the HTTP server in a separate Go routine .