Skip to content

Commit

Permalink
Update initializing configs
Browse files Browse the repository at this point in the history
  • Loading branch information
yunkon-kim committed Apr 19, 2022
1 parent d201e28 commit 0ee0bc0
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 124 deletions.
74 changes: 51 additions & 23 deletions poc-cb-net/cmd/admin-web/admin-web.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"html/template"
"io"
Expand Down Expand Up @@ -42,42 +43,69 @@ var systemManagementClient pb.SystemManagementServiceClient

func init() {
fmt.Println("Start......... init() of admin-web.go")
ex, err := os.Executable()
if err != nil {
panic(err)
}
exePath := filepath.Dir(ex)
fmt.Printf("exePath: %v\n", exePath)

// Load cb-log config from the current directory (usually for the production)
logConfPath := filepath.Join(exePath, "config", "log_conf.yaml")
fmt.Printf("logConfPath: %v\n", logConfPath)
if !file.Exists(logConfPath) {
// Load cb-log config from the project directory (usually for development)
path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
// Set cb-log
env := os.Getenv("CBLOG_ROOT")
if env != "" {
// Load cb-log config from the environment variable path (default)
fmt.Printf("CBLOG_ROOT: %v\n", env)
CBLogger = cblog.GetLogger("cb-network")
} else {

// Load cb-log config from the current directory (usually for the production)
ex, err := os.Executable()
if err != nil {
panic(err)
}
projectPath := strings.TrimSpace(string(path))
logConfPath = filepath.Join(projectPath, "poc-cb-net", "config", "log_conf.yaml")
exePath := filepath.Dir(ex)
fmt.Printf("exe path: %v\n", exePath)

logConfPath := filepath.Join(exePath, "config", "log_conf.yaml")
if file.Exists(logConfPath) {
fmt.Printf("path of log_conf.yaml: %v\n", logConfPath)
CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)

} else {
// Load cb-log config from the project directory (usually for development)
logConfPath = filepath.Join(exePath, "..", "..", "config", "log_conf.yaml")
if file.Exists(logConfPath) {
fmt.Printf("path of log_conf.yaml: %v\n", logConfPath)
CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)
} else {
err := errors.New("fail to load log_conf.yaml")
panic(err)
}
}
CBLogger.Debugf("Load %v", logConfPath)

}
CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)
CBLogger.Debugf("Load %v", logConfPath)

// Load cb-network config from the current directory (usually for the production)
ex, err := os.Executable()
if err != nil {
panic(err)
}
exePath := filepath.Dir(ex)
fmt.Printf("exe path: %v\n", exePath)

configPath := filepath.Join(exePath, "config", "config.yaml")
fmt.Printf("configPath: %v\n", configPath)
if !file.Exists(configPath) {
if file.Exists(configPath) {
fmt.Printf("path of config.yaml: %v\n", configPath)
config, _ = model.LoadConfig(configPath)
} else {
// Load cb-network config from the project directory (usually for the development)
path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
if err != nil {
configPath = filepath.Join(exePath, "..", "..", "config", "config.yaml")

if file.Exists(configPath) {
config, _ = model.LoadConfig(configPath)
} else {
err := errors.New("fail to load config.yaml")
panic(err)
}
projectPath := strings.TrimSpace(string(path))
configPath = filepath.Join(projectPath, "poc-cb-net", "config", "config.yaml")
}
config, _ = model.LoadConfig(configPath)

CBLogger.Debugf("Load %v", configPath)

fmt.Println("End......... init() of admin-web.go")
}

Expand Down
79 changes: 52 additions & 27 deletions poc-cb-net/cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -36,44 +36,69 @@ var config model.Config

func init() {
fmt.Println("Start......... init() of agent.go")
ex, err := os.Executable()
if err != nil {
panic(err)
}
exePath := filepath.Dir(ex)
fmt.Printf("exePath: %v\n", exePath)

// Load cb-log config from the current directory (usually for the production)
logConfPath := filepath.Join(exePath, "config", "log_conf.yaml")
fmt.Printf("logConfPath: %v\n", logConfPath)
if !file.Exists(logConfPath) {
fmt.Printf("not exist - %v\n", logConfPath)
// Load cb-log config from the project directory (usually for development)
path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
fmt.Printf("projectRoot: %v\n", string(path))

// Set cb-log
env := os.Getenv("CBLOG_ROOT")
if env != "" {
// Load cb-log config from the environment variable path (default)
fmt.Printf("CBLOG_ROOT: %v\n", env)
CBLogger = cblog.GetLogger("cb-network")
} else {

// Load cb-log config from the current directory (usually for the production)
ex, err := os.Executable()
if err != nil {
panic(err)
}
projectPath := strings.TrimSpace(string(path))
logConfPath = filepath.Join(projectPath, "poc-cb-net", "config", "log_conf.yaml")
exePath := filepath.Dir(ex)
fmt.Printf("exe path: %v\n", exePath)

logConfPath := filepath.Join(exePath, "config", "log_conf.yaml")
if file.Exists(logConfPath) {
fmt.Printf("path of log_conf.yaml: %v\n", logConfPath)
CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)

} else {
// Load cb-log config from the project directory (usually for development)
logConfPath = filepath.Join(exePath, "..", "..", "config", "log_conf.yaml")
if file.Exists(logConfPath) {
fmt.Printf("path of log_conf.yaml: %v\n", logConfPath)
CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)
} else {
err := errors.New("fail to load log_conf.yaml")
panic(err)
}
}
CBLogger.Debugf("Load %v", logConfPath)

}
CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)
CBLogger.Debugf("Load %v", logConfPath)

