helper

package
v0.0.0-...-2cc8177 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OK_STATUS  LeetechoStatus  = LeetechoStatus(http.StatusText(http.StatusOK))
	OK_CODE    LeetechoCode    = LeetechoCode(http.StatusOK)
	OK_MESSAGE LeetechoMessage = LeetechoMessage("OK")

	REDIRECT_STATUS  LeetechoStatus  = LeetechoStatus(http.StatusText(http.StatusFound))
	REDIRECT_CODE    LeetechoCode    = LeetechoCode(http.StatusFound)
	REDIRECT_MESSAGE LeetechoMessage = LeetechoMessage("Redirect")

	NOT_MODIFIED_STATUS  LeetechoStatus  = LeetechoStatus(http.StatusText(http.StatusNotModified))
	NOT_MODIFIED_CODE    LeetechoCode    = LeetechoCode(http.StatusNotModified)
	NOT_MODIFIED_MESSAGE LeetechoMessage = LeetechoMessage("Not Modified")

	BAD_REQUEST_STATUS  LeetechoStatus  = LeetechoStatus(http.StatusText(http.StatusBadRequest))
	BAD_REQUEST_CODE    LeetechoCode    = LeetechoCode(http.StatusBadRequest)
	BAD_REQUEST_MESSAGE LeetechoMessage = LeetechoMessage("Bad Request")

	FORBIDDEN_STATUS  LeetechoStatus  = LeetechoStatus(http.StatusText(http.StatusForbidden))
	FORBIDDEN_CODE    LeetechoCode    = LeetechoCode(http.StatusForbidden)
	FORBIDDEN_MESSAGE LeetechoMessage = LeetechoMessage("Forbidden")

	NOT_FOUND_STATUS  LeetechoStatus  = LeetechoStatus(http.StatusText(http.StatusNotFound))
	NOT_FOUND_CODE    LeetechoCode    = LeetechoCode(http.StatusNotFound)
	NOT_FOUND_MESSAGE LeetechoMessage = LeetechoMessage("Not Found")

	INTERNAL_SERVER_ERROR_STATUS  LeetechoStatus  = LeetechoStatus(http.StatusText(http.StatusInternalServerError))
	INTERNAL_SERVER_ERROR_CODE    LeetechoCode    = LeetechoCode(http.StatusInternalServerError)
	INTERNAL_SERVER_ERROR_MESSAGE LeetechoMessage = LeetechoMessage("Internal Server Error")

	BAD_GATEWAY_STATUS  LeetechoStatus  = LeetechoStatus(http.StatusText(http.StatusBadGateway))
	BAD_GATEWAY_CODE    LeetechoCode    = LeetechoCode(http.StatusBadGateway)
	BAD_GATEWAY_MESSAGE LeetechoMessage = LeetechoMessage("Bad Gateway")

	SERVICE_UNAVAILABLE_STATUS  LeetechoStatus  = LeetechoStatus(http.StatusText(http.StatusServiceUnavailable))
	SERVICE_UNAVAILABLE_CODE    LeetechoCode    = LeetechoCode(http.StatusServiceUnavailable)
	SERVICE_UNAVAILABLE_MESSAGE LeetechoMessage = LeetechoMessage("Service Unavailable")

	UNKNOWN_ERROR   LeetechoStatus  = LeetechoStatus("Unknown Error")
	UNKNOWN_CODE    LeetechoCode    = LeetechoCode(1)
	UNKNOWN_MESSAGE LeetechoMessage = LeetechoMessage("Unknown Error")

	NOT_LOGIN_STATUS  LeetechoStatus  = LeetechoStatus("Not Login")
	NOT_LOGIN_CODE    LeetechoCode    = LeetechoCode(4000001)
	NOT_LOGIN_MESSAGE LeetechoMessage = LeetechoMessage("Not Login")

	REQUEST_PARAMS_ERROR_STATUS  LeetechoStatus  = LeetechoStatus("Request Params Error")
	REQUEST_PARAMS_ERROR_CODE    LeetechoCode    = LeetechoCode(4000002)
	REQUEST_PARAMS_ERROR_MESSAGE LeetechoMessage = LeetechoMessage("Request Params Error")

	NOT_A_REPO_STATUS  LeetechoStatus  = LeetechoStatus("Not a Repo")
	NOT_A_REPO_CODE    LeetechoCode    = LeetechoCode(4030003)
	NOT_A_REPO_MESSAGE LeetechoMessage = LeetechoMessage("Not a Repo")

	INVALID_CONFIG_STATUS  LeetechoStatus  = LeetechoStatus("Invalid Config")
	INVALID_CONFIG_CODE    LeetechoCode    = LeetechoCode(4030004)
	INVALID_CONFIG_MESSAGE LeetechoMessage = LeetechoMessage("Invalid Config")

	NO_AC_SUBMISSIONS_STATUS  LeetechoStatus  = LeetechoStatus("No AC Submissions")
	NO_AC_SUBMISSIONS_CODE    LeetechoCode    = LeetechoCode(5000001)
	NO_AC_SUBMISSIONS_MESSAGE LeetechoMessage = LeetechoMessage("No AC Submissions")

	NO_NOTES_STATUS  LeetechoStatus  = LeetechoStatus("No Notes")
	NO_NOTES_CODE    LeetechoCode    = LeetechoCode(5000002)
	NO_NOTES_MESSAGE LeetechoMessage = LeetechoMessage("No Notes")

	REPO_CONNECTION_ERROR_STATUS  LeetechoStatus  = LeetechoStatus("Repo Connection Error")
	REPO_CONNECTION_ERROR_CODE    LeetechoCode    = LeetechoCode(5000003)
	REPO_CONNECTION_ERROR_MESSAGE LeetechoMessage = LeetechoMessage("Repo Connection Error")

	REPO_PUSH_ERROR_STATUS  LeetechoStatus  = LeetechoStatus("Repo Push Error")
	REPO_PUSH_ERROR_CODE    LeetechoCode    = LeetechoCode(5000004)
	REPO_PUSH_ERROR_MESSAGE LeetechoMessage = LeetechoMessage("Repo Push Error")

	NO_USER_CONFIG_STATUS  LeetechoStatus  = LeetechoStatus("No User Config")
	NO_USER_CONFIG_CODE    LeetechoCode    = LeetechoCode(5000005)
	NO_USER_CONFIG_MESSAGE LeetechoMessage = LeetechoMessage("No User Config")

	REPO_INIT_ERROR_STATUS  LeetechoStatus  = LeetechoStatus("Repo Init Error")
	REPO_INIT_ERROR_CODE    LeetechoCode    = LeetechoCode(5000006)
	REPO_INIT_ERROR_MESSAGE LeetechoMessage = LeetechoMessage("Repo Init Error")

	DECODE_JSON_ERROR_STATUS  LeetechoStatus  = LeetechoStatus("Decode JSON Error")
	DECODE_JSON_ERROR_CODE    LeetechoCode    = LeetechoCode(5000007)
	DECODE_JSON_ERROR_MESSAGE LeetechoMessage = LeetechoMessage("Decode JSON Error")
)

