Skip to content
On this page

API 解读

type APIRequest

go
type APIRequest struct {
	Method   string // 请问求方式 POST,GET 等等
	Endpoint string // 请求端点,为jks的rest api 不带host部分的url
	Payload  io.Reader // 有效荷载 响应数据body的内容就在其中
	Headers  http.Header // http请求头
	Suffix   string // 后缀
}

1. func NewAPIRequest

创建一个API连接请求

go
func NewAPIRequest(method string, endpoint string, payload io.Reader) *APIRequest

2. func (*APIRequest) SetHeader

设置请求头

go
func (ar *APIRequest) SetHeader(key string, value string) *APIRequest

使用案例

go
func TestJust(t *testing.T) {
	// 失败
	ctx := context.Background()
	jenkins, _ := gojenkins.CreateJenkins(nil, "http://localhost:8080/", "admin", "admin").Init(ctx)

	// JobName
	jobName := "JavaTest"

	// 请求端点
	endpoint := "/job/" + jobName + "/logText/progressiveHtml"
	//响应荷载
	var payload io.Reader
	// 发送GET请求
	request := gojenkins.NewAPIRequest("GET", endpoint, payload)
	
	request.SetHeader("auth", "Bearxxxxxxx")
}