trans

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(command []string) ([]byte, error)

Execute - execute the curl command

func ExecuteWithContext

func ExecuteWithContext(ctx context.Context, command []string) ([]byte, error)

Execute - execute the curl command with context

func GetCommand

func GetCommand(req *http.Request, inscure bool) ([]string, string, func() error, error)

GetCommand - return a string list which is the curl command and a function which can remove the temporary file of request body. if inscure is true, the command will add '-k' the list can use strings.Join(result, " ") become a curl command string

func GetResponse

func GetResponse(buf []byte) (*http.Response, error)

GetResponse - translate the command to a http response

Types

type CurlRequest

type CurlRequest interface {
	// GenerateCommand - generate curl command with curl request
	GenerateCommand(inscure bool) error

	// GetCommands - get the curl command
	GetCommands() []string

	// GetFilename - get the filename which contains the request body
	GetFilename() string

	// Execute - execute the curl command
	Execute() ([]byte, error)

	// Do - execute the curl command and get the http.Response, like http.client.Do
	Do() (*http.Response, error)

	// AddHeader - add curl header
	AddHeader(key, value string) error

	// GetHeaders - get all the curl headers
	GetHeaders() http.Header

	// GetHeader - get the specific header value
	GetHeader(key string) []string

	// SetPrivateKey - set the private key
	SetPrivateKey(fileType filetype.FileType, path string)

	// SetCertificate - set the certificate
	SetCertificate(fileType filetype.FileType, path, password string)

	// SetCA - set the ca file
	SetCA(filePath string)
}

func NewCurlRequest

func NewCurlRequest(req *http.Request) (CurlRequest, error)

func NewCurlRequestWithContext

func NewCurlRequestWithContext(ctx context.Context, req *http.Request) (CurlRequest, error)

Jump to

Keyboard shortcuts

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