config.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package abango
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. e "github.com/dabory/abango-rest/etc"
  7. _ "github.com/go-sql-driver/mysql"
  8. )
  9. func GetXConfig(params ...string) error { // Kafka, gRpc, REST 통합 업그레이드
  10. e.AokLog("Abango Gets XConfig !")
  11. conf := "conf/"
  12. if len(params) != 0 {
  13. conf = params[0] + conf
  14. }
  15. RunFilename := conf + "config_select.json"
  16. run := struct {
  17. ConfSelect string
  18. ConfPostFix string
  19. }{}
  20. if file, err := os.Open(RunFilename); err != nil {
  21. e.LogFatal("WERQRRQERQW", RunFilename+" File NOT exist", err)
  22. return err
  23. } else {
  24. decoder := json.NewDecoder(file)
  25. if err = decoder.Decode(&run); err != nil {
  26. e.LogFatal("ERTFDFDAFA", RunFilename+"Not Decoded", err)
  27. return err
  28. }
  29. }
  30. XConfig = make(map[string]string) // Just like malloc
  31. config := []Param{}
  32. // var varMap []map[string]interface{}
  33. filename := conf + run.ConfSelect + run.ConfPostFix
  34. if file, err := os.Open(filename); err != nil {
  35. e.LogFatal("WERCASDFAWEF", filename+" File NOT exist", err)
  36. return err
  37. } else {
  38. decoder := json.NewDecoder(file)
  39. if err = decoder.Decode(&config); err == nil {
  40. for _, p := range config {
  41. XConfig[p.Key] = p.Value
  42. }
  43. } else {
  44. e.LogFatal("QWERCQQGE", filename+"Not Decoded", err)
  45. }
  46. }
  47. if XConfig["RestOn"] == "Yes" || XConfig["ApiType"] == "Rest" {
  48. fmt.Println("==" + "Config file prefix: " + run.ConfSelect + "== REST Connection: " + XConfig["RestConnect"] + "==")
  49. }
  50. return nil
  51. }