mirror of
https://github.com/wonli/aqi.git
synced 2024-06-28 09:57:05 +08:00
35 lines
575 B
Go
35 lines
575 B
Go
|
package aqi
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"os"
|
||
|
|
||
|
"github.com/fatih/color"
|
||
|
|
||
|
"github.com/wonli/aqi/ws"
|
||
|
)
|
||
|
|
||
|
func (a *AppConfig) WithHttpServer(svr http.Handler) {
|
||
|
a.HttpServer = svr
|
||
|
}
|
||
|
|
||
|
func (a *AppConfig) Start() {
|
||
|
if a.HttpServer == nil {
|
||
|
color.Red("HttpServer not config")
|
||
|
os.Exit(0)
|
||
|
}
|
||
|
|
||
|
if a.HttpServer != nil {
|
||
|
server := ws.NewServer(a.HttpServer)
|
||
|
server.SetDataPath(a.DataPath)
|
||
|
server.SetIsDev(a.devMode)
|
||
|
server.Init()
|
||
|
}
|
||
|
|
||
|
err := http.ListenAndServe(":"+a.ServerPort, a.HttpServer)
|
||
|
if err != nil {
|
||
|
color.Red("Listener error: %s", err.Error())
|
||
|
os.Exit(0)
|
||
|
}
|
||
|
}
|