Incremental progress

This commit is contained in:
Ben 2025-07-27 16:20:52 -07:00
parent 9a7834c330
commit ab3b46713f
Signed by: webmaster
GPG key ID: A5FCBAF34E6E8B50
6 changed files with 99 additions and 22 deletions

View file

@ -10,13 +10,14 @@ import (
"strings"
)
// import "fmt"
/* Object to handle what is in a JSON config */
type Config struct {
configData map[string][]string;
}
/* Default Config object */
var GlobalConfig * Config;
/* Opens and reads a file at the path */
func NewConfig(filePath string) (newConfig *Config, err error) {
// Open file
@ -30,8 +31,7 @@ func NewConfig(filePath string) (newConfig *Config, err error) {
// Read lines into newConfigData
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
parts := strings.SplitN(line, " ", 2);
parts := strings.SplitN(scanner.Text(), " ", 2);
if len(parts) != 2 {err = errors.New("Bad config file!"); return;}
newConfigData[parts[0]] = append(newConfigData[parts[0]], parts[1]);
}
@ -41,4 +41,21 @@ func NewConfig(filePath string) (newConfig *Config, err error) {
}
/* Gets a reference copy to the config data */
func (config Config) GetConfigData() map[string][]string {return config.configData;}
func (config * Config) GetConfigData() map[string][]string {
return config.configData;
}
/* Returns if a bearer key is authorized for the path in this Config object
@return false for any situation that isn't a valid match */
func (config * Config) ValidateBearerKey(bearerKey string, request string) bool {
paths, exists := config.configData[bearerKey];
if !exists {return false}
for _, matchTo := range paths {
if match(request, matchTo) {
return true;
}
}
return false;
}