1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| func GatewayRun(cfg *configs.Config) {
ctx := context.Background()
mux := runtime.NewServeMux()
endpoint := ":" + cfg.Register.GrpcPort
opts := []grpc.DialOption{ grpc.WithTransportCredentials(insecure.NewCredentials()), }
if err := userPb.RegisterUserSrvHandlerFromEndpoint(ctx, mux, endpoint, opts); err != nil { tools.Log.Error(ctx, "[GatewayRun] RegisterUserSrvHandlerFromEndpoint err = %v", err) return }
tools.Log.Info(ctx, "launch http %s success at %s", cfg.Register.Name, "http://"+tools.GetOwnIP()+":"+cfg.Register.HttpPort)
if err := http.ListenAndServe(":"+cfg.Register.HttpPort, mux); err != nil { tools.Log.Error(ctx, "[GatewayRun] ListenAndServe err = %v", err) } }
|