apis

package
v1.3.0-rc Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PRESALE_SURVEY = ApiSpec{
	Path:   "/api/survey/login",
	Scheme: "http",
	Method: "GET",
	Doc:    "summary: 售前调查 API(伪装成登录接口)",
	Custom: func(rw http.ResponseWriter, req *http.Request) {
		bdl := bundle.New(bundle.WithEventBox())
		f := req.URL.Query()
		content := ""
		content += "真实姓名  : " + f.Get("realname") + "\n" +
			"手机号码  : " + f.Get("mobile") + "\n" +
			"企业邮箱地址: " + f.Get("email") + "\n" +
			"所处职位  : " + f.Get("position") + "\n" +
			"企业名称  : " + f.Get("company") + "\n" +
			"企业规模  : " + f.Get("company_size") + "\n" +
			"IT部门规模 : " + f.Get("it_size") + "\n" +
			"申请目的  : " + f.Get("purpose") + "\n"
		msg := apistructs.MessageCreateRequest{
			Sender: "survey",
			Labels: map[apistructs.MessageLabel]interface{}{
				apistructs.DingdingLabel: []apistructs.Target{{Receiver: conf.SurveyDingding(), Secret: ""}},
			},
			Content: content,
		}
		if err := bdl.CreateMessage(&msg); err != nil {
			logrus.Warnf("failed to POST survey, err: %v", err)
			rw.Header().Set("Content-Type", "application/json")
			rw.WriteHeader(500)
			rw.Write([]byte(`{"success":false,"err":{"msg":"失败"}}`))
			return
		}
		rw.Header().Set("Content-Type", "application/json")
		rw.WriteHeader(200)
		rw.Write([]byte(`{"success":true}`))
	},
}

Functions

func NewSwagger added in v1.1.0

func NewSwagger(title string) *openapi3.Swagger

Types

type ApiSpec

type ApiSpec struct {
	Path        string
	BackendPath string
	Method      string
	Host        string
	// 正常情况下,使用 internal/pkg/innerdomain 能解析转换出 `Host` 对应的 marathonHost 和 k8sHost,
	// 但是,当 `Host` 中的地址是老版的 marathon 内部地址,那么就无法确定 k8s地址会是什么,需要用 `K8SHost` 显式指定
	// 比如以下地址就无法转换
	// "hepa-gateway-1.hepagateway.addon-hepa-gateway.v1.runtimes.marathon.l4lb.thisdcos.directory"
	K8SHost         string
	Scheme          string
	Custom          func(rw http.ResponseWriter, req *http.Request)
	CustomResponse  func(*http.Response) error // 如果是 websocket,没意义,在 generator 里检查
	Audit           func(ctx *spec.AuditContext) error
	NeedDesensitize bool // 是否需要对返回的 userinfo 进行脱敏处理
	CheckLogin      bool
	TryCheckLogin   bool
	CheckToken      bool
	CheckBasicAuth  bool
	ChunkAPI        bool
	Doc             string
	// API 请求 & 应答 类型, 定义在 apistructs
	RequestType  interface{}
	ResponseType interface{}
	// 是否为真正的openapi,会生成2份 swagger doc, 一份是只有openapi的,另一份有所有注册的API
	IsOpenAPI bool
	// API 分类, 默认为Path的第二部分 /a/b/c -> b
	Group string

	// Parameters describes the request and response parameters
	Parameters *Parameters
	// contains filtered or unexported fields
}

ApiSpec 转换成 openapi.api.Spec,方便用户写的类型

func (*ApiSpec) AddOperationTo added in v1.1.0

func (api *ApiSpec) AddOperationTo(v3 *openapi3.Swagger) error

AddOperationTo generates self as an *openapi3.Operation and add it to the *openapi3.Swagger

func (ApiSpec) Convert2AccessibleApi

func (api ApiSpec) Convert2AccessibleApi() apistructs.AccessibleAPI

Convert2AccessibleApi 直接从 openapi 定义生成 openapi oauth2 token 可访问的 api 格式

func (*ApiSpec) IsValidForOperation added in v1.1.0

func (api *ApiSpec) IsValidForOperation() bool

type Parameters added in v1.1.0

type Parameters struct {
	Tag         string
	Header      http.Header
	QueryValues url.Values
	Body        interface{}
	Response    interface{}
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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