config.go 1.4 KB

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