2023-07-06 10:23:43 +00:00
|
|
|
package backendtest
|
2023-06-27 10:09:56 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-07-24 11:17:02 +00:00
|
|
|
|
|
|
|
authtest "fusenapi/server/auth/test"
|
2023-06-27 10:09:56 +00:00
|
|
|
"fusenapi/server/backend/internal/config"
|
|
|
|
"fusenapi/server/backend/internal/handler"
|
|
|
|
"fusenapi/server/backend/internal/svc"
|
2023-07-06 10:23:43 +00:00
|
|
|
"fusenapi/utils/fstests"
|
2023-06-27 10:09:56 +00:00
|
|
|
"log"
|
2023-07-06 10:23:43 +00:00
|
|
|
"runtime"
|
2023-06-27 10:09:56 +00:00
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/conf"
|
|
|
|
"github.com/zeromicro/go-zero/rest"
|
|
|
|
)
|
|
|
|
|
|
|
|
var cnf config.Config
|
2023-07-06 10:23:43 +00:00
|
|
|
var userver, gserver *rest.Server
|
2023-06-27 10:09:56 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
log.SetFlags(log.Llongfile)
|
2023-07-24 11:17:02 +00:00
|
|
|
userver = authtest.GetTestServer()
|
2023-06-27 10:09:56 +00:00
|
|
|
gserver = GetTestServer()
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetTestServer() *rest.Server {
|
|
|
|
|
2023-07-06 10:23:43 +00:00
|
|
|
conf.MustLoad(fstests.GetEtcYamlPathAuto(), &cnf)
|
2023-06-27 10:09:56 +00:00
|
|
|
|
|
|
|
server := rest.MustNewServer(cnf.RestConf)
|
2023-07-06 10:23:43 +00:00
|
|
|
runtime.SetFinalizer(server, func(server *rest.Server) {
|
|
|
|
if server != nil {
|
|
|
|
server.Stop()
|
|
|
|
}
|
|
|
|
})
|
2023-06-27 10:09:56 +00:00
|
|
|
|
|
|
|
ctx := svc.NewServiceContext(cnf)
|
|
|
|
handler.RegisterHandlers(server, ctx)
|
|
|
|
|
|
|
|
fmt.Printf("Starting server at %s:%d...\n", cnf.Host, cnf.Port)
|
|
|
|
return server
|
|
|
|
}
|