package server import ( "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" "wallet-system/internal/conf" "wallet-system/internal/service" v1 "wallet-system/api/walletSystem/v1" ) // NewHTTPServer new an HTTP server. func NewHTTPServer(c *conf.Server, wallet *service.WalletService, 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)) } srv := http.NewServer(opts...) v1.RegisterWalletHTTPServer(srv, wallet) return srv }