Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
SDP--PKI-CyberSec-/CTng/config/config_loaders.go
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
56 lines (52 sloc)
1.56 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package config | |
/* | |
Code Ownership: | |
Isaac - Responsible for functions | |
Finn - Helped with review+code refactoring | |
*/ | |
import ( | |
crypto "CTng/crypto" | |
"encoding/json" | |
"io/ioutil" | |
"log" | |
// this is just to check that the values are being updated without having to put a bunch of print statements | |
) | |
func LoadConfiguration(config interface{}, file string) { //takes in the struct that it is updating and the file it is updating with | |
// Let's first read the file | |
content, err := ioutil.ReadFile(file) | |
if err != nil { | |
log.Fatal("Error when opening file: ", err) | |
} | |
// Now let's unmarshall the data into `payload` | |
err = json.Unmarshal(content, config) | |
if err != nil { | |
log.Fatal("Error during Unmarshal(): ", err) | |
} | |
} | |
func LoadGossiperConfig(publicpath string, privatepath string, cryptopath string) (Gossiper_config, error) { | |
c := new(Gossiper_config) | |
c_pub := new(Gossiper_public_config) | |
LoadConfiguration(c, privatepath) | |
LoadConfiguration(c_pub, publicpath) | |
c.Public = c_pub | |
crypto, err := crypto.ReadCryptoConfig(cryptopath) | |
c.Crypto = crypto | |
if err != nil { | |
return *c, err | |
} | |
return *c, nil | |
} | |
//Identical to above, but for the monitor. | |
func LoadMonitorConfig(publicpath string, privatepath string, cryptopath string) (Monitor_config, error) { | |
c := new(Monitor_config) | |
c_pub := new(Monitor_public_config) | |
LoadConfiguration(c, privatepath) | |
LoadConfiguration(c_pub, publicpath) | |
c.Public = c_pub | |
crypto, err := crypto.ReadCryptoConfig(cryptopath) | |
c.Crypto = crypto | |
if err != nil { | |
return *c, err | |
} | |
return *c, nil | |
} |