| 637 | } |
| 638 | |
| 639 | func (s *ServerConfig) SetDefaults() error { |
| 640 | if s.ListenV4 == nil { |
| 641 | if !util.IsTest() || os.Getenv("FORCE_TEST_LISTEN_V4") == "true" { |
| 642 | s.ListenV4 = util.BoolPtr(true) |
| 643 | } |
| 644 | } |
| 645 | if s.HttpHostV4 == nil { |
| 646 | s.HttpHostV4 = util.StringPtr("0.0.0.0") |
| 647 | } |
| 648 | if s.HttpHostV6 == nil { |
| 649 | s.HttpHostV6 = util.StringPtr("[::]") |
| 650 | } |
| 651 | // Handle deprecated HttpPort -> HttpPortV4 migration |
| 652 | if s.HttpPort != nil && s.HttpPortV4 == nil { |
| 653 | s.HttpPortV4 = s.HttpPort // Migrate deprecated field |
| 654 | } |
| 655 | if s.HttpPortV4 == nil { |
| 656 | s.HttpPortV4 = util.IntPtr(4000) |
| 657 | } |
| 658 | // Keep HttpPort for backward compatibility (will be same as HttpPortV4) |
| 659 | if s.HttpPort == nil { |
| 660 | s.HttpPort = s.HttpPortV4 |
| 661 | } |
| 662 | // Handle deprecated HttpPort -> HttpPortV6 migration for backward compatibility |
| 663 | if s.HttpPort != nil && s.HttpPortV6 == nil { |
| 664 | s.HttpPortV6 = util.IntPtr(*s.HttpPort + 1000) |
| 665 | } |
| 666 | if s.HttpPortV6 == nil { |
| 667 | s.HttpPortV6 = util.IntPtr(5000) // Default: avoid 4001 (metrics) |
| 668 | } |
| 669 | if s.GrpcEnabled == nil { |
| 670 | s.GrpcEnabled = util.BoolPtr(false) |
| 671 | } |
| 672 | if s.GrpcHostV4 == nil && s.HttpHostV4 != nil { |
| 673 | v := *s.HttpHostV4 |
| 674 | s.GrpcHostV4 = &v |
| 675 | } |
| 676 | if s.GrpcPortV4 == nil && s.HttpPortV4 != nil { |
| 677 | v := *s.HttpPortV4 |
| 678 | s.GrpcPortV4 = &v |
| 679 | } |
| 680 | if s.GrpcHostV6 == nil && s.HttpHostV6 != nil { |
| 681 | v := *s.HttpHostV6 |
| 682 | s.GrpcHostV6 = &v |
| 683 | } |
| 684 | if s.GrpcPortV6 == nil && s.HttpPortV6 != nil { |
| 685 | v := *s.HttpPortV6 |
| 686 | s.GrpcPortV6 = &v |
| 687 | } |
| 688 | if s.GrpcMaxRecvMsgSize == nil { |
| 689 | s.GrpcMaxRecvMsgSize = util.IntPtr(100 * 1024 * 1024) |
| 690 | } |
| 691 | if s.GrpcMaxSendMsgSize == nil { |
| 692 | s.GrpcMaxSendMsgSize = util.IntPtr(100 * 1024 * 1024) |
| 693 | } |
| 694 | if s.MaxTimeout == nil { |
| 695 | d := Duration(150 * time.Second) |
| 696 | s.MaxTimeout = &d |