package utils import "reflect" import "github.com/jinzhu/gorm" const DateTimeFormat = "2006-01-02 15:04:05" func DatasToMap(datas []string) map[string]string { m := make(map[string]string, len(datas)/2) for i, data := range datas { if i%2 == 0 { m[data] = "" } else { key := datas[i-1] m[key] = data } } return m } // 根据参数名获取对应参数的值 func GetValue(data interface{}, name string) interface{} { value := reflect.ValueOf(data) for i := 0; i < value.NumField(); i++ { em := value.Field(i) if em.Kind() != reflect.Struct { continue } for j := 0; j < em.NumField(); j++ { varName := em.Type().Field(j).Tag.Get("json") if varName != name { continue } return em.Field(j).Interface() } } return nil } func GetLinkSeeConnection() (db *gorm.DB, err error) { //此为公网连接,供测试阶段使用,生产环境需要替换成内网地址连接: //内网地址:rm-bp1rxj4r7a204ujhn.mysql.rds.aliyuncs.com //外网地址:rm-bp1rxj4r7a204ujhnio.mysql.rds.aliyuncs.com db, err = gorm.Open("mysql", "common_user:Meiyoumima1234@tcp(rm-bp1rxj4r7a204ujhn.mysql.rds.aliyuncs.com:3306)/linksee?charset=utf8&parseTime=True&loc=Local") if err != nil { //LZPrint("db.conn err is:", err.Error()) } return db, err }