map.go 970 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * The ephemeralvariablemap is used "only" for variable substitution in config
  3. * titles, shell arguments, etc, in the foorm of {{ key }}, like Jinja2.
  4. *
  5. * OliveTin itself really only ever "writes" to this map, mostly by loading
  6. * EntityFiles, and the only form of "reading" is for the variable substitution
  7. * in configs.
  8. */
  9. package stringvariables
  10. import (
  11. "github.com/prometheus/client_golang/prometheus"
  12. "github.com/prometheus/client_golang/prometheus/promauto"
  13. )
  14. var (
  15. contents map[string]string
  16. metricSvCount = promauto.NewGauge(prometheus.GaugeOpts{
  17. Name: "olivetin_sv_count",
  18. Help: "The number entries in the sv map",
  19. })
  20. )
  21. func init() {
  22. contents = make(map[string]string)
  23. }
  24. func Get(key string) string {
  25. v, ok := contents[key]
  26. if !ok {
  27. return ""
  28. } else {
  29. return v
  30. }
  31. }
  32. func GetAll() map[string]string {
  33. return contents
  34. }
  35. func Set(key string, value string) {
  36. contents[key] = value
  37. metricSvCount.Set(float64(len(contents)))
  38. }