12345678910111213141516171819202122232425262728 |
- package models
- import (
- "github.com/gin-gonic/gin"
- "base-gin/helpers"
- )
- type Config struct {
- Id uint64 `gorm:"primary_key;AUTO_INCREMENT"`
- Key string
- Value string
- }
- func (Config) TableName() string {
- return "config"
- }
- func GetConfigValue(c *gin.Context, key string) (value string, err error) {
- var configs []Config
- err = helpers.MysqlClient.Ctx(c).Where("`key` = ?", key).Find(&configs).Error
- if err != nil {
- return value, err
- }
- if len(configs) == 0 {
- return "", err
- }
- return configs[0].Value, nil
- }
|