{"record":{"id":"8814a197e8f19002","repo":"micro/go-micro","slug":"missing-service-name","errorCode":null,"errorMessage":"missing service name","messagePattern":"missing service name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/mdns/zone.go","lineNumber":70,"sourceCode":"}\n\n// NewMDNSService returns a new instance of MDNSService.\n//\n// If domain, hostName, or ips is set to the zero value, then a default value\n// will be inferred from the operating system.\n//\n// TODO(reddaly): This interface may need to change to account for \"unique\n// record\" conflict rules of the mDNS protocol.  Upon startup, the server should\n// check to ensure that the instance name does not conflict with other instance\n// names, and, if required, select a new name.  There may also be conflicting\n// hostName A/AAAA records.\nfunc NewMDNSService(instance, service, domain, hostName string, port int, ips []net.IP, txt []string) (*MDNSService, error) {\n\t// Sanity check inputs\n\tif instance == \"\" {\n\t\treturn nil, fmt.Errorf(\"missing service instance name\")\n\t}\n\tif service == \"\" {\n\t\treturn nil, fmt.Errorf(\"missing service name\")\n\t}\n\tif port == 0 {\n\t\treturn nil, fmt.Errorf(\"missing service port\")\n\t}\n\n\t// Set default domain\n\tif domain == \"\" {\n\t\tdomain = \"local.\"\n\t}\n\tif err := validateFQDN(domain); err != nil {\n\t\treturn nil, fmt.Errorf(\"domain %q is not a fully-qualified domain name: %v\", domain, err)\n\t}\n\n\t// Get host information if no host is specified.\n\tif hostName == \"\" {\n\t\tvar err error\n\t\thostName, err = os.Hostname()\n\t\tif err != nil {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/internal/util/mdns/zone.go#L52-L88","documentation":"NewMDNSService requires a non-empty service name — the DNS-SD service type such as \"_http._tcp.\". An empty service string fails the sanity check and the service cannot be registered.","triggerScenarios":"Calling NewMDNSService(instance, \"\", domain, hostName, port, ips, txt) with an empty service argument, e.g. a service-type variable that was never initialized in makeServiceWithServiceName or Register.","commonSituations":"Service type read from config where the key is missing; passing only the protocol (\"_tcp\") or a typo'd constant; refactors dropping the default \"_workstation._tcp\" value.","solutions":["Pass a valid DNS-SD service type, e.g. \"_http._tcp.\"","Default the service type in code if not configured: if service == \"\" { service = \"_http._tcp.\" }","Validate the service type against a known allowlist at startup"],"exampleFix":"// before\nsvc, err := NewMDNSService(\"myapp\", serviceType, \"\", \"\", 8080, ips, nil) // serviceType == \"\"\n// after\nif serviceType == \"\" {\n\tserviceType = \"_http._tcp.\"\n}\nsvc, err := NewMDNSService(\"myapp\", serviceType, \"\", \"\", 8080, ips, nil)","handlingStrategy":"validation","validationCode":"var validServices = map[string]bool{\"_http._tcp.\": true, \"_workstation._tcp.\": true}\nif !validServices[service] {\n\treturn fmt.Errorf(\"unsupported or empty service type: %q\", service)\n}","typeGuard":"func isValidServiceType(s string) bool {\n\treturn strings.HasPrefix(s, \"_\") && strings.Contains(s, \"._\")\n}","tryCatchPattern":"svc, err := NewMDNSService(instance, service, domain, hostName, port, ips, txt)\nif err != nil {\n\tif strings.Contains(err.Error(), \"missing service name\") {\n\t\treturn fmt.Errorf(\"service type (e.g. \\\"_http._tcp.\\\") must be configured: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Define service types as constants, never build them from unset variables","Validate against the DNS-SD shape (\"_name._proto\") before registering","Document the required service-type field in your config schema"],"tags":["validation","mdns","dnssd","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}