Package profile contains all of the code for managing multiple credential files. A profile consists of a section in the default credentials file, with both the username and password, and a configuration file that is contained under the config directory and named after the profile.
- type Profile
- func (thisProfile *Profile) DeleteAttribute(sectionName string, key string) error
- func (thisProfile *Profile) GetAllAttributes() map[string]map[string]string
- func (thisProfile *Profile) GetAllSectionAttributes(sectionName string) (map[string]string, error)
- func (thisProfile *Profile) GetAttribute(sectionName string, key string) string
- func (thisProfile *Profile) SetAttribute(sectionName string, key string, value string) error
const ERR_DELETED_ATTRIBUTE_NOT_EXIST = "the attribute you have attempted to delete does not exist"
const ERR_MUST_MATCH_REGEX = "sorry the section name and value must only include letters, numbers and underscores [0-9A-Za-z_]"
const ERR_NOT_YET_IMPLEMENTED = "that feature has not been implemented yet"
const ERR_PROFILE_DID_NOT_EXIST = "the config file did not exist and a profile has not been loaded"
const ERR_PROFILE_NAME_MUST_MATCH_REGEX = "sorry the profile name must only include letters, numbers and underscores [0-9A-Za-z_]"
const ERR_PROFILE_NOT_INITIALIZED = "sorry the profile is not initialized"
const ERR_SECTION_NOT_EXIST = "that section does not exist in the profile"
Profile is used to hold information about the user settings or metadata attached to a Credential. Each profile stores its credential in the main credentials file, then the other information is held under config/profile_name
New is responsible for constructing a new, blank profile to be used by a Credential. It is important to note, that this function does not save a profile, and this needs to be done using the Save() function.
func (*Profile) DeleteAttribute ¶
DeleteAttribute removes an attribute from a profile. It is important to note that until the Profile is Save()d, the attribute may still exist on the file system.
func (*Profile) GetAllAttributes ¶
GetAllAttribute simply returns the a nested map that has two sets of keys, a section key, and then a normal key. Any attributes without a section will be returned under the section key of "default".
Example: Map Structure
default: my_key: my_value a_section: my_key: my_value a_key: a_value b_section: my_key: my_value b_key: b_value
func (*Profile) GetAllSectionAttributes ¶
GetAllSection attributes is responsible for returning all of the attributes for one section. It returns this as a simple map with the key and value for each attribute only. There are no section references returned by this function.
func (*Profile) GetAttribute ¶
GetAttribute retrieves an attribute from a profile section. If the section name is blank, the attribute will be retrieved from the default store which has no section name.
func (*Profile) SetAttribute ¶
SetAttribute is responsible for setting an attribute against a section name. If the section name is blank, the attribute will be stored without a section.
Example: With Section
myProfile.SetAttribute("a_section", "a_key", "a_value") // my_profile (ini) // [a_section] // a_key = a_value <-- this value will be set
Example: No Section
myProfile.SetAttribute("", "a_key", "a_value") // my_profile (ini) // a_key = a_value <-- this value will be set // [a_section] // a_key = a_value