|
@@ -3,24 +3,24 @@ package dartgen
|
|
import "text/template"
|
|
import "text/template"
|
|
|
|
|
|
var funcMap = template.FuncMap{
|
|
var funcMap = template.FuncMap{
|
|
|
|
+ "appendNullCoalescing": appendNullCoalescing,
|
|
|
|
+ "appendDefaultEmptyValue": appendDefaultEmptyValue,
|
|
|
|
+ "extractPositionalParamsFromPath": extractPositionalParamsFromPath,
|
|
"getBaseName": getBaseName,
|
|
"getBaseName": getBaseName,
|
|
|
|
+ "getCoreType": getCoreType,
|
|
"getPropertyFromMember": getPropertyFromMember,
|
|
"getPropertyFromMember": getPropertyFromMember,
|
|
- "isDirectType": isDirectType,
|
|
|
|
|
|
+ "hasUrlPathParams": hasUrlPathParams,
|
|
|
|
+ "isAtomicListType": isAtomicListType,
|
|
"isAtomicType": isAtomicType,
|
|
"isAtomicType": isAtomicType,
|
|
- "isNumberType": isNumberType,
|
|
|
|
|
|
+ "isDirectType": isDirectType,
|
|
"isClassListType": isClassListType,
|
|
"isClassListType": isClassListType,
|
|
- "isAtomicListType": isAtomicListType,
|
|
|
|
"isListItemsNullable": isListItemsNullable,
|
|
"isListItemsNullable": isListItemsNullable,
|
|
|
|
+ "isMapType": isMapType,
|
|
"isNullableType": isNullableType,
|
|
"isNullableType": isNullableType,
|
|
- "appendNullCoalescing": appendNullCoalescing,
|
|
|
|
- "appendDefaultEmptyValue": appendDefaultEmptyValue,
|
|
|
|
- "getCoreType": getCoreType,
|
|
|
|
|
|
+ "isNumberType": isNumberType,
|
|
"lowCamelCase": lowCamelCase,
|
|
"lowCamelCase": lowCamelCase,
|
|
- "normalizeHandlerName": normalizeHandlerName,
|
|
|
|
- "hasUrlPathParams": hasUrlPathParams,
|
|
|
|
- "extractPositionalParamsFromPath": extractPositionalParamsFromPath,
|
|
|
|
"makeDartRequestUrlPath": makeDartRequestUrlPath,
|
|
"makeDartRequestUrlPath": makeDartRequestUrlPath,
|
|
- "isMapType": isMapType,
|
|
|
|
|
|
+ "normalizeHandlerName": normalizeHandlerName,
|
|
}
|
|
}
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -29,28 +29,32 @@ import 'dart:convert';
|
|
import '../vars/kv.dart';
|
|
import '../vars/kv.dart';
|
|
import '../vars/vars.dart';
|
|
import '../vars/vars.dart';
|
|
|
|
|
|
-/// 发送POST请求.
|
|
|
|
|
|
+/// Send GET request.
|
|
///
|
|
///
|
|
-/// data:为你要post的结构体,我们会帮你转换成json字符串;
|
|
|
|
-/// ok函数:请求成功的时候调用,fail函数:请求失败的时候会调用,eventually函数:无论成功失败都会调用
|
|
|
|
-Future apiPost(String path, dynamic data,
|
|
|
|
|
|
+/// ok: the function that will be called on success.
|
|
|
|
+/// fail:the fuction that will be called on failure.
|
|
|
|
+/// eventually:the function that will be called regardless of success or failure.
|
|
|
|
+Future apiGet(String path,
|
|
{Map<String, String> header,
|
|
{Map<String, String> header,
|
|
Function(Map<String, dynamic>) ok,
|
|
Function(Map<String, dynamic>) ok,
|
|
Function(String) fail,
|
|
Function(String) fail,
|
|
Function eventually}) async {
|
|
Function eventually}) async {
|
|
- await _apiRequest('POST', path, data,
|
|
|
|
|
|
+ await _apiRequest('GET', path, null,
|
|
header: header, ok: ok, fail: fail, eventually: eventually);
|
|
header: header, ok: ok, fail: fail, eventually: eventually);
|
|
}
|
|
}
|
|
|
|
|
|
-/// 发送GET请求.
|
|
|
|
|
|
+/// Send POST request.
|
|
///
|
|
///
|
|
-/// ok函数:请求成功的时候调用,fail函数:请求失败的时候会调用,eventually函数:无论成功失败都会调用
|
|
|
|
-Future apiGet(String path,
|
|
|
|
|
|
+/// data: the data to post, it will be marshaled to json automatically.
|
|
|
|
+/// ok: the function that will be called on success.
|
|
|
|
+/// fail:the fuction that will be called on failure.
|
|
|
|
+/// eventually:the function that will be called regardless of success or failure.
|
|
|
|
+Future apiPost(String path, dynamic data,
|
|
{Map<String, String> header,
|
|
{Map<String, String> header,
|
|
Function(Map<String, dynamic>) ok,
|
|
Function(Map<String, dynamic>) ok,
|
|
Function(String) fail,
|
|
Function(String) fail,
|
|
Function eventually}) async {
|
|
Function eventually}) async {
|
|
- await _apiRequest('GET', path, null,
|
|
|
|
|
|
+ await _apiRequest('POST', path, data,
|
|
header: header, ok: ok, fail: fail, eventually: eventually);
|
|
header: header, ok: ok, fail: fail, eventually: eventually);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -213,11 +217,11 @@ Future _apiRequest(String method, String path, dynamic data,
|
|
}`
|
|
}`
|
|
|
|
|
|
tokensFileContent = `class Tokens {
|
|
tokensFileContent = `class Tokens {
|
|
- /// 用于访问的token, 每次请求都必须带在Header里面
|
|
|
|
|
|
+ /// the token used to access, it must be carried in the header of each request
|
|
final String accessToken;
|
|
final String accessToken;
|
|
final int accessExpire;
|
|
final int accessExpire;
|
|
|
|
|
|
- /// 用于刷新token
|
|
|
|
|
|
+ /// the token used to refresh
|
|
final String refreshToken;
|
|
final String refreshToken;
|
|
final int refreshExpire;
|
|
final int refreshExpire;
|
|
final int refreshAfter;
|
|
final int refreshAfter;
|
|
@@ -248,11 +252,11 @@ Future _apiRequest(String method, String path, dynamic data,
|
|
`
|
|
`
|
|
|
|
|
|
tokensFileContentV2 = `class Tokens {
|
|
tokensFileContentV2 = `class Tokens {
|
|
- /// 用于访问的token, 每次请求都必须带在Header里面
|
|
|
|
|
|
+ /// the token used to access, it must be carried in the header of each request
|
|
final String accessToken;
|
|
final String accessToken;
|
|
final int accessExpire;
|
|
final int accessExpire;
|
|
|
|
|
|
- /// 用于刷新token
|
|
|
|
|
|
+ /// the token used to refresh
|
|
final String refreshToken;
|
|
final String refreshToken;
|
|
final int refreshExpire;
|
|
final int refreshExpire;
|
|
final int refreshAfter;
|
|
final int refreshAfter;
|