api

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package api 存放对服务端的API调用逻辑,考虑到日后服务器API会有大改,便于解耦

Index

Constants

This section is empty.

Variables

View Source
var BaseCommonApiError = &CommonApiErr{}
View Source
var ErrServerRequest = errors.New("Send request failed")
View Source
var ErrTimeout = errors.New("API request timeout")
View Source
var ErrTokenInvalid = errors.New("Token invalid")
View Source
var UnprocessableResponse = errors.New("Unprocessable response")

Functions

func QueryResult

func QueryResult(taskId string) (*model.TaskScanResponse, error)

func SendDetect

func SendDetect(input *SendDetectRequest) error

func StartCheck

func StartCheck(taskId string) error

func StartCheckTaskType

func StartCheckTaskType(taskId string, kind model.TaskKind) error

func UploadChunk

func UploadChunk(taskId string, chunkId int, reader io.Reader) error

Types

type Client

type Client struct {
	Token string
	// contains filtered or unexported fields
}
var C *Client

func NewClient

func NewClient(baseUrl string) *Client

func (*Client) DoJson

func (c *Client) DoJson(req *http.Request, resBody interface{}) error

func (*Client) GET

func (c *Client) GET(relUri string) *http.Request

func (*Client) POST

func (c *Client) POST(relUri string, body io.Reader) *http.Request

func (*Client) PostJson

func (c *Client) PostJson(relUri string, a interface{}) *http.Request

type CommonApiErr

type CommonApiErr struct {
	EError struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
		Details string `json:"details"`
	} `json:"error"`
}

func (*CommonApiErr) Error

func (c *CommonApiErr) Error() string

func (*CommonApiErr) Is

func (c *CommonApiErr) Is(e error) bool

type Contributor

type Contributor struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

type CreateTaskGitInfo

type CreateTaskGitInfo struct {
	GitRemoteUrl string `json:"git_remote_url"`
	GitBranch    string `json:"git_branch"`
	Commit       string `json:"commit"`
}

type CreateTaskRequest

type CreateTaskRequest struct {
	CliVersion      string              `json:"cli_version"`
	TaskKind        model.TaskKind      `json:"task_kind"`
	TaskType        model.TaskType      `json:"task_type"`
	UserAgent       string              `json:"user_agent"`
	CmdLine         string              `json:"cmd_line"`
	ApiToken        string              `json:"api_token"`
	GitInfo         *VoGitInfo          `json:"git_info,omitempty"`
	ProjectName     string              `json:"project_name"`
	TargetAbsPath   string              `json:"target_abs_path"`
	ProjectType     model.ProjectType   `json:"project_type"`
	ContributorList []model.Contributor `json:"contributor_list,omitempty"`
	ProjectId       string              `json:"project_id,omitempty"`
}

type CreateTaskResponse

type CreateTaskResponse struct {
	TaskInfo          string `json:"task_info"`
	TotalContributors int    `json:"total_contributors"`
	ProjectId         string `json:"project_id"`
}

func CreateTask

func CreateTask(req *CreateTaskRequest) (*CreateTaskResponse, error)

type ModuleType

type ModuleType string
const (
	ModuleTypeVersion  ModuleType = "version"
	ModuleTypeFileHash ModuleType = "file_hash"
)

type SendDetectRequest

type SendDetectRequest struct {
	TaskInfo string     `json:"task_info"`
	ApiToken string     `json:"api_token"`
	Modules  []VoModule `json:"modules"`
}

type VoFileHash

type VoFileHash struct {
	Path string `json:"path"`
	Hash string `json:"hash"`
}

type VoGitInfo

type VoGitInfo struct {
	Commit        string    `json:"commit"`
	GitRef        string    `json:"git_ref"`
	GitRemoteUrl  string    `json:"git_remote_url"`
	CommitMessage string    `json:"commit_message"`
	CommitEmail   string    `json:"commit_email"`
	CommitTime    time.Time `json:"commit_time"`
}

type VoModule

type VoModule struct {
	Dependencies   []model.Dependency       `json:"dependencies,omitempty"`
	FileHashList   []VoFileHash             `json:"file_hash_list,omitempty"`
	Language       model.Language           `json:"language,omitempty"`
	Name           string                   `json:"name,omitempty"`
	PackageFile    string                   `json:"package_file,omitempty"`
	PackageManager model.PackageManagerType `json:"package_manager,omitempty"`
	RelativePath   string                   `json:"relative_path,omitempty"`
	RuntimeInfo    interface{}              `json:"runtime_info,omitempty"`
	Version        string                   `json:"version,omitempty"`
	ModuleUUID     uuid.UUID                `json:"module_uuid,omitempty"`
	ModuleType     ModuleType               `json:"module_type"`
}

Jump to

Keyboard shortcuts

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