utils

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 30 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRequest

func CheckRequest[Structure RequestStructure](httpRequest *http.Request, expectedRequestMethod string, structure *Structure) (virest.Error, bool)

Check the expected HTTP request method and convert the JSON request body to structure if not HTTP GET method. HTTP GET method must be use query parameter.

Notes for HTTP GET method:

- Query parameter and structure field will be compared in case sensitive.

- Every structure field data type must be string, so You must convert it to the right data type before You use it.

- Untested for array query argument (Please use this function with caution).

func HttpErrorCode

func HttpErrorCode(libvirtErrorNumber libvirt.ErrorNumber) int

Convert the Libvirt Error Number to HTTP Status Code

func JsonResponseBuilder

func JsonResponseBuilder[Response ResponseStructure](response Response, httpResponseWriter http.ResponseWriter, httpStatusCode int)

Create JSON response with HTTP header [Content-Type: application/json].

func NewConnect

func NewConnect(uri string) (virest.Connection, virest.Error, bool)

This function should be called first to get a connection to the Hypervisor and xen store.

If name is NULL, if the LIBVIRT_DEFAULT_URI environment variable is set, then it will be used. Otherwise if the client configuration file has the "uri_default" parameter set, then it will be used. Finally probing will be done to determine a suitable default driver to activate. This involves trying each hypervisor in turn until one successfully opens.

If connecting to an unprivileged hypervisor driver which requires the libvirtd daemon to be active, it will automatically be launched if not already running. This can be prevented by setting the environment variable LIBVIRT_AUTOSTART=0

URIs are documented at https://libvirt.org/uri.html

Close() should be used to release the resources after the connection is no longer needed.

func NewConnectReadOnly

func NewConnectReadOnly(uri string) (virest.Connection, virest.Error, bool)

This function should be called first to get a restricted connection to the library functionalities. The set of APIs usable are then restricted on the available methods to control the domains.

See https://pkg.go.dev/github.com/Hari-Kiri/virest-storage-pool/modules/utils#NewConnect or https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen for notes about environment variables which can have an effect on opening drivers and freeing the connection resources

URIs are documented at https://libvirt.org/uri.html

func NewConnectWithAuth

func NewConnectWithAuth(uri string, auth *libvirt.ConnectAuth, flags libvirt.ConnectFlags) (virest.Connection, virest.Error, bool)

This function should be called first to get a connection to the Hypervisor. If necessary, authentication will be performed fetching credentials via the callback

See https://pkg.go.dev/github.com/Hari-Kiri/virest-storage-pool/modules/utils#NewConnect or https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen for notes about environment variables which can have an effect on opening drivers and freeing the connection resources

URIs are documented at https://libvirt.org/uri.html

func NewConnectWithAuthDefault

func NewConnectWithAuthDefault(uri string, flags libvirt.ConnectFlags) (virest.Connection, virest.Error, bool)

This function should be called first to get a connection to the Hypervisor. If necessary, authentication will be performed fetching credentials via the callback

See https://pkg.go.dev/github.com/Hari-Kiri/virest-storage-pool/modules/utils#NewConnect or https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen for notes about environment variables which can have an effect on opening drivers and freeing the connection resources

URIs are documented at https://libvirt.org/uri.html

func NoContentResponseBuilder

func NoContentResponseBuilder(httpResponseWriter http.ResponseWriter)

Create http response with no content (HTTP code 204).

func StringToUint added in v0.1.22

func StringToUint(stringNumber string) (uint, virest.Error, bool)

Convert string to uint. The uint is an unsigned integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, uint32.

func StringToUint32 added in v0.1.22

func StringToUint32(stringNumber string) (uint32, virest.Error, bool)

Convert string to uint. The uint32 is the set of all unsigned 32-bit integers. Range: 0 through 4294967295.

func StringToUint64 added in v0.1.22

func StringToUint64(stringNumber string) (uint64, virest.Error, bool)

Convert string to uint. The uint64 is the set of all unsigned 64-bit integers. Range: 0 through 18446744073709551615.

Types

Directories

Path Synopsis
structures

Jump to

Keyboard shortcuts

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