package db import ( "time" "xiawan/wx/db/table" ) // GetProxyMapping 获取代理映射 func GetProxyMapping(proxyNumber string) (*table.ProxyMapping, error) { if err := checkAndReconnect(); err != nil { return nil, err } var mapping table.ProxyMapping if err := MysqlDB.Where("proxy_number = ?", proxyNumber).First(&mapping).Error; err != nil { return nil, err } return &mapping, nil } // AddProxyMapping 添加代理映射 func AddProxyMapping(proxyNumber, proxyValue string) error { if err := checkAndReconnect(); err != nil { return err } mapping := &table.ProxyMapping{ ProxyNumber: proxyNumber, ProxyValue: proxyValue, CreateTime: time.Now().Format("2006-01-02 15:04:05"), UpdateTime: time.Now().Format("2006-01-02 15:04:05"), } return MysqlDB.Create(mapping).Error } // UpdateProxyMapping 更新代理映射 func UpdateProxyMapping(proxyNumber, proxyValue string) error { if err := checkAndReconnect(); err != nil { return err } mapping := &table.ProxyMapping{ ProxyValue: proxyValue, UpdateTime: time.Now().Format("2006-01-02 15:04:05"), } return MysqlDB.Model(&table.ProxyMapping{}).Where("proxy_number = ?", proxyNumber).Updates(mapping).Error } // DeleteProxyMapping 删除代理映射 func DeleteProxyMapping(proxyNumber string) error { if err := checkAndReconnect(); err != nil { return err } return MysqlDB.Where("proxy_number = ?", proxyNumber).Delete(&table.ProxyMapping{}).Error }