func Proto(port uint32) string {
	switch port {
	case 80:
		return "http"
	case 443:
		return "https"
	default:
		return "tcp"
	}
}
Proto infers the port name based on the port number
package infer
import (
	"fmt"
	"net"
	"strings"
	"istio.io/api/networking/v1alpha3"
	ic "istio.io/client-go/pkg/apis/networking/v1alpha3"
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func ServiceEntry(owner v1.OwnerReference, prefix, host string, endpoints []*v1alpha3.ServiceEntry_Endpoint) *ic.ServiceEntry {
	addresses := []string{}
	if len(endpoints) > 0 {
		if ip := net.ParseIP(endpoints[0].Address); ip != nil {
			addresses = []string{endpoints[0].Address}
		}
	}
	return &ic.ServiceEntry{
		TypeMeta: v1.TypeMeta{},
		ObjectMeta: v1.ObjectMeta{
			Name:            ServiceEntryName(prefix, host),
			OwnerReferences: []v1.OwnerReference{owner},
		},
		Spec: v1alpha3.ServiceEntry{
			Hosts:     []string{host},
			Addresses: addresses,
			Location:   v1alpha3.ServiceEntry_MESH_EXTERNAL,
			Resolution: Resolution(endpoints),
			Ports:      Ports(endpoints),
			Endpoints:  endpoints,
		},
	}
}
func Endpoint(address string, port uint32) *v1alpha3.ServiceEntry_Endpoint {
	return &v1alpha3.ServiceEntry_Endpoint{
		Address: address,
		Ports:   map[string]uint32{Proto(port): port},
	}
}