api

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const HeaderMachineId = "machine-id"

Variables

View Source
var BaseCommonApiError = &CommonApiErr{}
View Source
var ErrServerRequest = model.WrapIdeaErr(err("Send request failed"), model.IdeaServerRequestFailed)
View Source
var ErrTimeout = model.WrapIdeaErr(err("API request timeout"), model.IdeaApiTimeout)
View Source
var ErrTlsRequest = model.WrapIdeaErr(err("TLS communication error"), model.IdeaServerRequestFailed)
View Source
var ErrTokenInvalid = model.WrapIdeaErr(err("Token invalid"), model.IdeaTokenInvalid)
View Source
var Logger = zap.NewNop()
View Source
var NetworkLogger = zap.NewNop()
View Source
var UnprocessableResponse = model.WrapIdeaErr(err("Unprocessable response"), model.IdeaServerRequestFailed)

Functions

func QueryResult

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

func SendDetect

func SendDetect(input *SendDetectRequest) 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() *Client

func (*Client) BaseURL added in v1.7.9

func (c *Client) BaseURL() string

func (*Client) DoJson

func (c *Client) DoJson(req *http.Request, resBody interface{}) (err 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"`
	Username          string           `json:"username"`
	AlertMessage      string           `json:"alert_message"`
	AlertLevel        display.MsgLevel `json:"alert_level"`
}

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"`
	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"`
	ScanStrategy   string                   `json:"scan_strategy"`
}

Jump to

Keyboard shortcuts

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