utils

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendCorsRoute added in v0.7.0

func AppendCorsRoute(r *router.Router, method string, route string, handler egoTypes.FHRequestHandler, noOptionsRoute bool)

AppendRoute adds a route with CORS headers.

func EnsureDir added in v0.7.0

func EnsureDir(dirPath string) (string, error)

EnsureDir checks if a directory exists at the given path. If it doesn't exist, it creates a directory with the given path. The function returns the directory path and an error, if any.

func ExecuteCommand

func ExecuteCommand(rawCommand string) (*exec.Cmd, error)

ExecuteCommand creates a new exec.Cmd instance and starts a new process with the provided raw command using the shell specified by GetShellName(). The command output is printed to stdout and stderr, and the command is run with os.Stdin. It returns the cmd object and an error if one occurs.

func GetAndCheckInput

func GetAndCheckInput(args []string, openEditor bool) string

GetAndCheckInput retrieves user input from the command line using the GetInput function and panics if an error occurs. It trims the whitespace from the input and panics if the input is empty.

func GetApiAccessType added in v0.7.0

func GetApiAccessType() (string, error)

GetApiAccessType returns the type of API access to be used. It checks if OpenAI API Key is provided in environment variable OPENAI_API_KEY, if not, it checks if Chat API Client ID is provided in environment variable CHAT_API_CLIENT_ID. If Chat API Client ID is provided, it further checks if Chat API URL and Key are provided. If Chat API URL and Key are provided, it returns "proxy_api_key". If Chat API URL and Key are not provided, it gets the access token using GetAccessToken and returns "proxy_oauth2". If none of the above are provided, it returns an empty string and no error.

func GetDefaultAddNoNewLineToChatAnswerSetting added in v0.10.0

func GetDefaultAddNoNewLineToChatAnswerSetting() bool

GetDefaultAddNoNewLineToChatAnswerSetting gets the default value for the setting, NOT adding a new line to each answer of a chat to STDOUT

func GetEnvFilePath added in v0.2.0

func GetEnvFilePath() (string, error)

GetEnvFilePath returns the path to the .env file located in the user's home directory. If an error occurs while getting the user's home directory, it returns an empty string and the error.

func GetInput

func GetInput(args []string, openEditor bool) (string, error)

GetInput function retrieves user input from the command-line arguments, standard input, or an editor

func GetOperatingSystemName

func GetOperatingSystemName() string

GetOperatingSystemName function returns the name of the operating system running the program

func GetShellName

func GetShellName() string

GetShellName function returns the name of the shell running the program

func GetSystemFilePath added in v0.4.0

func GetSystemFilePath() (string, error)

GetSystemFilePath function returns the path of the .system file used by the program

func GetSystemPrompt added in v0.4.0

func GetSystemPrompt() (string, bool, error)

GetSystemPrompt returns the system prompt message, a boolean value indicating whether the prompt message is custom, and an error if there is any.

func GetUISettingsFilePath added in v0.7.0

func GetUISettingsFilePath() (string, error)

GetUISettingsFilePath returns the file path for the UI settings file and an error if there is any.

func IsTruthy added in v0.10.0

func IsTruthy(val string) bool

IsTruthy checks if a string value is a "truthy" value like: "true", "t", "1", "y", "yes", "yeah", "✅", "👍"

func OpenSQLConnection added in v0.3.0

func OpenSQLConnection(connectionStr string) (*sql.DB, string, error)

OpenSQLConnection opens a connection to a SQL database and returns the database object, the display name of the database provider, and an error, if any.

func RemoveMarkdownCode added in v0.1.1

func RemoveMarkdownCode(str string) string

RemoveMarkdownCode removes the beginning and ending backticks from the given string.

func SendHttpError added in v0.7.0

func SendHttpError(ctx *fasthttp.RequestCtx, err error)

SendHttpError sends an HTTP 500 error with the given error message.

func SetupCorsHeaders added in v0.7.0

func SetupCorsHeaders(ctx *fasthttp.RequestCtx)

SetupCorsHeaders sets the necessary headers to enable CORS on an HTTP response.

func TryGetBestOpenEditorCommand

func TryGetBestOpenEditorCommand(filePath string) (string, []string)

TryGetBestOpenEditorCommand tries to find and return the best command to open a file for editing with the given file path. It returns the command and its arguments as a slice of strings. If no suitable editor is found, it returns an empty string and an empty slice.

func TryGetExecutablePath

func TryGetExecutablePath(command string) string

TryGetExecutablePath tries to find and return the path of the given command executable file. It returns the path as a string. If the executable file is not found, it returns an empty string.

func TryOpen added in v0.5.0

func TryOpen(resource string) error

TryOpen opens the given resource using the appropriate command based on the OS. It returns an error if the command failed to execute.

func WriteStringToStdOut added in v0.9.0

func WriteStringToStdOut(str string, withNewline bool)

func WriteToStdOut added in v0.9.0

func WriteToStdOut(data []byte, withNewline bool)

Types

type OAuth2TokenResponse

type OAuth2TokenResponse struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
	TokenType   string `json:"token_type"`
}

func GetAccessToken

func GetAccessToken() (OAuth2TokenResponse, error)

GetAccessToken retrieves an OAuth2TokenResponse struct, which contains an access token and other authentication details, from an API endpoint. If the response status code is 200, it attempts to parse the response body as JSON and returns the tokenResponse struct. Otherwise, it returns an error containing the response error message.

Jump to

Keyboard shortcuts

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