config.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * ECAL
  3. *
  4. * Copyright 2020 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package config
  11. import (
  12. "fmt"
  13. "strconv"
  14. "devt.de/krotik/common/errorutil"
  15. )
  16. // Global variables
  17. // ================
  18. /*
  19. ProductVersion is the current version of ECAL
  20. */
  21. const ProductVersion = "1.6.2"
  22. /*
  23. Known configuration options for ECAL
  24. */
  25. const (
  26. WorkerCount = "WorkerCount"
  27. )
  28. /*
  29. DefaultConfig is the defaut configuration
  30. */
  31. var DefaultConfig = map[string]interface{}{
  32. /*
  33. Number of worker threads in ECAL's ECA engine. This number is also the maximum
  34. number of concurrent operations - e.g. how often addEventAndWait can be called
  35. in a single event chain.
  36. */
  37. WorkerCount: 4,
  38. }
  39. /*
  40. Config is the actual config which is used
  41. */
  42. var Config map[string]interface{}
  43. /*
  44. Initialise the config
  45. */
  46. func init() {
  47. data := make(map[string]interface{})
  48. for k, v := range DefaultConfig {
  49. data[k] = v
  50. }
  51. Config = data
  52. }
  53. // Helper functions
  54. // ================
  55. /*
  56. Str reads a config value as a string value.
  57. */
  58. func Str(key string) string {
  59. return fmt.Sprint(Config[key])
  60. }
  61. /*
  62. Int reads a config value as an int value.
  63. */
  64. func Int(key string) int {
  65. ret, err := strconv.ParseInt(fmt.Sprint(Config[key]), 10, 64)
  66. errorutil.AssertTrue(err == nil,
  67. fmt.Sprintf("Could not parse config key %v: %v", key, err))
  68. return int(ret)
  69. }
  70. /*
  71. Bool reads a config value as a boolean value.
  72. */
  73. func Bool(key string) bool {
  74. ret, err := strconv.ParseBool(fmt.Sprint(Config[key]))
  75. errorutil.AssertTrue(err == nil,
  76. fmt.Sprintf("Could not parse config key %v: %v", key, err))
  77. return ret
  78. }