本文整理汇总了Golang中middleware.RepoFromContext函数的典型用法代码示例。如果您正苦于以下问题:Golang RepoFromContext函数的具体用法?Golang RepoFromContext怎么用?Golang RepoFromContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RepoFromContext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BatchDeleteVm
func BatchDeleteVm(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var infos []struct {
ID uint
}
if err := r.DecodeJSONPayload(&infos); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误"})
return
}
for _, info := range infos {
_, errDevice := repo.DeleteVmDeviceById(info.ID)
if errDevice != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errDevice.Error()})
return
}
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功"})
}
示例2: GetNetworkList
func GetNetworkList(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
Limit uint
Offset uint
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
mods, err := repo.GetNetworkListWithPage(info.Limit, info.Offset)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
result := make(map[string]interface{})
result["list"] = mods
//总条数
count, err := repo.CountNetwork()
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
result["recordCount"] = count
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": result})
}
示例3: GetScanDeviceModelName
func GetScanDeviceModelName(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
Company string
Product string
UserID uint
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误"})
return
}
info.Company = strings.TrimSpace(info.Company)
info.Product = strings.TrimSpace(info.Product)
var where string
where = "device_id = 0 and company = '" + info.Company + "'"
if info.Product != "" {
where += " and product = '" + info.Product + "'"
}
if info.UserID > uint(0) {
where += " and user_id = '" + fmt.Sprintf("%d", info.UserID) + "'"
}
mod, err := repo.GetManufacturerModelNameByGroup(where)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": mod})
}
示例4: FormatLocationToTreeByPid
func FormatLocationToTreeByPid(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
Pid uint
SelectPid uint
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
//var initContent []map[string]interface{}
mods, err := repo.FormatLocationToTreeByPid(info.Pid, nil, 0, info.SelectPid)
//mods, err := repo.FormatLocationToTreeByPid(info.Pid)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": mods})
}
示例5: GetScanDeviceProduct
func GetScanDeviceProduct(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
Company string
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误"})
return
}
info.Company = strings.TrimSpace(info.Company)
var where string
where = "device_id = 0 and company = '" + info.Company + "'"
mod, err := repo.GetManufacturerProductByGroup(where)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": mod})
}
示例6: DeleteUserById
func DeleteUserById(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
ID uint
AccessToken string
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
_, errAccessToken := VerifyAccessToken(info.AccessToken, ctx, true)
if errAccessToken != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errAccessToken.Error()})
return
}
osConfig, err := repo.DeleteUserById(info.ID)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
errAssign := repo.AssignManufacturerNewOnwer(uint(0), info.ID)
if errAssign != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errAssign.Error()})
return
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": osConfig})
}
示例7: DeleteNetworkById
func DeleteNetworkById(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
ID uint
AccessToken string
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
_, errVerify := VerifyAccessPurview(info.AccessToken, ctx, true, w, r)
if errVerify != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errVerify.Error()})
return
}
mod, err := repo.DeleteNetworkById(info.ID)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
_, errDelete := repo.DeleteIpByNetworkId(info.ID)
if errDelete != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errDelete.Error()})
return
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": mod})
}
示例8: UpdateMyInfo
func UpdateMyInfo(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
ID uint
Password string
Name string
PhoneNumber string
Permission string
Status string
Role string
AccessToken string
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
info.Password = strings.TrimSpace(info.Password)
info.Name = strings.TrimSpace(info.Name)
info.PhoneNumber = strings.TrimSpace(info.PhoneNumber)
info.AccessToken = strings.TrimSpace(info.AccessToken)
_, errAccessToken := VerifyAccessToken(info.AccessToken, ctx, false)
if errAccessToken != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errAccessToken.Error()})
return
}
user, err := repo.GetUserById(info.ID)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
if info.Password == "" {
info.Password = user.Password
} else {
encodePassword, err := util.EncodePassword(info.Password)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
info.Password = encodePassword
}
info.Permission = user.Permission
info.Status = user.Status
info.Role = user.Role
mod, err := repo.UpdateUserById(info.ID, info.Password, info.Name, info.PhoneNumber, info.Permission, info.Status, info.Role)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": mod})
}
示例9: DeleteHardwareById
func DeleteHardwareById(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
ID uint
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
hardware, err := repo.GetHardwareById(info.ID)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
if hardware.IsSystemAdd == "Yes" {
//w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "系统添加的配置不允许删除!"})
//return
}
mod, err := repo.DeleteHardwareById(info.ID)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": mod})
}
示例10: SavePlatformConfig
func SavePlatformConfig(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
Name string
Content string
AccessToken string
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
info.AccessToken = strings.TrimSpace(info.AccessToken)
_, errVerify := VerifyAccessPurview(info.AccessToken, ctx, true, w, r)
if errVerify != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errVerify.Error()})
return
}
info.Name = strings.TrimSpace(info.Name)
info.Content = strings.TrimSpace(info.Content)
if info.Name == "" {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "请将信息填写完整!"})
return
}
count, err := repo.CountPlatformConfigByName(info.Name)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
if count > 0 {
platformConfig, err := repo.GetPlatformConfigByName(info.Name)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
_, errUpdate := repo.UpdatePlatformConfigById(platformConfig.ID, info.Name, info.Content)
if errUpdate != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errUpdate.Error()})
return
}
} else {
_, err := repo.AddPlatformConfig(info.Name, info.Content)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功"})
}
示例11: BatchReInstall
//重装
func BatchReInstall(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var infos []struct {
ID uint
}
if err := r.DecodeJSONPayload(&infos); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误"})
return
}
for _, info := range infos {
_, err := repo.ReInstallDeviceById(info.ID)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
//log
device, err := repo.GetDeviceById(info.ID)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
logContent := make(map[string]interface{})
logContent["data"] = device
json, err := json.Marshal(logContent)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "操作失败:" + err.Error()})
return
}
_, errAddLog := repo.AddDeviceLog(info.ID, "重装设备", "operate", string(json))
if errAddLog != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errAddLog.Error()})
return
}
_, errLog := repo.UpdateDeviceLogTypeByDeviceIdAndType(info.ID, "install", "install_history")
if errLog != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errLog.Error()})
return
}
/*
//删除LOG
_, errLog := repo.DeleteDeviceLogByDeviceID(info.ID)
if errLog != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errLog.Error()})
return
}
*/
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功"})
}
示例12: GetDeviceNumByStatus
func GetDeviceNumByStatus(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
Status string
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
info.Status = strings.TrimSpace(info.Status)
var where string
where = " where t1.id > 0 "
where += " and t1.status = '" + info.Status + "'"
//总条数
count, err := repo.CountDevice(where)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
result := make(map[string]interface{})
result["count"] = count
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": result})
}
示例13: ValidateSn
func ValidateSn(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
Sn string
}
info.Sn = strings.TrimSpace(info.Sn)
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
if info.Sn == "" {
w.WriteJSON(map[string]interface{}{"Status": "failure", "Message": "SN参数不能为空!", "Content": ""})
return
}
count, err := repo.CountDeviceBySn(info.Sn)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "failure", "Message": "参数错误!"})
return
}
if count > 0 {
w.WriteJSON(map[string]interface{}{"Status": "failure", "Message": "该SN已存在,继续填写会覆盖旧的数据!"})
} else {
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "SN填写正确!"})
}
}
示例14: GetCidrInfoByNetwork
//获取cidr信息
func GetCidrInfoByNetwork(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
_, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
logger, ok := middleware.LoggerFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
Network string
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误"})
return
}
info.Network = strings.TrimSpace(info.Network)
//处理网段
network, err := util.GetCidrInfo(info.Network, logger)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": network})
}
示例15: GetModelNameByWhereAndGroup
func GetModelNameByWhereAndGroup(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
repo, ok := middleware.RepoFromContext(ctx)
if !ok {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
return
}
var info struct {
Company string
Product string
IsSystemAdd string
}
if err := r.DecodeJSONPayload(&info); err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
return
}
where := " company = '" + info.Company + "'"
if info.Product != "" {
where += " and product = '" + info.Product + "'"
}
if info.IsSystemAdd != "" {
where += " and is_system_add = '" + info.IsSystemAdd + "'"
}
mod, err := repo.GetModelNameByWhereAndGroup(where)
if err != nil {
w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
return
}
w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": mod})
}