ソースを参照

reading config and write log into absolute path using current directory

master
patrick 5年前
コミット
1882acf44b
3個のファイルの変更27行の追加4行の削除
  1. +4
    -2
      config.go
  2. +11
    -1
      deploy.sh
  3. +12
    -1
      main.go

+ 4
- 2
config.go ファイルの表示

@@ -35,12 +35,14 @@ var Config AppConfig

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

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

func readConfigFile(file string) error {

+ 11
- 1
deploy.sh ファイルの表示

@@ -1,2 +1,12 @@
#!/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 ファイルの表示

@@ -4,6 +4,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"text/template"
"time"
)
@@ -11,8 +12,10 @@ import (
func main() {
db.h = nil //make sure it's in proper state.

workingdir := getWorkingDir()

//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)
if err != nil {
log.Fatalf("Error opening file: %v", err)
@@ -39,6 +42,14 @@ func main() {
//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) {
var data struct {
ErrorMessage string

読み込み中…
キャンセル
保存