potato/initialize/http_server.go

30 lines
690 B
Go
Raw Permalink Normal View History

2021-06-20 22:28:27 +08:00
/*
* @Date: 2021-03-22 17:03:27
* @LastEditors: viletyy
2021-07-09 14:26:02 +08:00
* @LastEditTime: 2021-07-09 14:24:36
2021-06-20 22:28:27 +08:00
* @FilePath: /potato/initialize/http_server.go
*/
package initialize
import (
2021-07-09 14:26:02 +08:00
"fmt"
2021-06-20 22:28:27 +08:00
"net/http"
"time"
"github.com/viletyy/potato/global"
"github.com/viletyy/potato/internal/routers"
)
2021-07-09 14:26:02 +08:00
func RunHttpServer(port string) error {
2021-06-20 22:28:27 +08:00
router := routers.InitRouter()
server := &http.Server{
2021-07-09 14:26:02 +08:00
Addr: fmt.Sprintf(":%s", port),
2021-06-20 22:28:27 +08:00
Handler: router,
ReadTimeout: time.Duration(global.GO_CONFIG.Server.ReadTimeout) * time.Second,
WriteTimeout: time.Duration(global.GO_CONFIG.Server.ReadTimeout) * time.Second,
MaxHeaderBytes: 1 << 20,
}
2021-07-09 14:26:02 +08:00
return server.ListenAndServe()
2021-06-20 22:28:27 +08:00
}