utils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString converts a byte slice to a string.

It takes a parameter b, which is a byte slice. It returns a string.

This function is implemented using the `unsafe` package to achieve zero cost conversion.

func CreateTempFile

func CreateTempFile(data []byte) (string, error)

CreateTempFile creates a temporary file and writes the provided data to it.

Parameters:

  • data: the data to be written to the file.

Returns:

  • string: the absolute path of the created file.
  • error: an error if any occurred during the process.

func FastStatusCode

func FastStatusCode(resp *FastResponse) int

FastStatusCode returns fasthttp status code

func FindNameIterTo

func FindNameIterTo(r *qxml.Reader, name string, to string) bool

FindNameIterTo finds the given name iteratively in the qxml Reader until it reaches the specified end element.

Parameters:

  • r: a pointer to the qxml Reader.
  • name: the name to search for in the qxml Reader.
  • to: the end element name to stop the search.

Returns:

  • true if the name is found before reaching the end element, false otherwise.

func MatchNameIterTo

func MatchNameIterTo(r *qxml.Reader, namePattern string, toPattern string) bool

MatchNameIterTo is a function that matches the name pattern and the to pattern iteratively using the given qxml.Reader. It returns true if the name pattern is matched and false if the to pattern is matched or if the end of the reader is reached.

Parameters:

  • r: A pointer to a qxml.Reader object
  • namePattern: The regular expression pattern to match the name
  • toPattern: The regular expression pattern to match the to

Return:

  • bool: true if the name pattern is matched, false otherwise

func MaxLineLen

func MaxLineLen(s string) int

MaxLineLen returns the maximum line length in a given string.

Parameters:

  • s: the input string to check for maximum line length.

Return type:

  • int: the maximum line length in the given string.

func MaxLineLenWithPrefix

func MaxLineLenWithPrefix(s string, prefix []byte) (string, int)

MaxLineLenWithPrefix calculates the maximum line length in a string with a given prefix.

Parameters:

  • s: the input string
  • prefix: the prefix to add to each line

Returns:

  • string: the modified string with the added prefix
  • int: the maximum line length (including the prefix)

func MimeTypeFromURL

func MimeTypeFromURL(u string) (string, string)

MimeTypeFromURL returns the MIME type and lowercase file extension from a given URL.

Parameters:

  • u(string): The URL from which to extract the MIME type and file extension.

Returns:

  • string: The MIME type extracted from the URL.
  • string: The file extension extracted from the URL.

func ParseRelsMap

func ParseRelsMap(f *zip.File, preffix string) (map[string]string, error)

ParseRelsMap parses a zip file and returns a mapping of relationship IDs to target strings.

Parameters:

  • f: *zip.File object representing the zip file to parse.
  • prefix: string prefix used to construct full part name(target string).

Returns:

  • map[string]string: a mapping of relationship IDs to target strings.
  • error: an error object indicating any error occurred during parsing.

func StringTobytes

func StringTobytes(s string) []byte

StringTobytes converts a string to a byte slice.

It takes a string parameter `s` and returns a byte slice.

This function is implemented using the `unsafe` package to achieve zero cost conversion.

Types

type FastResponse

type FastResponse struct {
	Body       []byte
	StatusCode int
}

func FastGet

func FastGet(u string, reqSetters ...ReqSetter) (*FastResponse, error)

FastGet retrieves a response from the specified URL using the GET method.

Parameters:

  • u: The URL to send the GET request to.
  • reqSetters: Optional request setters to modify the request before sending.

Returns:

  • *FastResponse: A pointer to the FastResponse struct containing the response body and status code.
  • error: An error object if the request fails.

func FastPut

func FastPut(u string, reqSetters ...ReqSetter) (*FastResponse, error)

FastPut sends a fast HTTP PUT request to the specified URL with optional request setters.

Parameters:

  • u: The URL to send the request to.
  • reqSetters: Optional request setters to customize the request before sending.

Returns:

  • fastResp: The response from the request containing the response body and status code.
  • error: An error if the request fails.

type ReqSetter

type ReqSetter func(req *fasthttp.Request)

func WithBodyStream

func WithBodyStream(r io.Reader, size int) ReqSetter

WithBodyStream sets the body of the fasthttp request to the given reader and size.

Parameters:

  • r: The reader to use as the body of the request.
  • size: The size of the body.

Returns:

  • ReqSetter: func(req *fasthttp.Request)

func WithHeaders

func WithHeaders(headers map[string]string) ReqSetter

WithHeaders sets the headers of the request.

Parameters:

  • headers: a map of string keys to string values representing the headers to be set.

Returns:

  • ReqSetter: func(req *fasthttp.Request)

Jump to

Keyboard shortcuts

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