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.
132 lines
4.9 KiB
132 lines
4.9 KiB
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
"github.com/go-kratos/kratos/v2/middleware/logging"
|
|
"github.com/go-kratos/kratos/v2/middleware/recovery"
|
|
"github.com/go-kratos/kratos/v2/transport/http"
|
|
"github.com/gorilla/handlers"
|
|
"github.com/gorilla/mux"
|
|
"matchmaking-system/internal/conf"
|
|
"matchmaking-system/internal/data/socket"
|
|
"matchmaking-system/internal/pkg/flags"
|
|
"matchmaking-system/internal/pkg/logging/applogger"
|
|
"matchmaking-system/internal/service"
|
|
|
|
backend "matchmaking-system/api/matchmaking/v1/backend"
|
|
block "matchmaking-system/api/matchmaking/v1/block"
|
|
forex "matchmaking-system/api/matchmaking/v1/forex"
|
|
money "matchmaking-system/api/matchmaking/v1/money"
|
|
option "matchmaking-system/api/matchmaking/v1/option"
|
|
order "matchmaking-system/api/matchmaking/v1/order"
|
|
share "matchmaking-system/api/matchmaking/v1/share"
|
|
virtually "matchmaking-system/api/matchmaking/v1/virtually"
|
|
)
|
|
|
|
// NewHTTPServer
|
|
//
|
|
// @Description:
|
|
// @param c
|
|
// @param s
|
|
// @param logger
|
|
// @return *http.Server
|
|
func NewHTTPServer(c *conf.Server, s *service.ConduitService, logger log.Logger) *http.Server {
|
|
var opts = []http.ServerOption{
|
|
http.Middleware(
|
|
recovery.Recovery(),
|
|
logging.Server(logger),
|
|
),
|
|
http.Filter(handlers.CORS(
|
|
handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization", "token", "Language"}),
|
|
handlers.AllowedMethods([]string{"GET", "POST", "PUT", "HEAD", "OPTIONS"}),
|
|
handlers.AllowedOrigins([]string{"*"}),
|
|
handlers.AllowCredentials(),
|
|
)),
|
|
}
|
|
if c.Http.Network != "" {
|
|
opts = append(opts, http.Network(c.Http.Network))
|
|
}
|
|
if c.Http.Addr != "" {
|
|
opts = append(opts, http.Address(c.Http.Addr))
|
|
}
|
|
|
|
// wss 订单订阅行情
|
|
var wss string
|
|
routerQuotes := mux.NewRouter()
|
|
switch flags.CheckEnvironment {
|
|
case flags.CheckSport: // Spots Wss
|
|
wss = fmt.Sprintf("/%v", flags.SpotsWss)
|
|
case flags.CheckContract: // Contract Wss
|
|
wss = fmt.Sprintf("/%v", flags.ContractWss)
|
|
case flags.CheckSecond: // Second Wss
|
|
wss = fmt.Sprintf("/%v", flags.SecondWss)
|
|
case flags.CheckForex: // Forex Wss
|
|
wss = fmt.Sprintf("/%v", flags.ForexWss)
|
|
case flags.CheckMoney: // Money Wss
|
|
wss = fmt.Sprintf("/%v", flags.MoneyWss)
|
|
case flags.CheckShareUs: // Share Us Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareUsWss)
|
|
case flags.CheckShareMys: // Share Mys Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareMysWss)
|
|
case flags.CheckShareTha: // Share Tha Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareThaWss)
|
|
case flags.CheckShareIdn: // Share Idn Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareIdnWss)
|
|
case flags.CheckShareInr: // Share Inr Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareInrWss)
|
|
case flags.CheckShareSgd: // Share Sgd Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareSgdWss)
|
|
case flags.CheckShareGbx: // Share Gbx Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareGbxWss)
|
|
case flags.CheckShareHkd: // Share Hkd Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareHkdWss)
|
|
case flags.CheckShareEur: // Share Eur Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareEurWss)
|
|
case flags.CheckShareFur: // Share Fur Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareFurWss)
|
|
case flags.CheckShareJpy: // Share Jpy Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareJpyWss)
|
|
case flags.CheckShareBrl: // Share Brl Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareBrlWss)
|
|
case flags.CheckShareBlk: // Share Blk Wss
|
|
wss = fmt.Sprintf("/%v", flags.ShareBlkWss)
|
|
case flags.CheckOptionInr: // Option Inr Wss
|
|
wss = fmt.Sprintf("/%v", flags.OptionInrWss)
|
|
case flags.CheckAdmin: // Admin Wss
|
|
wss = fmt.Sprintf("/%v", flags.AdminWss)
|
|
case flags.CheckAdminBlk: // admin Blk Wss
|
|
wss = fmt.Sprintf("/%v", flags.AdminBlkWss)
|
|
default:
|
|
applogger.Error(flags.ErrOrderSeven.Error())
|
|
}
|
|
routerQuotes.HandleFunc(wss, socket.WsHandlerOrder)
|
|
|
|
// http 订单静态服务
|
|
srv := http.NewServer(opts...)
|
|
order.RegisterOrderHTTPServer(srv, s) // OrderPre
|
|
virtually.RegisterSecondHTTPServer(srv, s) // Second
|
|
virtually.RegisterSpotsHTTPServer(srv, s) // Spots
|
|
virtually.RegisterContractHTTPServer(srv, s) // Contract
|
|
forex.RegisterForexHTTPServer(srv, s) // Forex
|
|
money.RegisterMoneyHTTPServer(srv, s) // Money
|
|
backend.RegisterBackendHTTPServer(srv, s) // Backend
|
|
share.RegisterShareUsHTTPServer(srv, s) // Us
|
|
share.RegisterShareThaHTTPServer(srv, s) // Tha
|
|
share.RegisterShareIdnHTTPServer(srv, s) // Idn
|
|
share.RegisterShareInrHTTPServer(srv, s) // Inr
|
|
share.RegisterShareMysHTTPServer(srv, s) // Mys
|
|
share.RegisterShareSgdHTTPServer(srv, s) // Sgd
|
|
share.RegisterShareGbxHTTPServer(srv, s) // Gbx
|
|
share.RegisterShareHkdHTTPServer(srv, s) // Hkd
|
|
share.RegisterShareEurHTTPServer(srv, s) // Eur
|
|
share.RegisterShareFurHTTPServer(srv, s) // Fur
|
|
share.RegisterShareJpyHTTPServer(srv, s) // Jpy
|
|
share.RegisterShareBrlHTTPServer(srv, s) // Brl
|
|
block.RegisterBlockTradeHTTPServer(srv, s) // Block stock
|
|
option.RegisterOptionInrHTTPServer(srv, s) // OptionInr
|
|
|
|
srv.HandlePrefix("/", routerQuotes)
|
|
|
|
return srv
|
|
}
|
|
|