res

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 4 Imported by: 0

README

Go-Res

GoDoc rcard License

一个轻量、简单的后端响应结果封装工具

{
"status": 0,
"msg": "",
"data": {
    "text": "World!"
    ...
    }
}

安装

go get github.com/rroy233/go-res

使用

1.常规用法

实例化对象,状态码初始化为0

resultjson := res.New(0)

修改msg

resultjson.Msg("ok")

向Data中新增加键值对

resultjson.AddData("key","value")

从Data中删除键值对

err := resultjson.DelData("key")

导出为字符串或[]byte类型

resultjson.String()

resultjson.ByteSlice()

2.导入已有的结构体

使用Json()方法,将已有的map或结构体json格式化后注入data中

result,err := res.New(0).Json(struct)

导出为字符串或[]byte类型

result.String()

result.ByteSlice()

Documentation

Overview

Package res 返回json封装

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(status int) (r *resStruct)

New 实例化一个Res对象

输入status的值,msg默认为空字符串,data默认为空map

可使用MsgText(),AddData()方法做进一步操作

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL