<commit_before>package main

import (
	"encoding/json"
	"log"

	"github.com/hoisie/redis"
)

// Lookup the record in Redis
func Lookup(client redis.Client, key string) []byte {
	log.Printf("⌘ Lookup %s\n", key)
	byteary, err := client.Get(key)
	log.Printf("  %s\n", string(byteary))
	if err != nil {
		log.Printf("Error during Lookup %s: %s\n", key, err)
		return nil
	}
	return byteary
}

// WildCardLookup of the record in Redis
func WildCardLookup(client redis.Client, key string) []byte {
	wc := "*." + key
	return Lookup(client, wc)
}

// Get the record for key, apply wildcard if bare record doesn't work
func (s *RedisDNSServer) Get(key string) *Record {
	r := &Record{}
	bAry := Lookup(s.redisClient, key)
	if bAry == nil {
		return r
	}
	err := r.Parse(bAry)<commit_msg>Fix wildcard lookup<commit_after>package main

import (
	"encoding/json"
	"log"
	"strings"

	"github.com/hoisie/redis"
)

// Lookup the record in Redis
func Lookup(client redis.Client, key string) []byte {
	log.Printf("⌘ Lookup %s\n", key)
	byteary, err := client.Get(key)
	log.Printf("  %s\n", string(byteary))
	if err != nil {
		log.Printf("Error during Lookup %s: %s\n", key, err)
		return nil
	}
	return byteary
}

// WildCardLookup of the record in Redis
func WildCardLookup(client redis.Client, key string) []byte {
	wc := wildcardHostName(key)
	return Lookup(client, wc)
}

func wildcardHostName(hostName string) string {
	nameParts := strings.SplitAfterN(hostName, ".", 2)
	return "*." + nameParts[1]
}

// Get the record for key, apply wildcard if bare record doesn't work
func (s *RedisDNSServer) Get(key string) *Record {
	r := &Record{}
	bAry := Lookup(s.redisClient, key)
	if bAry == nil {
		bAry = WildCardLookup(s.redisClient, key)
		if bAry == nil {
			return r
		}
	}
	err := r.Parse(bAry)
{'fraction_non_alphanumeric': 0.146218487394958, 'fraction_numerical': 0.0011204481792717086, 'mean_word_length': 3.9473684210526314, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2577087', 'n_tokens_mistral': 704, 'n_tokens_neox': 691, 'n_words': 193}