code: func (hr *Resolver) CNAMEFlatten(ctx context.Context, host string) string {
  	if hr.cache == nil {
  		hr.cache = cache.New(30*time.Minute, 5*time.Minute)
  	}
  
  	result := host
  	request := host
  
  	value, found := hr.cache.Get(host)
  	if found {
  		return value.(string)
  	}
  
  	logger := log.FromContext(ctx)
  	var cacheDuration = 0 * time.Second
  	for depth := 0; depth < hr.ResolvDepth; depth++ {
  		resolv, err := cnameResolve(ctx, request, hr.ResolvConfig)
  		if err != nil {
  			logger.Error(err)
  			break
  		}
  		if resolv == nil {
  			break
  		}
  
  		result = resolv.Record
  		if depth == 0 {
  			cacheDuration = resolv.TTL
  		}
  		request = resolv.Record
  	}
  
  	if err := hr.cache.Add(host, result, cacheDuration); err != nil {
  		logger.Error(err)
  	}
  
  	return result
  }
docs: // CNAMEFlatten check if CNAME record exists, flatten if possible.