utils

package
v0.0.0-...-5f17d81 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIfPathExist

func CheckIfPathExist(path string) bool

func CheckIfServiceIsInstalled

func CheckIfServiceIsInstalled(serv string) (bool, error)

func CheckIndexExists

func CheckIndexExists(url string) (bool, error)

CheckIndexExists checks if the given OpenSearch index exists by sending an HTTP GET request to the provided URL. It returns true if the index exists, false otherwise.

func CheckIndexExistsWithRetry

func CheckIndexExistsWithRetry(url string) (bool, error)

retrying every 5 seconds up to a total duration of 1 minute.

func CreatePathIfNotExist

func CreatePathIfNotExist(path string) error

func DoReq

func DoReq[response any](url string, data []byte, method string, headers map[string]string, transCfg *http.Transport) (response, int, error)

DoReq sends an HTTP request and processes the response.

This function sends an HTTP request to the specified URL with the given method, data, and headers. It returns the response body unmarshalled into the specified response type, the HTTP status code, and an error if any occurred during the process.

Type Parameters:

  • response: The type into which the response body will be unmarshalled.

Parameters:

  • url: The URL to which the request is sent.
  • data: The request payload as a byte slice.
  • method: The HTTP method to use for the request (e.g., "GET", "POST").
  • headers: A map of headers to include in the request.

Returns:

  • response: The response body unmarshalled into the specified type.
  • int: The HTTP status code of the response.
  • error: An error if any occurred during the request or response processing, otherwise nil.

func Download

func Download(url, file string) error

Download downloads the content from the specified URL and saves it to the specified file. It returns an error if any error occurs during the process.

Parameters:

  • url: The URL from which to download the content.
  • file: The path to the file where the content should be saved.

Returns:

  • error: An error object if an error occurs, otherwise nil.

func GenerateCerts

func GenerateCerts(folder string) error

func GenerateConfig

func GenerateConfig(variables any, text, output string) error

GenerateConfig generates a configuration file from a text template.

The `variables` argument is a map of variables to be used in the template. The `text` argument is the text of the template. The `output` argument is the path to the output file.

The function returns an error if there is any problem generating the configuration file.

func GenerateSecret

func GenerateSecret(size int) string

func GetLock

func GetLock(v int, locksDir string) bool

func GetMainIP

func GetMainIP() (string, error)

func GetMainIPInAirGapMode

func GetMainIPInAirGapMode() (string, error)

func GetMainIface

func GetMainIface(mainIP string) (string, error)

func GetMyPath

func GetMyPath() string

func GetStep

func GetStep() int

func MakeDir

func MakeDir(mode os.FileMode, arg ...string) string

func Mode

func Mode(mode string, options map[string]any) any

func ParseTemplate

func ParseTemplate(text string, data any) (*bytes.Buffer, error)

ParseTemplate parses a template and executes it with the given data.

text: The text of the template. data: The data to use to render the template.

Returns: A bytes.Buffer containing the rendered template, or an error if parsing or execution failed.

func PointerOf

func PointerOf[t any](s t) *t

func ReadJson

func ReadJson(fileName string, data any) error

func ReadYAML

func ReadYAML(path string, result any) error

func Remove

func Remove(path string) error

func RestartService

func RestartService(name string) error

func RunCmd

func RunCmd(command string, arg ...string) error

func RunCmdWithOutput

func RunCmdWithOutput(command string, arg ...string) ([]string, error)

func RunEnvCmd

func RunEnvCmd(env []string, command string, arg ...string) error

func SetLock

func SetLock(v int, locksDir string) error

func StopService

func StopService(name string) error

func UninstallService

func UninstallService(name string) error

func WriteJSON

func WriteJSON(path string, data any) error

func WriteToFile

func WriteToFile(fileName string, body string) error

func WriteYAML

func WriteYAML(url string, data any) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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