config.go 526 B

12345678910111213141516171819202122232425262728
  1. package models
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "base-gin/helpers"
  5. )
  6. type Config struct {
  7. Id uint64 `gorm:"primary_key;AUTO_INCREMENT"`
  8. Key string
  9. Value string
  10. }
  11. func (Config) TableName() string {
  12. return "config"
  13. }
  14. func GetConfigValue(c *gin.Context, key string) (value string, err error) {
  15. var configs []Config
  16. err = helpers.MysqlClient.Ctx(c).Where("`key` = ?", key).Find(&configs).Error
  17. if err != nil {
  18. return value, err
  19. }
  20. if len(configs) == 0 {
  21. return "", err
  22. }
  23. return configs[0].Value, nil
  24. }