• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang rest.ResponseWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/AlexanderChen1989/go-json-rest/rest.ResponseWriter的典型用法代码示例。如果您正苦于以下问题:Golang ResponseWriter类的具体用法?Golang ResponseWriter怎么用?Golang ResponseWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ResponseWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:31,代码来源:network.go


示例2: 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
	}
	if err := r.DecodeJSONPayload(&info); err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.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})
}
开发者ID:lue828,项目名称:osinstall-server,代码行数:28,代码来源:network.go


示例3: 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})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:33,代码来源:network.go


示例4: DeleteSystemConfigById

//SystemConfig
func DeleteSystemConfigById(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
	}

	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
	}

	mod, err := repo.DeleteSystemConfigById(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})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:31,代码来源:system_config.go


示例5: 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})
}
开发者ID:lue828,项目名称:osinstall-server,代码行数:33,代码来源:hardware.go


示例6: GetDeviceInstallCallbackList

func GetDeviceInstallCallbackList(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 {
		DeviceId uint
	}

	if err := r.DecodeJSONPayload(&info); err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
		return
	}

	where := fmt.Sprintf("device_id = %d", info.DeviceId)
	order := "id asc"
	list, err := repo.GetDeviceInstallCallbackByWhere(where, order)
	if err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
		return
	}

	var rows []model.DeviceInstallCallback
	for _, callback := range list {
		device, err := repo.GetDeviceById(callback.DeviceID)
		if err != nil {
			w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
			return
		}

		callback.Content = strings.Replace(callback.Content, "<{sn}>", device.Sn, -1)
		callback.Content = strings.Replace(callback.Content, "<{hostname}>", device.Hostname, -1)
		callback.Content = strings.Replace(callback.Content, "<{ip}>", device.Ip, -1)
		callback.Content = strings.Replace(callback.Content, "<{manage_ip}>", device.ManageIp, -1)

		if device.NetworkID > uint(0) {
			network, _ := repo.GetNetworkById(device.NetworkID)
			callback.Content = strings.Replace(callback.Content, "<{gateway}>", network.Gateway, -1)
			callback.Content = strings.Replace(callback.Content, "<{netmask}>", network.Netmask, -1)
		}
		if device.ManageNetworkID > uint(0) {
			manageNetwork, _ := repo.GetManageNetworkById(device.ManageNetworkID)
			callback.Content = strings.Replace(callback.Content, "<{manage_gateway}>", manageNetwork.Gateway, -1)
			callback.Content = strings.Replace(callback.Content, "<{manage_netmask}>", manageNetwork.Netmask, -1)
		}
		callback.Content = strings.Replace(callback.Content, "\n", "<br />", -1)
		callback.RunResult = strings.Replace(callback.RunResult, "\n", "<br />", -1)
		rows = append(rows, callback)
	}

	result := make(map[string]interface{})
	result["list"] = rows

	w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": result})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:57,代码来源:device_install_callback.go


示例7: CreateNewMacAddress

func CreateNewMacAddress(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
	}
	fmt.Println(repo)

	mac := util.CreateNewMacAddress()
	w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": mac})
}
开发者ID:lue828,项目名称:osinstall-server,代码行数:11,代码来源:vm_install.go


示例8: UploadDevice

func UploadDevice(ctx context.Context, w rest.ResponseWriter, r *rest.Request) {
	r.ParseForm()
	file, handle, err := r.FormFile("file")
	if err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
		return
	}

	cd, err := iconv.Open("UTF-8", "GBK")
	if err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
		return
	}
	defer cd.Close()

	dir := "./upload/"
	if !util.FileExist(dir) {
		err := os.MkdirAll(dir, 0777)
		if err != nil {
			w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
			return
		}
	}

	list := strings.Split(handle.Filename, ".")
	fix := list[len(list)-1]

	h := md5.New()
	h.Write([]byte(fmt.Sprintf("%s", time.Now().UnixNano()) + handle.Filename))
	cipherStr := h.Sum(nil)
	md5 := fmt.Sprintf("%s", hex.EncodeToString(cipherStr))
	filename := md5 + "." + fix

	result := make(map[string]interface{})
	result["result"] = filename

	if util.FileExist(dir + filename) {
		os.Remove(dir + filename)
	}

	f, err := os.OpenFile(dir+filename, os.O_WRONLY|os.O_CREATE, 0666)
	io.Copy(f, file)
	if err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
		return
	}
	defer f.Close()
	defer file.Close()
	w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": result})
	return
}
开发者ID:lue828,项目名称:osinstall-server,代码行数:51,代码来源:import.go


示例9: 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})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:34,代码来源:hardware.go


示例10: 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})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:35,代码来源:manufacturer.go


示例11: 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})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:26,代码来源:manufacturer.go


示例12: GetHardwareList

