Documentation ¶
Index ¶
Constants ¶
const VERSION = "1.1.2"
VERSION is envsync version
Variables ¶
var ( //ExecCommand cmd executor ExecCommand = exec.Command //IOWriteString alias command to write string IOWriteString = io.WriteString )
Functions ¶
This section is empty.
Types ¶
type EnvSyncer ¶
type EnvSyncer interface { // Sync synchronizes source and target. // Source is the default env or the sample env. // Target is the actual env. // Both source and target are string and indicate the location of the files. // // Any values in source that aren't in target will be written to target. // Any values in source that are in target won't be written to target. Sync(source, target string) error }
EnvSyncer describes some contracts to synchronize env.
type Syncer ¶
type Syncer struct { }
Syncer implements EnvSyncer.
func (*Syncer) Sync ¶
Sync implements EnvSyncer. Sync will read the file line by line. It will read the first '=' character. All characters prior to the first '=' character is considered as the key. All characters after the first '=' character until a newline character is considered as the value.
e.g: FOO=bar. FOO is the key and bar is the value.
Before the synchronization process, it will create .bak from target file as backup. During the synchronization process, there may be an error. If error occurred, target file will be restored from previously created .bak file. If the synchronization succeed, the key-values will be sorted and header will be added based on key's prefix e.g: for FOO_BAR, '#FOO' header will be added before the first key of FOO_