// Load cb-network config from the current directory (usually for the production)
ex, err := os.Executable()
if err != nil {
panic(err)
}
exePath := filepath.Dir(ex)
fmt.Printf("exe path: %v\n", exePath)

configPath := filepath.Join(exePath, "config", "config.yaml")
fmt.Printf("configPath: %v\n", configPath)
if !file.Exists(configPath) {
if file.Exists(configPath) {
fmt.Printf("path of config.yaml: %v\n", configPath)
config, _ = model.LoadConfig(configPath)
} else {
// Load cb-network config from the project directory (usually for the development)
path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
if err != nil {
configPath = filepath.Join(exePath, "..", "..", "config", "config.yaml")

if file.Exists(configPath) {
config, _ = model.LoadConfig(configPath)
} else {
err := errors.New("fail to load config.yaml")
panic(err)
}
projectPath := strings.TrimSpace(string(path))
configPath = filepath.Join(projectPath, "poc-cb-net", "config", "config.yaml")
}
config, _ = model.LoadConfig(configPath)

CBLogger.Debugf("Load %v", configPath)

fmt.Println("End......... init() of agent.go")
}

Expand Down
78 changes: 51 additions & 27 deletions poc-cb-net/cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"net"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
Expand All @@ -31,44 +30,69 @@ var config model.Config

func init() {
fmt.Println("Start......... init() of controller.go")
ex, err := os.Executable()
if err != nil {
panic(err)
}
exePath := filepath.Dir(ex)
fmt.Printf("exePath: %v\n", exePath)

// Load cb-log config from the current directory (usually for the production)
logConfPath := filepath.Join(exePath, "config", "log_conf.yaml")
fmt.Printf("logConfPath: %v\n", logConfPath)
if !file.Exists(logConfPath) {
fmt.Printf("not exist - %v\n", logConfPath)
// Load cb-log config from the project directory (usually for development)
path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
fmt.Printf("projectRoot: %v\n", string(path))

// Set cb-log
env := os.Getenv("CBLOG_ROOT")
if env != "" {
// Load cb-log config from the environment variable path (default)
fmt.Printf("CBLOG_ROOT: %v\n", env)
CBLogger = cblog.GetLogger("cb-network")
} else {

// Load cb-log config from the current directory (usually for the production)
ex, err := os.Executable()
if err != nil {
panic(err)
}
projectPath := strings.TrimSpace(string(path))
logConfPath = filepath.Join(projectPath, "poc-cb-net", "config", "log_conf.yaml")
exePath := filepath.Dir(ex)
fmt.Printf("exe path: %v\n", exePath)

logConfPath := filepath.Join(exePath, "config", "log_conf.yaml")
if file.Exists(logConfPath) {
fmt.Printf("path of log_conf.yaml: %v\n", logConfPath)
CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)

} else {
// Load cb-log config from the project directory (usually for development)
logConfPath = filepath.Join(exePath, "..", "..", "config", "log_conf.yaml")
if file.Exists(logConfPath) {
fmt.Printf("path of log_conf.yaml: %v\n", logConfPath)
CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)
} else {
err := errors.New("fail to load log_conf.yaml")
panic(err)
}
}
CBLogger.Debugf("Load %v", logConfPath)

}
CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)
CBLogger.Debugf("Load %v", logConfPath)

// Load cb-network config from the current directory (usually for the production)
ex, err := os.Executable()
if err != nil {
panic(err)
}
exePath := filepath.Dir(ex)
fmt.Printf("exe path: %v\n", exePath)

configPath := filepath.Join(exePath, "config", "config.yaml")
fmt.Printf("configPath: %v\n", configPath)
if !file.Exists(configPath) {
if file.Exists(configPath) {
fmt.Printf("path of config.yaml: %v\n", configPath)
config, _ = model.LoadConfig(configPath)
} else {
// Load cb-network config from the project directory (usually for the development)
path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
if err != nil {
configPath = filepath.Join(exePath, "..", "..", "config", "config.yaml")

if file.Exists(configPath) {
config, _ = model.LoadConfig(configPath)
} else {
err := errors.New("fail to load config.yaml")
panic(err)
}
projectPath := strings.TrimSpace(string(path))
configPath = filepath.Join(projectPath, "poc-cb-net", "config", "config.yaml")
}
config, _ = model.LoadConfig(configPath)

CBLogger.Debugf("Load %v", configPath)

fmt.Println("End......... init() of controller.go")
}

Expand Down
Loading

0 comments on commit 0ee0bc0

Please sign in to comment.