Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some functions in the client/lxd.go file were missing the documentation headings #11913

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions client/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func (r *ProtocolLXD) GetConnectionInfo() (*ConnectionInfo, error) {
return &info, nil
}

// isSameServer compares the calling ProtocolLXD object with the provided server object to check if they are the same server.
// It verifies the equality based on their connection information (Protocol, Certificate, Project, and Target).
func (r *ProtocolLXD) isSameServer(server Server) bool {
// Short path checking if the two structs are identical.
if r == server {
Expand Down Expand Up @@ -243,6 +245,8 @@ func lxdParseResponse(resp *http.Response) (*api.Response, string, error) {
return &response, etag, nil
}

// rawQuery is a method that sends an HTTP request to the LXD server with the provided method, URL, data, and ETag.
// It processes the request based on the data's type and handles the HTTP response, returning parsed results or an error if it occurs.
func (r *ProtocolLXD) rawQuery(method string, url string, data any, ETag string) (*api.Response, string, error) {
var req *http.Request
var err error
Expand Down Expand Up @@ -356,6 +360,8 @@ func (r *ProtocolLXD) query(method string, path string, data any, ETag string) (
return r.rawQuery(method, url, data, ETag)
}

// queryStruct sends a query to the LXD server, then converts the response metadata into the specified target struct.
// The function logs the retrieved data, returns the etag of the response, and handles any errors during this process.
func (r *ProtocolLXD) queryStruct(method string, path string, data any, ETag string, target any) (string, error) {
resp, etag, err := r.query(method, path, data, ETag)
if err != nil {
Expand All @@ -374,6 +380,8 @@ func (r *ProtocolLXD) queryStruct(method string, path string, data any, ETag str
return etag, nil
}

// queryOperation sends a query to the LXD server and then converts the response metadata into an Operation object.
// It sets up an early event listener, performs the query, processes the response, and manages the lifecycle of the event listener.
func (r *ProtocolLXD) queryOperation(method string, path string, data any, ETag string) (Operation, string, error) {
// Attempt to setup an early event listener
listener, err := r.GetEvents()
Expand Down Expand Up @@ -416,6 +424,8 @@ func (r *ProtocolLXD) queryOperation(method string, path string, data any, ETag
return &op, etag, nil
}

// rawWebsocket creates a websocket connection to the provided URL using the underlying HTTP transport of the ProtocolLXD receiver.
// It sets up the request headers, manages the connection handshake, sets TCP timeouts, and handles any errors that may occur during these operations.
func (r *ProtocolLXD) rawWebsocket(url string) (*websocket.Conn, error) {
// Grab the http transport handler
httpTransport, err := r.getUnderlyingHTTPTransport()
Expand Down Expand Up @@ -461,6 +471,8 @@ func (r *ProtocolLXD) rawWebsocket(url string) (*websocket.Conn, error) {
return conn, nil
}

// websocket generates a websocket URL based on the provided path and the base URL of the ProtocolLXD receiver.
// It then leverages the rawWebsocket method to establish and return a websocket connection to the generated URL.
func (r *ProtocolLXD) websocket(path string) (*websocket.Conn, error) {
// Generate the URL
var url string
Expand Down