Functions

func DecodeResponseJSONBody

func DecodeResponseJSONBody(r *http.Response, dst interface{}) error

func GetHTTPClient

func GetHTTPClient() *http.Client

func HTTPParseHandler

func HTTPParseHandler(resp *http.Response, requestErr error) (interface{}, error)

HTTPParseHandler parses the response and returns the struct of the response and error

@param resp *http.Response
@param requestErr error
@return interface{}  the struct of the response
@return error  	 *ErrorResp{}

func HTTPRequest

func HTTPRequest(param *HTTPRequestParam) (*http.Response, error)

func ParseCookie

func ParseCookie(cookies []string, key string) string

func WrappedHTTPRequest

func WrappedHTTPRequest(param *HTTPRequestParam) (rawResp *http.Response, respJSON interface{}, err error)

Types

type Base

type Base struct {
	US *EndpointURI
	CN *EndpointURI
}
var BaseURI *Base = &Base{
	US: &EndpointURI{
		Base:    "https://leetcode.com/",
		Login:   "https://leetcode.com/accounts/login/",
		Graphql: "https://leetcode.com/graphql",
	},
	CN: &EndpointURI{
		Base:    "https://leetcode.cn/",
		Login:   "https://leetcode.cn/accounts/login/",
		Graphql: "https://leetcode.cn/graphql",
	},
}

type Credit

type Credit struct {
	Session   string
	CSRFToken string
}

type EndPoint

type EndPoint string
const (
	US EndPoint = "US"
	CN EndPoint = "CN"
)

type EndpointURI

type EndpointURI struct {
	Base    string
	Login   string
	Graphql string
}

func GetEndPoint

func GetEndPoint(endPoint EndPoint) *EndpointURI

type ErrorResp

type ErrorResp struct {
	Status  LeetechoStatus  `json:"status"`
	Code    LeetechoCode    `json:"code"`
	Message LeetechoMessage `json:"message"`
}

ErrorResp is the customized error for all leetecho-cli business

func (*ErrorResp) Error

func (e *ErrorResp) Error() string

Error implement the customized error function for all leetecho-cli business

@receiver e the customized error in leetecho-cli business
@return string the customized error message

type GraphqlRequestParam

type GraphqlRequestParam struct {
	Origin  string
	Referer string
	/**
	* Query should be a pointer to struct that corresponds to the GraphQL schema
	 */
	Query     interface{}
	Variables *map[string]interface{}
}

type GraphqlRequestType

type GraphqlRequestType string
const (
	QUERY    GraphqlRequestType = "query"
	MUTATION GraphqlRequestType = "mutation"
)

type HTTPRequestParam

type HTTPRequestParam struct {
	Method                  string
	URL                     string
	Referer                 string
	ResolveWithFullResponse bool
	Form                    *map[string][]string
	Body                    string
	Header                  *map[string]string
}

type Helper

type Helper struct {
	Credit        *Credit
	BaseURI       *EndpointURI
	GraphQLClient *graphql.Client
}

func GetHelper

func GetHelper(credit *Credit, baseURI *EndpointURI) *Helper

*

  • Get the singleton instance of Helper

func (*Helper) GraphqlRequest

func (helper *Helper) GraphqlRequest(reqType GraphqlRequestType, param GraphqlRequestParam) (res *interface{}, reqErr error)

func (*Helper) SetBaseURI

func (helper *Helper) SetBaseURI(baseURI *EndpointURI)

func (*Helper) SetCredit

func (helper *Helper) SetCredit(credit *Credit)

func (*Helper) SwitchEndPoint

func (helper *Helper) SwitchEndPoint(endPoint EndPoint)

type LeetechoCode

type LeetechoCode int

type LeetechoMessage

type LeetechoMessage string

func GetErrorCodeMessage

func GetErrorCodeMessage(code LeetechoCode) LeetechoMessage

type LeetechoStatus

type LeetechoStatus string

type URI

type URI string

Jump to

Keyboard shortcuts

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