func GetHardwareList(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
		Company     string
		Product     string
		ModelName   string
		IsSystemAdd string
	}
	if err := r.DecodeJSONPayload(&info); err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
		return
	}
	var where string
	if info.Company != "" {
		where += " and company = '" + info.Company + "' "
	}
	if info.Product != "" {
		where += " and product = '" + info.Product + "' "
	}
	if info.ModelName != "" {
		where += " and model_name = '" + info.ModelName + "' "
	}
	if info.IsSystemAdd != "" {
		where += " and is_system_add = '" + info.IsSystemAdd + "' "
	}

	mods, err := repo.GetHardwareListWithPage(info.Limit, info.Offset, where)
	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.CountHardware(where)
	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})
}
开发者ID:lue828,项目名称:osinstall-server,代码行数:50,代码来源:hardware.go


示例13: 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})
}
开发者ID:oiooj,项目名称:osinstall-server,代码行数:31,代码来源:device.go


示例14: 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": "操作成功"})
}
开发者ID:lue828,项目名称:osinstall-server,代码行数:26,代码来源:vm_install.go


示例15: 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})
}
开发者ID:lue828,项目名称:osinstall-server,代码行数:25,代码来源:location.go


示例16: LoginOut

func LoginOut(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 {
		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)

	session, err := store.Get(r.Request, "user-authentication")
	if err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
		return
	}

	/*
		sessionUser, err := GetSession(w, r)
		if err != nil {
			w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
			return
		}
	*/

	_, errToken := repo.DeleteUserAccessTokenByToken(info.AccessToken)
	if errToken != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": errToken.Error()})
		return
	}

	delete(session.Values, "ID")
	delete(session.Values, "Username")
	delete(session.Values, "Name")
	delete(session.Values, "Role")
	delete(session.Values, "AccessToken")
	session.Save(r.Request, w)

	w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功"})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:47,代码来源:user.go


示例17: GetVmDeviceLogByDeviceIdAndType

func GetVmDeviceLogByDeviceIdAndType(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 {
		DeviceID uint
		Type     string
		Order    string
		MaxID    uint
	}
	if err := r.DecodeJSONPayload(&info); err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
		return
	}

	if info.Order == "" {
		info.Order = "id DESC"
	}

	mods, err := repo.GetVmDeviceLogListByDeviceIDAndType(info.DeviceID, info.Type, info.Order, info.MaxID)
	if err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
		return
	}

	type log struct {
		ID        uint
		DeviceID  uint
		Title     string
		Type      string
		Content   string
		CreatedAt utils.ISOTime
		UpdatedAt utils.ISOTime
	}

	var result []log
	for _, v := range mods {
		var row log
		row.ID = v.ID
		row.DeviceID = v.DeviceID
		row.Title = v.Title
		row.Type = v.Type
		row.Content = v.Content
		row.CreatedAt = utils.ISOTime(v.CreatedAt)
		row.UpdatedAt = utils.ISOTime(v.UpdatedAt)
		result = append(result, row)
	}

	w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": result})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:52,代码来源:vm_device_log.go


示例18: GetUserById

func GetUserById(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
	}

	mod, err := repo.GetUserById(info.ID)
	if err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
		return
	}

	type UserWithTime struct {
		ID          uint
		Username    string
		Password    string
		Name        string
		PhoneNumber string
		Permission  string
		Status      string
		Role        string
		CreatedAt   utils.ISOTime
		UpdatedAt   utils.ISOTime
	}

	var user UserWithTime
	user.ID = mod.ID
	user.Username = mod.Username
	user.Name = mod.Name
	user.PhoneNumber = mod.PhoneNumber
	user.Permission = mod.Permission
	user.Status = mod.Status
	user.Role = mod.Role
	user.CreatedAt = utils.ISOTime(mod.CreatedAt)
	user.UpdatedAt = utils.ISOTime(mod.UpdatedAt)

	w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": user})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:46,代码来源:user.go


示例19: CollectAndUpdateVmHostResource

func CollectAndUpdateVmHostResource(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
	}
	logger, ok := middleware.LoggerFromContext(ctx)
	if !ok {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
		return
	}
	conf, ok := middleware.ConfigFromContext(ctx)
	if !ok {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "内部服务器错误"})
		return
	}
	UpdateVmHostResource(logger, repo, conf, 0)
	w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功"})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:19,代码来源:vm_host.go


示例20: GetVmHostBySn

func GetVmHostBySn(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
	}
	if err := r.DecodeJSONPayload(&info); err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": "参数错误" + err.Error()})
		return
	}

	mod, err := repo.GetVmHostBySn(info.Sn)
	if err != nil {
		w.WriteJSON(map[string]interface{}{"Status": "error", "Message": err.Error()})
		return
	}

	w.WriteJSON(map[string]interface{}{"Status": "success", "Message": "操作成功", "Content": mod})
}
开发者ID:idcos,项目名称:osinstall-server,代码行数:22,代码来源:vm_host.go



注:本文中的github.com/AlexanderChen1989/go-json-rest/rest.ResponseWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gcm.NewMessage函数代码示例发布时间:2022-05-24
下一篇:
Golang rest.Request类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap