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:
37
api/config_file.go
Normal file
37
api/config_file.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user