<commit_before>// +build windows

package windows

import (
	"strings"
	"unsafe"

	"github.com/mackerelio/golib/logging"
	"github.com/mackerelio/mackerel-client-go"

	"github.com/mackerelio/mackerel-agent/util/windows"
)

// KernelGenerator XXX
type KernelGenerator struct {
}

var kernelLogger = logging.GetLogger("spec.kernel")

// Generate XXX
func (g *KernelGenerator) Generate() (interface{}, error) {
	results := make(mackerel.Kernel)

	osname, _, err := windows.RegGetString(
		windows.HKEY_LOCAL_MACHINE,
		`Software\Microsoft\Windows NT\CurrentVersion`,
		`ProductName`)
	if err != nil {
		return nil, err
	}
	edition, _, err := windows.RegGetString(
		windows.HKEY_LOCAL_MACHINE,
		`Software\Microsoft\Windows NT\CurrentVersion`,
		`EditionID`)
	if err != nil {
		return nil, err
	}
	version, _, err := windows.RegGetString(
		windows.HKEY_LOCAL_MACHINE,
		`Software\Microsoft\Windows NT\CurrentVersion`,
		`CurrentVersion`)
	if err != nil {
		return nil, err
	}
	release, errno, err := windows.RegGetString(
		windows.HKEY_LOCAL_MACHINE,
		`Software\Microsoft\Windows NT\CurrentVersion`,
		`CSDVersion`)
	if err != nil && errno != windows.ERROR_FILE_NOT_FOUND { // CSDVersion is nullable
		return nil, err
	}

	if edition != "" && strings.Index(osname, edition) == -1 {
		osname += " (" + edition + ")"
	}

	results["name"] = "Microsoft Windows"
	results["os"] = osname
	results["version"] = version
	results["release"] = release

	var systemInfo windows.SYSTEM_INFO
	windows.GetSystemInfo.Call(uintptr(unsafe.Pointer(&systemInfo)))
	switch systemInfo.ProcessorArchitecture {
	case 0:
		results["machine"] = "x86"
	case 1:
		results["machine"] = "mips"
	case 2:
		results["machine"] = "alpha"
	case 3:
		results["machine"] = "ppc"
	case 4:
		results["machine"] = "shx"
	case 5:
		results["machine"] = "arm"
	case 6:
		results["machine"] = "ia64"
	case 7:
		results["machine"] = "alpha64"
	case 8:
		results["machine"] = "msil"
	case 9:
		results["machine"] = "amd64"
	case 10:
		results["machine"] = "ia32_on_win64"
	}

	return results, nil
}
<commit_msg>Use const<commit_after>// +build windows

package windows

import (
	"strings"
	"unsafe"

	"github.com/mackerelio/golib/logging"
	"github.com/mackerelio/mackerel-client-go"

	"github.com/mackerelio/mackerel-agent/util/windows"
)

const registryKey = `Software\Microsoft\Windows NT\CurrentVersion`

// KernelGenerator XXX
type KernelGenerator struct {
}

var kernelLogger = logging.GetLogger("spec.kernel")

// Generate XXX
func (g *KernelGenerator) Generate() (interface{}, error) {
	results := make(mackerel.Kernel)

	osname, _, err := windows.RegGetString(
		windows.HKEY_LOCAL_MACHINE, registryKey, `ProductName`)
	if err != nil {
		return nil, err
	}
	edition, _, err := windows.RegGetString(
		windows.HKEY_LOCAL_MACHINE, registryKey, `EditionID`)
	if err != nil {
		return nil, err
	}
	version, _, err := windows.RegGetString(
		windows.HKEY_LOCAL_MACHINE, registryKey, `CurrentVersion`)
	if err != nil {
		return nil, err
	}
	release, errno, err := windows.RegGetString(
		windows.HKEY_LOCAL_MACHINE, registryKey, `CSDVersion`)
	if err != nil && errno != windows.ERROR_FILE_NOT_FOUND { // CSDVersion is nullable
		return nil, err
	}

	if edition != "" && strings.Index(osname, edition) == -1 {
		osname += " (" + edition + ")"
	}

	results["name"] = "Microsoft Windows"
	results["os"] = osname
	results["version"] = version
	results["release"] = release

	var systemInfo windows.SYSTEM_INFO
	windows.GetSystemInfo.Call(uintptr(unsafe.Pointer(&systemInfo)))
	switch systemInfo.ProcessorArchitecture {
	case 0:
		results["machine"] = "x86"
	case 1:
		results["machine"] = "mips"
	case 2:
		results["machine"] = "alpha"
	case 3:
		results["machine"] = "ppc"
	case 4:
		results["machine"] = "shx"
	case 5:
		results["machine"] = "arm"
	case 6:
		results["machine"] = "ia64"
	case 7:
		results["machine"] = "alpha64"
	case 8:
		results["machine"] = "msil"
	case 9:
		results["machine"] = "amd64"
	case 10:
		results["machine"] = "ia32_on_win64"
	}

	return results, nil
}

{'fraction_non_alphanumeric': 0.149009900990099, 'fraction_numerical': 0.012376237623762377, 'mean_word_length': 4.4830393487109905, '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': '1035651', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1422, 'n_words': 313}