gogs_runner/init.go
2022-06-26 10:40:11 +08:00

48 lines
749 B
Go

package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"time"
)
func init() {
go setLogDestination()
go readConfigs()
}
func setLogDestination() {
for {
os.Mkdir(logDir, perm)
file := logDir + time.Now().Format("2006-01-02") + ".txt"
var err error
logFile, err = os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, perm)
if err != nil {
panic(err)
}
log.SetOutput(logFile)
time.Sleep(time.Minute)
}
}
func readConfigs() {
for {
data, err := ioutil.ReadFile("config.json")
if err != nil {
return
}
configsLock.Lock()
if err := json.Unmarshal(data, &configs); err != nil {
log.Printf("Error unmarshalling configs: %v\n", err)
}
configsLock.Unlock()
time.Sleep(time.Second * 10)
}
}