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.
paopao-ce/main.go

71 lines
1.5 KiB

3 years ago
package main
import (
"flag"
3 years ago
"fmt"
"log"
3 years ago
"net/http"
"strings"
3 years ago
"github.com/fatih/color"
3 years ago
"github.com/gin-gonic/gin"
"github.com/rocboss/paopao-ce/internal"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/routers"
"github.com/rocboss/paopao-ce/pkg/debug"
"github.com/rocboss/paopao-ce/pkg/util"
)
var (
noDefaultFeatures bool
features suites
3 years ago
)
type suites []string
func (s *suites) String() string {
return strings.Join(*s, ",")
}
func (s *suites) Set(value string) error {
for _, item := range strings.Split(value, ",") {
*s = append(*s, strings.TrimSpace(item))
}
return nil
}
func init() {
flagParse()
conf.Initialize(features, noDefaultFeatures)
internal.Initialize()
}
func flagParse() {
flag.BoolVar(&noDefaultFeatures, "no-default-features", false, "whether use default features")
flag.Var(&features, "features", "use special features")
flag.Parse()
}
3 years ago
func main() {
gin.SetMode(conf.ServerSetting.RunMode)
3 years ago
router := routers.NewRouter()
s := &http.Server{
Addr: conf.ServerSetting.HttpIp + ":" + conf.ServerSetting.HttpPort,
3 years ago
Handler: router,
ReadTimeout: conf.ServerSetting.ReadTimeout,
WriteTimeout: conf.ServerSetting.WriteTimeout,
3 years ago
MaxHeaderBytes: 1 << 20,
}
util.PrintHelloBanner(debug.VersionInfo())
fmt.Fprintf(color.Output, "PaoPao service listen on %s\n",
color.GreenString(fmt.Sprintf("http://%s:%s", conf.ServerSetting.HttpIp, conf.ServerSetting.HttpPort)),
)
if err := s.ListenAndServe(); err != nil {
log.Fatalf("run app failed: %s", err)
}
3 years ago
}