http

package
v0.0.0-...-baadd90 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package http provides basic http request/response method and definition

Index

Constants

View Source
const (
	POST   = "POST"
	GET    = "GET"
	PATCH  = "PATCH"
	DELETE = "DELETE"

	HTTP  = "http"
	HTTPS = "https"

	Domain = "api.apitable.com"
	Path   = "/"
)
View Source
const (
	FormContent = "application/x-www-form-urlencoded"
	JsonContent = "application/json"
)

Variables

This section is empty.

Functions

func ConstructParams

func ConstructParams(req Request) (err error)

func GetUrlQueriesEncoded

func GetUrlQueriesEncoded(params map[string]string) string

func ParseFromHttpResponse

func ParseFromHttpResponse(hr *http.Response, response Response) (err error)

Types

type BaseRequest

type BaseRequest struct {
	// contains filtered or unexported fields
}

func (*BaseRequest) GetBodyReader

func (r *BaseRequest) GetBodyReader() io.Reader

func (*BaseRequest) GetContentType

func (r *BaseRequest) GetContentType() string

func (*BaseRequest) GetDomain

func (r *BaseRequest) GetDomain() string

func (*BaseRequest) GetFile

func (r *BaseRequest) GetFile() []byte

func (*BaseRequest) GetHttpMethod

func (r *BaseRequest) GetHttpMethod() string

func (*BaseRequest) GetParams

func (r *BaseRequest) GetParams() map[string]string

func (*BaseRequest) GetPath

func (r *BaseRequest) GetPath() string

func (*BaseRequest) GetScheme

func (r *BaseRequest) GetScheme() string

func (*BaseRequest) GetUrl

func (r *BaseRequest) GetUrl() string

func (*BaseRequest) Init

func (r *BaseRequest) Init() *BaseRequest

func (*BaseRequest) SetContentType

func (r *BaseRequest) SetContentType(contentType string)

func (*BaseRequest) SetDomain

func (r *BaseRequest) SetDomain(domain string)

func (*BaseRequest) SetFile

func (r *BaseRequest) SetFile(byte []byte)

func (*BaseRequest) SetHttpMethod

func (r *BaseRequest) SetHttpMethod(method string)

func (*BaseRequest) SetPath

func (r *BaseRequest) SetPath(path string)

func (*BaseRequest) SetScheme

func (r *BaseRequest) SetScheme(scheme string)

type BaseResponse

type BaseResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Success bool   `json:"success"`
	// unique request id, will be return each time request.
	// when positioning question, it's necessary to provider request id.
	RequestId *string
}

func (*BaseResponse) ParseErrorFromHTTPResponse

func (r *BaseResponse) ParseErrorFromHTTPResponse(body []byte) (err error)

type ErrorResponse

type ErrorResponse struct {
	BaseResponse
}

type Request

type Request interface {
	GetBodyReader() io.Reader
	GetScheme() string
	GetDomain() string
	GetHttpMethod() string
	GetParams() map[string]string
	GetPath() string
	GetUrl() string
	GetContentType() string
	GetFile() []byte
	SetScheme(string)
	SetDomain(string)
	SetHttpMethod(string)
	SetPath(string)
	SetContentType(string)
	SetFile([]byte)
}

type Response

type Response interface {
	ParseErrorFromHTTPResponse(body []byte) error
}

Jump to

Keyboard shortcuts

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