Incremental progress
This commit is contained in:
parent
9a7834c330
commit
ab3b46713f
6 changed files with 99 additions and 22 deletions
27
conf/conf.go
27
conf/conf.go
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue