Просмотр исходного кода

reading config and write log into absolute path using current directory

master
patrick 5 лет назад
Родитель
Сommit
1882acf44b
3 измененных файлов: 27 добавлений и 4 удалений
  1. +4
    -2
      config.go
  2. +11
    -1
      deploy.sh
  3. +12
    -1
      main.go

+ 4
- 2
config.go Просмотреть файл



func readConfig() error { func readConfig() error {
log.Println("Read configration for production ") log.Println("Read configration for production ")
return readConfigFile("config.json")
workingdir := getWorkingDir()
return readConfigFile(workingdir + "/config.json")
} }


func readConfigForTest() error { func readConfigForTest() error {
log.Println("Read configration for Test ") log.Println("Read configration for Test ")
return readConfigFile("config.test.json")
workingdir := getWorkingDir()
return readConfigFile(workingdir + "/config.test.json")
} }


func readConfigFile(file string) error { func readConfigFile(file string) error {

+ 11
- 1
deploy.sh Просмотреть файл

#!/bin/bash #!/bin/bash
echo compile program
echo "compile program to rpn "
go build -o rpn

scp rpn rpn@hk-01.biukop.com:~/go/
scp config.json rpn@hk-01.biukop.com:~/go/
rsync -a --exclude _pgbackup PG rpn@hk-01.biukop.com:~/go/
rsync -a form rpn@hk-01.biukop.com:~/go/

echo 'stop remote rpn and start new one'
ssh root@hk-01.biukop.com "/usr/sbin/service rpn stop; /usr/sbin/service rpn start"


+ 12
- 1
main.go Просмотреть файл

"log" "log"
"net/http" "net/http"
"os" "os"
"path/filepath"
"text/template" "text/template"
"time" "time"
) )
func main() { func main() {
db.h = nil //make sure it's in proper state. db.h = nil //make sure it's in proper state.


workingdir := getWorkingDir()

//setup log file //setup log file
filename := "logs/rpn.superforex." + time.Now().Format("2006-01-02-15-04-06") + ".log"
filename := workingdir + "/logs/rpn.superforex." + time.Now().Format("2006-01-02-15-04-06") + ".log"
f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil { if err != nil {
log.Fatalf("Error opening file: %v", err) log.Fatalf("Error opening file: %v", err)
//program never reach here. //program never reach here.
} }


func getWorkingDir() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
return dir
}

func errPage(w http.ResponseWriter, code int, msg string) { func errPage(w http.ResponseWriter, code int, msg string) {
var data struct { var data struct {
ErrorMessage string ErrorMessage string

Загрузка…
Отмена
Сохранить