optimize service define in pkg/service package

pull/196/head
Michael Li 2 years ago
parent fd665abb8b
commit e81772005d

@ -20,9 +20,11 @@ var (
)
type Service interface {
Name() string
PreStart() string
PreStop() string
Start()
Stop()
Info() string
}
func NewWebService() Service {

@ -12,10 +12,26 @@ import (
"github.com/rocboss/paopao-ce/internal/conf"
)
type baseService struct{}
type webService struct {
baseService
server *http.Server
}
func (baseService) PreStart() string {
return ""
}
func (baseService) PreStop() string {
return ""
}
func (s *webService) Name() string {
return "WebService"
}
func (s *webService) Start() {
if err := s.server.ListenAndServe(); err != nil {
log.Fatalf("run app failed: %s", err)
@ -26,7 +42,7 @@ func (s *webService) Stop() {
s.server.Shutdown(context.Background())
}
func (s *webService) Info() string {
func (s *webService) PreStart() string {
return fmt.Sprintf("PaoPao service listen on %s\n", color.GreenString("http://%s:%s", conf.ServerSetting.HttpIp, conf.ServerSetting.HttpPort))
}

Loading…
Cancel
Save