Documentation ¶
Index ¶
- Constants
- Variables
- func AllAuthTypes() []maps.Map
- func AllStatusTypes() []maps.Map
- func ContainsAuthType(authType string) bool
- func FindAuthTypeName(authType string) string
- type API
- func (this *API) AddMock(filename string)
- func (this *API) AddParam(param *APIParam)
- func (this *API) AddScript(script *APIScript)
- func (this *API) AddTestCase(filename string)
- func (this *API) AllowMethod(method string) bool
- func (this *API) CachePolicyObject() *shared.CachePolicy
- func (this *API) ChangeGroup(oldName string, newName string)
- func (this *API) ChangeVersion(oldName string, newName string)
- func (this *API) Delete() error
- func (this *API) DeleteMock(mockFile string)
- func (this *API) DeleteTestCase(filename string)
- func (this *API) DeleteTestScript(filename string) error
- func (this *API) FindTestCases() []*APITestCase
- func (this *API) FindTestScript(filename string) *APIScript
- func (this *API) FindTestScripts() []*APIScript
- func (this *API) IsWatching() bool
- func (this *API) Match(path string) (params map[string]string, matched bool)
- func (this *API) MockDataFiles() []string
- func (this *API) RandMock() *APIMock
- func (this *API) RemoveGroup(name string)
- func (this *API) RemoveVersion(name string)
- func (this *API) Save() error
- func (this *API) StartWatching()
- func (this *API) StopWatching()
- func (this *API) Validate() error
- type APIAuthBasicAuth
- type APIAuthInterface
- func NewAPIAuth(authType string, options map[string]interface{}) APIAuthInterface
- func NewAPIAuthBasicAuth(options map[string]interface{}) APIAuthInterface
- func NewAPIAuthKeyAuth(options map[string]interface{}) APIAuthInterface
- func NewAPIAuthNoneAuth(options map[string]interface{}) APIAuthInterface
- type APIAuthKeyAuth
- type APIAuthNoneAuth
- type APIConfig
- func (this *APIConfig) AddAPI(api *API)
- func (this *APIConfig) AddAPIGroup(name string)
- func (this *APIConfig) AddAPIVersion(name string)
- func (this *APIConfig) AddConsumer(consumerFile string)
- func (this *APIConfig) AddStatus(status *APIStatus)
- func (this *APIConfig) AddTestPlan(filename string)
- func (this *APIConfig) ChangeAPIGroup(oldName string, newName string)
- func (this *APIConfig) ChangeAPIVersion(oldName string, newName string)
- func (this *APIConfig) DeleteAPI(api *API)
- func (this *APIConfig) DeleteConsumer(consumerFile string)
- func (this *APIConfig) DeleteTestPlan(filename string) error
- func (this *APIConfig) ExistStatusCode(code string) bool
- func (this *APIConfig) FindAPI(path string) *API
- func (this *APIConfig) FindAPIStatus(code string) *APIStatus
- func (this *APIConfig) FindActiveAPI(path string, method string) (api *API, params map[string]string)
- func (this *APIConfig) FindAllAPIs() []*API
- func (this *APIConfig) FindAllConsumers() []*APIConsumer
- func (this *APIConfig) FindAllRunningConsumers() []*APIConsumer
- func (this *APIConfig) FindConsumerForRequest(authType string, req *http.Request) (consumer *APIConsumer, authorized bool)
- func (this *APIConfig) FindTestPlans() []*APITestPlan
- func (this *APIConfig) MoveAPIStatus(fromIndex int, toIndex int)
- func (this *APIConfig) MoveDownAPIGroup(name string)
- func (this *APIConfig) MoveDownAPIStatus(code string)
- func (this *APIConfig) MoveDownAPIVersion(name string)
- func (this *APIConfig) MoveUpAPIGroup(name string)
- func (this *APIConfig) MoveUpAPIStatus(code string)
- func (this *APIConfig) MoveUpAPIVersion(name string)
- func (this *APIConfig) RefreshStatusMap()
- func (this *APIConfig) ReloadConsumers()
- func (this *APIConfig) RemoveAPIGroup(name string)
- func (this *APIConfig) RemoveAPIVersion(name string)
- func (this *APIConfig) RemoveStatus(code string)
- func (this *APIConfig) UpdateAPI(api *API)
- func (this *APIConfig) Validate() error
- type APIConsumer
- type APIDataLimit
- type APILimit
- type APIMock
- type APIParam
- type APIRequestLimit
- type APIScript
- type APIStatus
- type APITestCase
- type APITestPlan
- func (this *APITestPlan) AddReport(reportFilename string)
- func (this *APITestPlan) Delete() error
- func (this *APITestPlan) LastReport() *APITestPlanReport
- func (this *APITestPlan) MatchTime(currentTime time.Time) bool
- func (this *APITestPlan) Save() error
- func (this *APITestPlan) WeekdayNames() []string
- type APITestPlanReport
- func (this *APITestPlanReport) AddAPIResult(apiResult *APITestResult)
- func (this *APITestPlanReport) CountFailedResults() int
- func (this *APITestPlanReport) CountResults() int
- func (this *APITestPlanReport) CountScripts() int
- func (this *APITestPlanReport) InitFile()
- func (this *APITestPlanReport) Save() error
- func (this *APITestPlanReport) Summary() maps.Map
- type APITestResult
- type APITestScriptResult
- type APIVersion
- type ApiWatching
Constants ¶
View Source
const ( APIAuthTypeNone = "none" APIAuthTypeBasicAuth = "basicAuth" APIAuthTypeKeyAuth = "keyAuth" )
认证类型
View Source
const ( APIMockFormatJSON = "json" APIMockFormatXML = "xml" APIMockFormatText = "text" APIMockFormatFile = "file" )
API的mock格式定义
View Source
const ( APIStatusTypeNormal = "normal" APIStatusTypeSuccess = "success" APIStatusTypeWarning = "warning" APIStatusTypeFailure = "failure" APIStatusTypeError = "error" )
API状态常量
Variables ¶
Functions ¶
Types ¶
type API ¶
type API struct { shared.HeaderList Filename string `yaml:"filename" json:"filename"` // 文件名 Path string `yaml:"path" json:"path"` // 访问路径 Address string `yaml:"address" json:"address"` // 实际地址 Methods []string `yaml:"methods" json:"methods"` // 方法 Params []*APIParam `yaml:"params" json:"params"` // 参数 Name string `yaml:"name" json:"name"` // 名称 Description string `yaml:"description" json:"description"` // 描述 MockFiles []string `yaml:"mockFiles" json:"mockFiles"` // 假数据文件(Mock) MockOn bool `yaml:"mockOn" json:"mockOn"` // 是否开启Mock Author string `yaml:"author" json:"author"` // 作者 Company string `yaml:"company" json:"company"` // 公司或团队 IsAsynchronous bool `yaml:"isAsynchronous" json:"isAsynchronous"` // TODO Timeout float64 `yaml:"timeout" json:"timeout"` // TODO MaxSize uint `yaml:"maxSize" json:"maxSize"` // TODO TodoThings []string `yaml:"todo" json:"todo"` // 待做事宜 DoneThings []string `yaml:"done" json:"done"` // 已完成事宜 Response []byte `yaml:"response" json:"response"` // 响应内容 TODO IsDeprecated bool `yaml:"isDeprecated" json:"isDeprecated"` // 是否过期 On bool `yaml:"on" json:"on"` // 是否开启 Versions []string `yaml:"versions" json:"versions"` // 版本信息 ModifiedAt int64 `yaml:"modifiedAt" json:"modifiedAt"` // 最后修改时间 Username string `yaml:"username" json:"username"` // 最后修改用户名 Groups []string `yaml:"groups" json:"groups"` // 分组 Limit *APILimit `yaml:"limit" json:"limit"` // 限制 TODO AuthType string `yaml:"authType" json:"authType"` // 认证方式 TestScripts []string `yaml:"testScripts" json:"testScripts"` // 脚本文件 TestCaseFiles []string `yaml:"testCaseFiles" json:"testCaseFiles"` // 单元测试存储文件 CachePolicy string `yaml:"cachePolicy" json:"cachePolicy"` // 缓存策略 CacheOn bool `yaml:"cacheOn" json:"cacheOn"` // 缓存是否打开 TODO // contains filtered or unexported fields }
API定义
func (*API) ChangeVersion ¶
修改API某个版本号
type APIAuthBasicAuth ¶
Basic Auth
func (*APIAuthBasicAuth) KeyFromRequest ¶
func (this *APIAuthBasicAuth) KeyFromRequest(req *http.Request) string
func (*APIAuthBasicAuth) MatchRequest ¶
func (this *APIAuthBasicAuth) MatchRequest(req *http.Request) bool
func (*APIAuthBasicAuth) UniqueKey ¶
func (this *APIAuthBasicAuth) UniqueKey() string
type APIAuthInterface ¶
type APIAuthInterface interface { // 唯一Key UniqueKey() string // 从Request中读取Key KeyFromRequest(req *http.Request) string // 匹配Request MatchRequest(req *http.Request) bool }
认证接口
func NewAPIAuth ¶
func NewAPIAuth(authType string, options map[string]interface{}) APIAuthInterface
新对象
func NewAPIAuthBasicAuth ¶
func NewAPIAuthBasicAuth(options map[string]interface{}) APIAuthInterface
func NewAPIAuthKeyAuth ¶
func NewAPIAuthKeyAuth(options map[string]interface{}) APIAuthInterface
func NewAPIAuthNoneAuth ¶
func NewAPIAuthNoneAuth(options map[string]interface{}) APIAuthInterface
type APIAuthKeyAuth ¶
Key Auth
func (*APIAuthKeyAuth) KeyFromRequest ¶
func (this *APIAuthKeyAuth) KeyFromRequest(req *http.Request) string
func (*APIAuthKeyAuth) MatchRequest ¶
func (this *APIAuthKeyAuth) MatchRequest(req *http.Request) bool
func (*APIAuthKeyAuth) UniqueKey ¶
func (this *APIAuthKeyAuth) UniqueKey() string
type APIAuthNoneAuth ¶
type APIAuthNoneAuth struct { }
默认认证(无认证)
func (*APIAuthNoneAuth) KeyFromRequest ¶
func (this *APIAuthNoneAuth) KeyFromRequest(req *http.Request) string
func (*APIAuthNoneAuth) MatchRequest ¶
func (this *APIAuthNoneAuth) MatchRequest(req *http.Request) bool
func (*APIAuthNoneAuth) UniqueKey ¶
func (this *APIAuthNoneAuth) UniqueKey() string
type APIConfig ¶
type APIConfig struct { On bool `yaml:"on" json:"on"` // 是否开启API功能 Files []string `yaml:"files" json:"files"` // API文件列表 Groups []string `yaml:"groups" json:"groups"` // API分组 Versions []string `yaml:"versions" json:"versions"` // API版本 TestPlans []string `yaml:"testPlans" json:"testPlans"` // API测试计划 StatusList []*APIStatus `yaml:"status" json:"status"` // 状态码列表 StatusScriptOn bool `yaml:"statusScriptOn" json:"statusScriptOn"` // 是否开启状态码分析脚本 StatusScript string `yaml:"statusScript" json:"statusScript"` // 状态码分析脚本 MockOn bool `yaml:"mockOn" json:"mockOn"` // 是否开启Mock ConsumerFiles []string `yaml:"consumerFiles" json:"consumerFiles"` // 消费者(调用的开发者) // contains filtered or unexported fields }
服务的API配置
func (*APIConfig) ChangeAPIGroup ¶
修改API分组
func (*APIConfig) ChangeAPIVersion ¶
修改API版本
func (*APIConfig) DeleteConsumer ¶
删除consumer
func (*APIConfig) DeleteTestPlan ¶
删除某个测试计划
func (*APIConfig) ExistStatusCode ¶
判断状态代号是否存在
func (*APIConfig) FindAPIStatus ¶
根据代号查找状态码
func (*APIConfig) FindActiveAPI ¶
func (this *APIConfig) FindActiveAPI(path string, method string) (api *API, params map[string]string)
查找激活状态中的API
func (*APIConfig) FindAllConsumers ¶
func (this *APIConfig) FindAllConsumers() []*APIConsumer
查询所有的Consumer
func (*APIConfig) FindAllRunningConsumers ¶
func (this *APIConfig) FindAllRunningConsumers() []*APIConsumer
查询所有正在运行的Consumer
func (*APIConfig) FindConsumerForRequest ¶
func (this *APIConfig) FindConsumerForRequest(authType string, req *http.Request) (consumer *APIConsumer, authorized bool)
查找某个认证类型的Consumer
func (*APIConfig) MoveAPIStatus ¶
移动位置
func (*APIConfig) MoveDownAPIGroup ¶
把API分组往下调整
func (*APIConfig) MoveDownAPIStatus ¶
把API分组往下调整
func (*APIConfig) MoveDownAPIVersion ¶
把API版本往下调整
func (*APIConfig) MoveUpAPIVersion ¶
把API版本往上调整
type APIConsumer ¶
type APIConsumer struct { Filename string `yaml:"filename" json:"filename"` // 文件名 On bool `yaml:"on" json:"on"` // 是否开启 TODO Name string `yaml:"name" json:"name"` // 名称 // 认证 Auth struct { On bool `yaml:"on" json:"on"` // 是否开启 TODO Type string `yaml:"type" json:"type"` // 类型 Options map[string]interface{} `yaml:"options" json:"options"` // 选项 } `yaml:"auth" json:"auth"` // API控制 API struct { On bool `yaml:"on" json:"on"` // 是否开启 AllowAll bool `yaml:"allowAll" json:"allowAll"` // 是否允许所有 DenyAll bool `yaml:"denyAll" json:"denyAll"` // 是否禁止所有 Allow []string `yaml:"allow" json:"allow"` // 允许的API Deny []string `yaml:"deny" json:"deny"` // 禁止的API } `yaml:"api" json:"api"` // API控制 Policy shared.AccessPolicy `yaml:"policy" json:"policy"` // 控制策略 }
API consumer
func (*APIConsumer) AllowAPI ¶
func (this *APIConsumer) AllowAPI(apiPath string) (passed bool)
消费API
type APIDataLimit ¶
type APIDataLimit struct { Max uint `yaml:"max" json:"max"` // 最大数据量 TODO Total uint `yaml:"total" json:"total"` // 数据量 TODO Duration string `yaml:"duration" json:"duration"` // 数据限制间隔 TODO // contains filtered or unexported fields }
api数据量限制
type APILimit ¶
type APILimit struct { Concurrent uint `yaml:"concurrent" json:"concurrent"` // 并发数 RequestLimits []*APIRequestLimit `yaml:"request" json:"request"` // 请求数限制 TODO DataLimits []*APIDataLimit `yaml:"data" json:"data"` // 数据量限制 TODO // contains filtered or unexported fields }
API限制
type APIMock ¶
type APIMock struct { Filename string `yaml:"filename" json:"filename"` // 保存的文件名 On bool `yaml:"on" json:"on"` // 是否开启 Headers []maps.Map `yaml:"headers" json:"headers"` // 输出的Header Format string `yaml:"format" json:"format"` // 格式 Text string `yaml:"text" json:"text"` // 文本 File string `yaml:"file" json:"file"` // 文件名,一般是和文本二选一 Username string `yaml:"username" json:"username"` // 创建的用户名 CreatedAt int64 `yaml:"createdAt" json:"createdAt"` // 创建时间 }
API Mock定义
type APIParam ¶
type APIParam struct { Name string `yaml:"name" json:"name"` Type string `yaml:"type" json:"type"` Description string `yaml:"description" json:"description"` }
API参数定义
type APIRequestLimit ¶
type APIRequestLimit struct { Count uint `yaml:"count" json:"count"` // 请求数 TODO Duration string `yaml:"duration" json:"duration"` // 请求限制间隔 TODO // contains filtered or unexported fields }
api请求数限制
func (*APIRequestLimit) Validate ¶
func (this *APIRequestLimit) Validate() error
type APIScript ¶
type APIScript struct { Filename string `yaml:"filename" json:"filename"` // 脚本路径 Code string `yaml:"code" json:"code"` // 代码 }
脚本定义
type APIStatus ¶
type APIStatus struct { Code string `yaml:"code" json:"code"` // 代码 Description string `yaml:"description" json:"description"` // 描述 Groups []string `yaml:"groups" json:"groups"` // 分组 Versions []string `yaml:"versions" json:"versions"` // 版本 Type string `yaml:"type" json:"type"` // 类型 }
API状态定义
type APITestCase ¶
type APITestCase struct { Filename string `yaml:"filename" json:"filename"` // 文件名 Name string `yaml:"name" json:"name"` // 名称 Domain string `yaml:"domain" json:"domain"` // 域名 Method string `yaml:"method" json:"method"` // 方法 Query string `yaml:"query" json:"query"` // URL附加参数 Headers []maps.Map `yaml:"headers" json:"headers"` // Header Params []maps.Map `yaml:"params" json:"params"` // 内置参数 AttachParams []maps.Map `yaml:"attachParams" json:"attachParams"` // 附加参数 Format string `yaml:"format" json:"format"` // 响应格式 Username string `yaml:"username" json:"username"` // 用户名 CreatedAt int64 `yaml:"createdAt" json:"createdAt"` // 创建时间 UpdatedAt int64 `yaml:"updatedAt" json:"updatedAt"` // 更新时间 }
测试历史
type APITestPlan ¶
type APITestPlan struct { On bool `yaml:"on" json:"on"` // 是否开启 Filename string `yaml:"filename" json:"filename"` // 配置文件名 Hour int `yaml:"hour" json:"hour"` // 小时 Minute int `yaml:"minute" json:"minute"` // 分钟 Second int `yaml:"second" json:"second"` // 秒 Weekdays []int `yaml:"weekdays" json:"weekdays"` // 周 Reports []string `yaml:"reports" json:"reports"` // 报告文件名 APIs []string `yaml:"apis" json:"apis"` // 参与计划的API TODO 需要实现 }
API测试计划
type APITestPlanReport ¶
type APITestPlanReport struct { Filename string `yaml:"filename" json:"filename"` // 文件名 StartedAt int64 `yaml:"startedAt" json:"startedAt"` // 开始时间 FinishedAt int64 `yaml:"finishedAt" json:"finishedAt"` // 结束时间 TotalAPIs int `yaml:"totalApis" json:"totalApis"` // 总体API数量 TotalScripts int `yaml:"totalScripts" json:"totalScripts"` // 总体脚本总数 Results []*APITestResult `yaml:"results" json:"results"` // 统计 // contains filtered or unexported fields }
API测试报告
func NewAPITestPlanReportFromFile ¶
func NewAPITestPlanReportFromFile(filename string) *APITestPlanReport
从配置文件中加载测试报告
func (*APITestPlanReport) AddAPIResult ¶
func (this *APITestPlanReport) AddAPIResult(apiResult *APITestResult)
添加API执行结果
func (*APITestPlanReport) CountFailedResults ¶
func (this *APITestPlanReport) CountFailedResults() int
计算失败的结果数
type APITestResult ¶
type APITestResult struct { API string `yaml:"api" json:"api"` // API Scripts []*APITestScriptResult `yaml:"scripts" json:"scripts"` // 脚本 IsPassed bool `yaml:"isPassed" json:"isPassed"` // 是否通过测试 }
单个API测试结果
func (*APITestResult) AddScriptResult ¶
func (this *APITestResult) AddScriptResult(scriptResult *APITestScriptResult)
添加脚本执行结果
type APITestScriptResult ¶
type APITestScriptResult struct { Code string `yaml:"code" json:"code"` // 脚本代码 IsPassed bool `yaml:"isPassed" json:"isPassed"` // 是否通过测试 Failures []string `yaml:"failures" json:"failures"` // 失败 }
单个脚本测试结果
type APIVersion ¶
type APIVersion struct { Name string `yaml:"name" json:"name"` Code string `yaml:"code" json:"code"` On bool `yaml:"on" json:"on"` }
API版本定义
type ApiWatching ¶
type ApiWatching struct {
// contains filtered or unexported fields
}
API监控管理
func NewApiWatching ¶
func NewApiWatching() *ApiWatching
func (*ApiWatching) Add ¶
func (this *ApiWatching) Add(path string)
func (*ApiWatching) Contains ¶
func (this *ApiWatching) Contains(path string) bool
func (*ApiWatching) Remove ¶
func (this *ApiWatching) Remove(path string)
Source Files ¶
- api.go
- api_auth.go
- api_auth_basic.go
- api_auth_key.go
- api_auth_none.go
- api_config.go
- api_consumer.go
- api_data_limit.go
- api_limit.go
- api_mock.go
- api_param.go
- api_request_limit.go
- api_script.go
- api_status.go
- api_test_case.go
- api_test_plan.go
- api_test_plan_report.go
- api_test_result.go
- api_test_script_result.go
- api_version.go
- api_watch.go
Click to show internal directories.
Click to hide internal directories.