模板规范
以下结构体定义为sdk模版内的变量
type SDKTpl struct {
BaseURL string // 现在是写死的localhost:9991
SdkVersion string // 版本,现在也是写死的
ApplicationHash string // 唯一哈希
ReactNative bool
Webhooks []string `json:"webhooks"`
Roles []string `json:"roles"` // 角色列表
Fields []Fields // linkerBuilder
Types []Types // linkerBuilder
Operations []*JsonSchemaOperations // operationsSchema转换(老版使用)
OnceMap map[string]any
MaxLengthMap map[string]*MaxLength
AuthProviders []*wgpb.AuthProvider // 认证配置
DataSources []types.DataSource // 数据源详情
S3Providers []*wgpb.S3UploadConfiguration // S3上传配置
HooksConfig *types.HooksConfiguration // 钩子配置
ProxyDirectories []string // 代理钩子目录
EnumFieldArray []*enumField // 枚举类型定义(新版使用)
ObjectFieldArray []*objectField // 对象类型定义(新版使用)
}
// 对象类型(新)
type objectField struct {
Name string // 对象/字段名
TypeName string // 类型名(为字段时使用)
TypeRef string // 忽略
TypeRefObject *objectField // 类型引用(为字段时使用)
TypeRefEnum *enumField // 枚举引用(为字段时使用)
Required bool // 是否必须(为字段时使用)
IsArray bool // 是否数组(为字段时使用)
IsDefinition bool // 是否全局定义
DocumentPath []string // 文档路径(建议拼接后用来做对象名)
Fields []*objectField // 字段列表(为对象时使用)
Root string // 归属顶层结构体
OperationInfo *operationInfo // operation信息
}
// 枚举类型(新)
type enumField struct {
Name string // 枚举名称
Values []string // 枚举值列表
}
// operation信息(新)
type operationInfo struct {
Name string
Path string
IsInternal bool
IsQuery bool
IsLiveQuery bool
IsMutation bool
IsSubscription bool
}
type JsonSchemaOperations struct {
Name string // operation名称
Path string // operation路径
Copy map[string]interface{} // 用来作筛选
InputSchema types.DataSchema
InputSchemaString string
InjectedSchema types.DataSchema
InjectedSchemaString string
InternalSchema types.DataSchema
InternalSchemaString string
ResponseSchema types.DataSchema
ResponseSchemaString string
Engine wgpb.OperationExecutionEngine `json:"engine"`
IsInternal bool `json:"isInternal"` // 是否内部
IsQuery bool `json:"isQuery"` // 是否查询
IsLiveQuery bool `json:"isLiveQuery"` // 是否实时查询
IsMutation bool `json:"isMutation"` // 是否变更
IsSubscription bool `json:"isSubscription"` // 是否订阅
HasInput bool `json:"hasInput"` // 是否有输入
HasInjectedInput bool `json:"hasInjectedInput"` // 是否有injected输入
HasInternalInput bool `json:"hasInternalInput"` // 是否有internal输入
RequiresAuthentication bool `json:"requiresAuthentication"` //是否需要认证
}
type Fields struct {
Name string `json:"name"`
Args []string `json:"args"`
}
type Types struct {
Name string `json:"name"`
Fields []string `json:"fields"`
}
type HooksConfiguration struct {
Global *HooksGlobalConf
Authentication wgpb.ApiAuthenticationHooks //不使用指针,需要初始化默认值,不然 uuid 没法使用
Queries map[string]*wgpb.OperationHooksConfiguration
Mutations map[string]*wgpb.OperationHooksConfiguration
}
type DataSource struct {
ApiId string `json:"api_id"`
ApiNameSpace string `json:"api_name_space"`
Kind wgpb.DataSourceKind `json:"kind"`
DataBaseURL *wgpb.ConfigurationVariable `json:"data_base_url"`
URL *wgpb.ConfigurationVariable `json:"url"`
SkipRenameRootFields []string `json:"skip_rename_root_fields"`
Source Source `json:"source"` // openApi json 文件
BaseURL string `json:"base_url"` // openApi baseUrl
IsFederation bool `json:"is_federation"` // graphql 配置,默认 false,暂时没有理解, 貌似是看数据源是不是独立的子图
Header HeadValues `json:"header"`
IsCustomized bool `json:"is_customized"`
}
type AuthProvider struct {
Id string `json:"id"`
Kind AuthProviderKind `json:"kind"`
GithubConfig *GithubAuthProviderConfig `json:"githubConfig"`
OidcConfig *OpenIDConnectAuthProviderConfig `json:"oidcConfig"`
}
type S3UploadConfiguration struct {
Name string `json:"name"`
Endpoint *ConfigurationVariable `json:"endpoint"`
AccessKeyID *ConfigurationVariable `json:"accessKeyID"`
SecretAccessKey *ConfigurationVariable `json:"secretAccessKey"`
BucketName *ConfigurationVariable `json:"bucketName"`
BucketLocation *ConfigurationVariable `json:"bucketLocation"`
UseSSL bool `json:"useSSL"`
UploadProfiles map[string]*S3UploadProfile `json:"uploadProfiles" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
}�
全局Helpers注册
片段函数注册及调用(扫描目录partials下的文件,文件名作为helper函数,文件内容为函数执行结果片段)
使用特殊姿势
子表达式
遍历map
遍历slice
with临时变量
变长参数
最后更新于
这有帮助吗?