mirror of https://github.com/rocboss/paopao-ce
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.
62 lines
1.4 KiB
62 lines
1.4 KiB
2 years ago
|
// Copyright 2022 ROC. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package service
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/fatih/color"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/rocboss/paopao-ce/internal/conf"
|
||
|
"github.com/rocboss/paopao-ce/internal/servants"
|
||
|
)
|
||
|
|
||
|
type localossService struct {
|
||
|
*baseHttpService
|
||
|
}
|
||
|
|
||
|
func (s *localossService) Name() string {
|
||
|
return "LocalossService"
|
||
|
}
|
||
|
|
||
|
func (s *localossService) Init() error {
|
||
|
s.registerRoute(servants.RegisterLocalossServants)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (s *localossService) String() string {
|
||
|
return fmt.Sprintf("listen on %s\n", color.GreenString("http://%s:%s", conf.LocalossServerSetting.HttpIp, conf.LocalossServerSetting.HttpPort))
|
||
|
}
|
||
|
|
||
|
func newLocalossEngine() *gin.Engine {
|
||
|
e := gin.New()
|
||
|
e.Use(gin.Logger())
|
||
|
e.Use(gin.Recovery())
|
||
|
return e
|
||
|
}
|
||
|
|
||
|
func newLocalossService() Service {
|
||
|
addr := conf.LocalossServerSetting.HttpIp + ":" + conf.LocalossServerSetting.HttpPort
|
||
|
server := httpServerFrom(addr, func() *httpServer {
|
||
|
engine := newLocalossEngine()
|
||
|
return &httpServer{
|
||
|
e: engine,
|
||
|
server: &http.Server{
|
||
|
Addr: addr,
|
||
|
Handler: engine,
|
||
|
ReadTimeout: conf.LocalossServerSetting.ReadTimeout,
|
||
|
WriteTimeout: conf.LocalossServerSetting.WriteTimeout,
|
||
|
MaxHeaderBytes: 1 << 20,
|
||
|
},
|
||
|
}
|
||
|
})
|
||
|
return &localossService{
|
||
|
baseHttpService: &baseHttpService{
|
||
|
server: server,
|
||
|
},
|
||
|
}
|
||
|
}
|