1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

api: allow configuration files

Closes https://gitlab.com/commento/commento-ce/issues/55
This commit is contained in:
Adhityaa
2018-06-21 20:51:10 +05:30
parent 89852ef76a
commit 1b1c97f0f0
2 changed files with 45 additions and 0 deletions

37
api/config_file.go Normal file
View File

@ -0,0 +1,37 @@
package main
import (
"bufio"
"os"
"strings"
)
func configFileLoad(filepath string) error {
file, err := os.Open(filepath)
if err != nil {
return err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
i := strings.Index(line, "=")
if i == -1 {
continue
}
key := line[:i]
value := line[i+1:]
if !strings.HasPrefix(key, "COMMENTO_") {
continue
}
os.Setenv(key[9:], value)
}
return nil
}