Skip to content

utils

import "github.com/atropos112/gocore/utils"

Index

func ArrContains

func ArrContains[T constraints.Ordered](arr []T, obj T) bool

ArrContains checks if an array contains obj

func ArrContainsArr

func ArrContainsArr[T constraints.Ordered](arr []T, subArr []T) bool

ArrContainsArr checks if an array contains all elements of another array

func GetCred

func GetCred(value string) (string, error)

GetCred is a function that gets a credential from the environment variables. If the credential is not found, it will return an error.

func GetCredUnsafe

func GetCredUnsafe(value string) string

GetCredUnsafe is a function that gets a credential from the environment variables. If the credential is not found, it will log a fatal error.

func MakeAPIRequest

func MakeAPIRequest(client *http.Client, kind, apiBaseURL, endpoint, token string, request, response interface{}) error

MakeAPIRequest is a generic function to make an API request. It supports GET, POST, PUT, and DELETE requests.

func MakeDeleteRequest

func MakeDeleteRequest(client *http.Client, apiBaseURL, endpoint, token string, response interface{}) error

MakeDeleteRequest is a helper function to make a DELETE request to the specified endpoint. If token is not "" it will be added to the request as a Bearer token.

func MakeGetRequest

func MakeGetRequest(client *http.Client, apiBaseURL, endpoint, token string, response interface{}) error

MakeGetRequest is a helper function to make a GET request to the specified endpoint. If token is not "" it will be added to the request as a Bearer token.

func MakePostRequest

func MakePostRequest(client *http.Client, apiBaseURL, endpoint, token string, request, response interface{}) error

MakePostRequest is a helper function to make a POST request to the specified endpoint. If token is not "" it will be added to the request as a Bearer token.

func MakePutRequest

func MakePutRequest(client *http.Client, apiBaseURL, endpoint, token string, request, response interface{}) error

MakePutRequest is a helper function to make a PUT request to the specified endpoint. If token is not "" it will be added to the request as a Bearer token.

func RunAPIServer

func RunAPIServer(port int) error

RunAPIServer attaches logging middleware to the default http server and starts it on the specified port.

type APIError

APIError is an error type that is returned when an API request fails.

type APIError struct {
    StatusCode int
    Message    string
}

func (*APIError) Error

func (e *APIError) Error() string

type AuthenticatedAPIClient

AuthenticatedAPIClient is a struct that contains the base URL of the API and the token to use for requests.

type AuthenticatedAPIClient struct {
    BaseURL string
    Token   string
    Client  *http.Client
}

func NewAPIClient

func NewAPIClient(baseURL, token string) AuthenticatedAPIClient

NewAPIClient creates a new AuthenticatedAPIClient with the specified base URL and token.

func (*AuthenticatedAPIClient) Delete

func (c *AuthenticatedAPIClient) Delete(endpoint string, response interface{}) error

Delete is a helper function to make a DELETE request to the specified endpoint. If token is not "" it will be added to the request as a Bearer token.

func (*AuthenticatedAPIClient) Get

func (c *AuthenticatedAPIClient) Get(endpoint string, response interface{}) error

Get is a helper function to make a GET request to the specified endpoint. If token is not "" it will be added to the request as a Bearer token.

func (*AuthenticatedAPIClient) Post

func (c *AuthenticatedAPIClient) Post(endpoint string, request, response interface{}) error

Post is a helper function to make a POST request to the specified endpoint. If token is not "" it will be added to the request as a Bearer token.

func (*AuthenticatedAPIClient) Put

func (c *AuthenticatedAPIClient) Put(endpoint string, request, response interface{}) error

Put is a helper function to make a PUT request to the specified endpoint. If token is not "" it will be added to the request as a Bearer token.

type DeveloperError

DeveloperError represents an error that is caused by a developer mistake

type DeveloperError struct {
    Message string
}

func (*DeveloperError) Error

func (e *DeveloperError) Error() string

type GPTDoesntListenError

GPTDoesntListenError represents an error when GPT doesn't listen

type GPTDoesntListenError struct {
    UserMessage string
    SysMessage  string
}

func (*GPTDoesntListenError) Error

func (e *GPTDoesntListenError) Error() string

type NoCredFoundError

NoCredFoundError represents an error when no credentials are found

type NoCredFoundError struct {
    CredentialName string
}

func (*NoCredFoundError) Error

func (e *NoCredFoundError) Error() string

Generated by gomarkdoc