测试示例

Version  1.0.2 Latest

测试示例

其它一些示例演示

  1. struct数组
  2. struct嵌套
  3. int数组
  4. int
  5. map
  6. xml
  7. time

apis

1. struct数组

version: 1.0.2.1

GET /user/demo/struct_array

Response:

//StatusCode: 200 demo struct array
[  //array[handler.DemoData]
  {  //object(handler.DemoData)
    "count": 123,  //int
    "description": "abc",  //string
    "float_array": [  //array[float64]
      1.23
    ],
    "int_array": [  //array[int]
      123
    ],
    "int_pointer": 123,  //int
    "map": {  //object(map[string]int)
      "abc": 123  //int
    },
    "object_1": {  //object(handler.DemoObject)
      "name": "abc"  //string
    },
    "object_2": {  //object(handler.DemoObject)
      "name": "abc"  //string
    },
    "title": "abc"  //string, 标题
  }
]

2. struct嵌套

GET /user/demo/struct_nested

Response:

//StatusCode: 200 nested struct
{  //object(handler.Struct1)
  "Name": "abc",  //string
  "Name2": "abc"  //string
}

3. int数组

GET /user/demo/int_array

Response:

//StatusCode: 200 demo int array
[  //array[int]
  123
]

4. int

GET /user/demo/int

Response:

//StatusCode: 200 demo int
//int
123

5. map

GET /user/demo/map

Response:

//StatusCode: 200 demo map
{  //object(map[string]handler.DemoData)
  "abc": {  //object(handler.DemoData)
    "count": 123,  //int
    "description": "abc",  //string
    "float_array": [  //array[float64]
      1.23
    ],
    "int_array": [  //array[int]
      123
    ],
    "int_pointer": 123,  //int
    "map": {  //object(map[string]int)
      "abc": 123  //int
    },
    "object_1": {  //object(handler.DemoObject)
      "name": "abc"  //string
    },
    "object_2": {  //object(handler.DemoObject)
      "name": "abc"  //string
    },
    "title": "abc"  //string, 标题
  }
}

6. xml

author: alovn

GET /user/demo/xml

Request:

parameter parameterType dataType required validate example description
id param int64 false DemoID

body:

<request> //object(handler.DemoXMLRequest), XML测试请求对象
  <id>123</id> //int64, DemoID
</request>

Response:

//StatusCode: 200 
<response> //object(common.Response), 通用返回结果
  <code>0</code> //int, 返回状态码
  <demo> //object(handler.DemoXMLResponse), XML测试返回对象
    <address>abc</address> //string, 地址信息
    <city_id>123</city_id> //int64, 城市ID
    <id>123</id> //int64, 地址ID
  </demo>
  <msg>success</msg> //string, 返回消息
</response>
//StatusCode: 200 
<response> //object(common.Response), 通用返回结果
  <code>0</code> //int, 返回状态码
  <data> //object(handler.DemoXMLResponse2), XML测试返回对象2
    <address>abc</address> //string, 地址信息
    <city_id>123</city_id> //int64, 城市ID
    <id>123</id> //int64, 地址ID
  </data>
  <msg>success</msg> //string, 返回消息
</response>
//StatusCode: 200 
<response> //object(common.Response), 通用返回结果
  <code>10010</code> //int, 返回状态码
  <msg>sme error</msg> //string, 返回消息
</response>

7. time

author: alovn

GET /user/demo/time

Response:

//StatusCode: 200 
{  //object(common.Response), 通用返回结果
  "code": 0,  //int, 返回状态码
  "data": {  //object(handler.DemoTime)
    "time_1": "2022-05-16T16:47:48.741899+08:00",  //object(time.Time), example1
    "time_2": "2022-05-14 15:04:05",  //object(time.Time), example2
    "time_3": "2022-05-16T16:47:48.741899+08:00"  //object(time.Time)
  },
  "msg": "success"  //string, 返回消息
}