zero-ppanel/apps/api/ppanel.go

42 lines
1000 B
Go

// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package main
import (
"flag"
"fmt"
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/config"
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/handler"
"github.com/zero-ppanel/zero-ppanel/apps/api/internal/svc"
"github.com/zero-ppanel/zero-ppanel/pkg/result"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
"github.com/zeromicro/go-zero/rest/httpx"
)
var configFile = flag.String("f", "etc/api-dev.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
ctx := svc.NewServiceContext(c)
server.Use(ctx.SignatureMiddleware.Handle)
server.Use(ctx.DecryptMiddleware.Handle)
handler.RegisterHandlers(server, ctx)
// Registe global http error handler
httpx.SetErrorHandler(result.ErrHandler)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
server.Start()
}