common.go 760 B

12345678910111213141516171819202122232425262728293031323334
  1. package conf
  2. import (
  3. "errors"
  4. "fmt"
  5. "git.shuncheng.lu/bigthing/gocommon/pkg/internal/constant"
  6. )
  7. func SetAndAssertNil(config map[string]string, parent, str string, defaultValue ...string) error {
  8. if value := GetString(parent, str, defaultValue...); value != "" {
  9. config[str] = value
  10. return nil
  11. }
  12. return errors.New(fmt.Sprintf("config %s.%s is empty string or not found", parent, str))
  13. }
  14. const (
  15. EnvDebug = "debug"
  16. EnvTest = "test"
  17. EnvRelease = "release"
  18. )
  19. func GetEnv() string {
  20. return GetString(constant.ApplicationName, constant.EnvName)
  21. }
  22. func GetProjectName() string {
  23. return GetString(constant.ApplicationName, constant.ProjectName)
  24. }
  25. func GetAppPort() uint64 {
  26. return GetUint64(constant.ApplicationName, constant.PortName)
  27. }