<commit_before>package boop

import (
  "io/ioutil"
  "encoding/json"
)

var default_config_file_locations = [...]string { "./config.json", "/usr/etc/boop/config.json" }
const default_port = 9180

type Command struct {
  Path string `json:"path"`
  Command string `json:"command"`
  OnlyAllowIps []string `json:"only_allow_ips"`
  LimitRate int `json:"limit_rate"`
}

type Config struct {
  Port int `json:"port"`
  OnlyAllowIps []string `json:"only_allow_ips"`
  Commands []Command `json:"commands"`
}

func LoadConfig() (*Config, error) {
  var err error
  var config *Config

  for _, v := range default_config_file_locations {
    if config, err = LoadConfigFromFile(v); err == nil {
      return config, nil
    }
  }
  return nil, err
}

func LoadConfigFromFile(location string) (*Config, error) {
  file_data, err := ioutil.ReadFile(location)
  if err != nil {
    return nil, err
  }

  return LoadConfigFromBytes(file_data)
}

func LoadConfigFromBytes(data []byte) (*Config, error) {
  var config Config
  err := json.Unmarshal(data, &config)
  if err != nil {
    return &config, err
  }

  fillInDefaultValues(&config)
  return &config, nil
}

func fillInDefaultValues(config *Config) (*Config) {
  if (config.Port == 0) {
    config.Port = default_port;
  }

  return config
}

<commit_msg>Added config option for specifying HTTP actions to respond to<commit_after>package boop

import (
  "io/ioutil"
  "encoding/json"
)

var default_config_file_locations = [...]string { "./config.json", "/usr/etc/boop/config.json" }
const default_port = 9180
const post_action = "POST"

type Command struct {
  Path string `json:"path"`
  Command string `json:"command"`
  OnlyAllowIps []string `json:"only_allow_ips"`
  LimitRate int `json:"limit_rate"`
  AllowActions []string `json:"allow_actions"`
}

type Config struct {
  Port int `json:"port"`
  OnlyAllowIps []string `json:"only_allow_ips"`
  Commands []Command `json:"commands"`
}

func LoadConfig() (*Config, error) {
  var err error
  var config *Config

  for _, v := range default_config_file_locations {
    if config, err = LoadConfigFromFile(v); err == nil {
      return config, nil
    }
  }
  return nil, err
}

func LoadConfigFromFile(location string) (*Config, error) {
  file_data, err := ioutil.ReadFile(location)
  if err != nil {
    return nil, err
  }

  return LoadConfigFromBytes(file_data)
}

func LoadConfigFromBytes(data []byte) (*Config, error) {
  var config Config
  err := json.Unmarshal(data, &config)
  if err != nil {
    return &config, err
  }

  fillInDefaultValues(&config)
  return &config, nil
}

func fillInDefaultValues(config *Config) (*Config) {
  if (config.Port == 0) {
    config.Port = default_port;
  }

  // Make sure we allow only POST by
  // default
  for _, v := range config.Commands {
    if len(v.AllowActions) == 0 {
      v.AllowActions = append(v.AllowActions, post_action)
    }
  }

  return config
}


{'fraction_non_alphanumeric': 0.12782727895819054, 'fraction_numerical': 0.0037697052775873888, 'mean_word_length': 3.8488372093023258, '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': '4518378', 'n_tokens_mistral': 986, 'n_tokens_neox': 957, 'n_words': 261}