<commit_before>package main

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"strconv"
	"time"
)

func apiLogHandler(event string) {
	fmt.Fprintln(os.Stderr, event, "-", time.Now())
}
func VersionHandler(logger func(string)) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		logger("Version")
		var jsonResp struct {
			Text string `json:"version"`
		}
		jsonResp.Text = Version
		message, err := json.Marshal(jsonResp)
		if err != nil {
			logger(fmt.Sprintf("%s", err))
		}
		w.Write(message)
	})
}

func DoorStatusHandler(doorStatus func(int) (string, error), logger func(string), statusPin int) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		var jsonResp struct {
			Text string `json:"door_status"`
		}

		status, err := doorStatus(statusPin)
		if err != nil {
			errMessage := fmt.Sprintf("%s", err)
			logger(errMessage)
			jsonResp.Text = errMessage
			w.WriteHeader(422)
		}

		jsonResp.Text = status
		message, err := json.Marshal(jsonResp)
		if err != nil {
			logger(fmt.Sprintf("%s", err))
		}
		w.Write(message)
	})
}

func RelayHandle(toggleSwitch func(int, int) error, logger func(string), pinNumber int, sleepTimeout int) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		logger("TOGGLE DOOR")
		err := toggleSwitch(pinNumber, sleepTimeout)
		if err != nil {
			errMessage := "Could not write to pin"
			logger(errMessage)<commit_msg>Add better error message for doorStatus<commit_after>package main

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"strconv"
	"time"
)

func apiLogHandler(event string) {
	fmt.Fprintln(os.Stderr, event, "-", time.Now())
}
func VersionHandler(logger func(string)) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		logger("Version")
		var jsonResp struct {
			Text string `json:"version"`
		}
		jsonResp.Text = Version
		message, err := json.Marshal(jsonResp)
		if err != nil {
			logger(fmt.Sprintf("%s", err))
		}
		w.Write(message)
	})
}

func DoorStatusHandler(doorStatus func(int) (string, error), logger func(string), statusPin int) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		var jsonResp struct {
			Text string `json:"door_status"`
		}

		status, err := doorStatus(statusPin)
		if err != nil {
			errMessage := fmt.Sprintf("Could not read pin '%d' on Raspberry Pi", statusPin)
			logger(errMessage)
			jsonResp.Text = errMessage
			w.WriteHeader(422)
		}

		jsonResp.Text = status
		message, err := json.Marshal(jsonResp)
		if err != nil {
			logger(fmt.Sprintf("%s", err))
		}
		w.Write(message)
	})
}

func RelayHandle(toggleSwitch func(int, int) error, logger func(string), pinNumber int, sleepTimeout int) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		logger("TOGGLE DOOR")
		err := toggleSwitch(pinNumber, sleepTimeout)
		if err != nil {
			errMessage := "Could not write to pin"
			logger(errMessage)
{'fraction_non_alphanumeric': 0.13790870831984461, 'fraction_numerical': 0.0032372936225315637, 'mean_word_length': 4.411558669001751, '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': '4051691', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1036, 'n_words': 251}