You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
722 B
44 lines
722 B
1 year ago
|
package server
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/spf13/viper"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
"product/backend/module"
|
||
|
"product/backend/module/mw"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func handlerMain() http.Handler {
|
||
|
r := gin.Default()
|
||
|
// middle ware
|
||
|
mw.SetHandler(r)
|
||
|
|
||
|
// handler
|
||
|
module.Handler(r)
|
||
|
|
||
|
return r
|
||
|
}
|
||
|
|
||
|
type ServerMain struct {
|
||
|
*http.Server
|
||
|
}
|
||
|
|
||
|
func (s *ServerMain) Start() error {
|
||
|
log.Println("server main is listen on", s.Server.Addr)
|
||
|
return s.Server.ListenAndServe()
|
||
|
}
|
||
|
|
||
|
func LoadServerMain() (*ServerMain, error) {
|
||
|
s := &http.Server{
|
||
|
Addr: viper.GetString("app.main.addr"),
|
||
|
Handler: handlerMain(),
|
||
|
ReadTimeout: 5 * time.Second,
|
||
|
WriteTimeout: 10 * time.Second,
|
||
|
}
|
||
|
return &ServerMain{
|
||
|
s,
|
||
|
}, nil
|
||
|
}
|