thrift/thrift-gen/extends.go
func setExtends(state map[string]parseState) error {
	for _, v := range state {
		for _, s := range v.services {
			if s.Extends == "" {
				continue
			}

			var searchServices []*Service
			var searchFor string
			parts := strings.SplitN(s.Extends, ".", 2)
			// If it's not imported, then look at the current file's services.
			if len(parts) < 2 {
				searchServices = v.services
				searchFor = s.Extends
			} else {
				include := v.global.includes[parts[0]]
				s.ExtendsPrefix = include.pkg + "."
				searchServices = state[include.file].services
				searchFor = parts[1]
			}

			foundService := sort.Search(len(searchServices), func(i int) bool {
				return searchServices[i].Name >= searchFor
			})
			if foundService == len(searchServices) {
				return fmt.Errorf("failed to find base service %q for %q", s.Extends, s.Name)
			}
			s.ExtendsService = searchServices[foundService]
		}
	}

	return nil
}
func setExtends(state map[string]parseState) error {
	for _, v := range state {
		for _, s := range v.services {
			if s.Extends == "" {
				continue
			}

			var searchServices []*Service
			var searchFor string
			parts := strings.SplitN(s.Extends, ".", 2)
			// If it's not imported, then look at the current file's services.
			if len(parts) < 2 {
				searchServices = v.services
				searchFor = s.Extends
			} else {
				include := v.global.includes[parts[0]]
				s.ExtendsPrefix = include.pkg + "."
				searchServices = state[include.file].services
				searchFor = parts[1]
			}

			foundService := sort.Search(len(searchServices), func(i int) bool {
				return searchServices[i].Name >= searchFor
			})
			if foundService == len(searchServices) {
				return fmt.Errorf("failed to find base service %q for %q", s.Extends, s.Name)
			}
			s.ExtendsService = searchServices[foundService]
		}
	}

	return nil
}
// setExtends will set the ExtendsService for all services.
// It is done after all files are parsed, as services may extend those
// found in an included file.