Redoing program to center around JSONRPC instead of a more REST-like API
This commit is contained in:
parent
ed4bbeb608
commit
be8936a665
15 changed files with 209 additions and 170 deletions
37
auth/auth.go
Normal file
37
auth/auth.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package auth
|
||||
|
||||
/* This file contains the AuthAuthConfig object and its methods, which handle reading
|
||||
from a config file and matching requests to the whitelist. */
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
/* Stores a map between a string (bearer token) and a list of unmarshaled JSONS */
|
||||
var authConfig any;
|
||||
var authConfigSetup bool = false;
|
||||
|
||||
/* Opens and reads a file at the path */
|
||||
func SetupAuthConfig(filePath string) (err error) {
|
||||
if authConfigSetup {return errors.New("Auth configuration already set up!")}
|
||||
|
||||
// Open and read file contents
|
||||
fileContents, err := os.ReadFile(filePath);
|
||||
if err != nil {return}
|
||||
|
||||
// Unmarshal
|
||||
authConfig = unmarshalJSON(fileContents);
|
||||
if authConfig == nil {return errors.New("Invalid JSON config!");}
|
||||
|
||||
print(match(authConfig, authConfig), "\n")
|
||||
|
||||
// Finish setup
|
||||
authConfigSetup = true;
|
||||
return nil;
|
||||
}
|
||||
|
||||
/* Gets a reference copy to the config data */
|
||||
func GetAuthConfigData() (any, bool) {
|
||||
return authConfig, authConfigSetup;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue