package server_http

import (
	"fmt"
	"net/http"
	"net/http/pprof"
	"sync"
)

// 启动Web服务器
// wg:WaitGroup对象
// address:服务器地址
func Start(wg *sync.WaitGroup, address string) {
	defer func() {
		wg.Done()
	}()

	//// 开启服务
	//serverInstance := http.Server{
	//	Addr:    address,
	//	Handler: new(httpServer),
	//}

	//// 开启监听
	//msg := fmt.Sprintf("server_http begins to listen on: %s...", address)
	//fmt.Println(msg)
	//logUtil.InfoLog(msg)

	// 启动Web服务器监听
	mux := http.NewServeMux()
	mux.Handle("/", &httpServer{})
	mux.HandleFunc("/debug/pprof/", pprof.Index)
	mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
	mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
	mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
	mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

	if err := http.ListenAndServe(address, mux); err != nil {
		panic(fmt.Sprintf("server_http ListenAndServe Error:%v", err))
	}
	//if err := serverInstance.ListenAndServe(); err != nil {
	//	panic(fmt.Sprintf("server_http ListenAndServe Error:%v", err))
	//}
}
