gf_core

package
v0.0.0-...-37756be Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: GPL-2.0 Imports: 50 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GitCommitSHAstr = "GF_COMMIT_SHA"

Functions

func BreadcrumbsAdd(pCategoryStr string,
	pMsgStr string,
	pDataMap map[string]interface{},
	pLocalHub *sentry.Hub)

func CastToStr

func CastToStr(pElement interface{}) (bool, string)

func ConfigGetArg

func ConfigGetArg(pArgNameStr string, pCmd *cobra.Command) string

func CryptoConvertKeysToPEM

func CryptoConvertKeysToPEM(pPrivateKey *rsa.PrivateKey,
	pPublicKey *rsa.PublicKey) (string, string)

func CryptoConvertPubKeyToPEM

func CryptoConvertPubKeyToPEM(pPublicKey *rsa.PublicKey) string

func CryptoGenerateKeys

func CryptoGenerateKeys() (*rsa.PublicKey, *rsa.PrivateKey)

generate RSA private/public keys (4096 bit)

func CryptoGenerateKeysAsPEM

func CryptoGenerateKeysAsPEM() (string, string)

generate new RSA private/public key-pair (4096 bit) and encoded it into the PEM format and return as two separate strings.

func EncodeJSONfromData

func EncodeJSONfromData(pInput interface{}) []byte

func ErrorInitSentry

func ErrorInitSentry(pSentryEndpointStr string,
	pTransactionsTracingRateMap map[string]float64,
	pSampleRateDefaultF float64) error

func GetTokenShorthand

func GetTokenShorthand(pTokenStr string) string

func HTTPdeleteCookieOnResp

func HTTPdeleteCookieOnResp(pCookieNameStr string,
	pResp http.ResponseWriter)

func HTTPdisableCachingOfResponse

func HTTPdisableCachingOfResponse(pResp http.ResponseWriter)

func HTTPfetchURL

func HTTPfetchURL(pURLstr string,
	pHeadersMap map[string]string,
	pUserAgentStr string,
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) (*GF_http_fetch, *GFerror)

func HTTPgetAllCookies

func HTTPgetAllCookies(pReq *http.Request) map[string]interface{}

func HTTPgetCookieFromReq

func HTTPgetCookieFromReq(pCookieNameStr string,
	pReq *http.Request,
	pRuntimeSys *RuntimeSys) (bool, string)

func HTTPgetReqConfig

func HTTPgetReqConfig() (map[string]string, string)

func HTTPinitStaticServing

func HTTPinitStaticServing(pURLbaseStr string,
	pRuntimeSys *RuntimeSys)

func HTTPinitStaticServingWithMux

func HTTPinitStaticServingWithMux(pURLbaseStr string,
	p_local_dir_path_str string,
	p_mux *http.ServeMux,
	pRuntimeSys *RuntimeSys)

func HTTPserializeCookies

func HTTPserializeCookies(pCookiesLst []*http.Cookie,
	pRuntimeSys *RuntimeSys) string

func HTTPserveFile

func HTTPserveFile(pLocalDirStr string,
	pURLstr string,
	pReq *http.Request,
	pResp http.ResponseWriter,
	pRuntimeSys *RuntimeSys)

func HTTPsetCookieOnReq

func HTTPsetCookieOnReq(pCookieNameStr string,
	pDataStr string,
	pReq *http.Request,
	pTTLhoursInt int)

func HTTPsetCookieOnResp

func HTTPsetCookieOnResp(pCookieNameStr string,
	pDataStr string,
	pResp http.ResponseWriter,
	pTTLhoursInt int)

func HashValSha256

func HashValSha256(pVal interface{}) string

func ListContainsStr

func ListContainsStr(pStr string, pLst []string) bool

func ListPop

func ListPop[T any](pLst []T) (T, []T)

func ListRemoveElementAtIndex

func ListRemoveElementAtIndex(pLst []interface{}, pIndex int) []interface{}

func LogsIsDebugEnabled

func LogsIsDebugEnabled() bool

func MapHasKey

func MapHasKey[K string, V any](pMap map[K]V, pKeyStr string) bool

func MongoStart

func MongoStart(p_mongodb_bin_path_str string,
	p_mongodb_port_str int,
	p_mongodb_data_dir_path_str string,
	p_mongodb_log_file_path_str string,
	p_sudo_bool bool,
	pLogFun func(string, string)) error

func PanicCheckAndHandle

func PanicCheckAndHandle(pUserMsgStr string,
	pPanicDataMap map[string]interface{},
	pOnCompleteFun func(),
	pSubsystemNameStr string,
	pRuntimeSys *RuntimeSys)

func StrRandom

func StrRandom() string

func ValidateInit

func ValidateInit() *validator.Validate

Types

type ErrorDef

type ErrorDef struct {
	DescrStr string
}

type ExternalPlugins

type ExternalPlugins struct {

	//---------------------------
	// RPC_HANDLERS
	RPChandlersGetCallback func(*RuntimeSys) ([]HTTPhandlerInfo, *GFerror)

	//---------------------------
	// IMAGES
	ImageFilterMetadataCallback func(map[string]interface{}) map[string]interface{}

	//---------------------------
	// EVENTS
	EventCallback func(string, map[string]interface{}, *RuntimeSys) *GFerror

	//---------------------------
	// SECRETS
	SecretCreateCallback func(string, map[string]interface{}, string, *RuntimeSys) *GFerror
	SecretGetCallback    func(string, *RuntimeSys) (map[string]interface{}, *GFerror)

	// called on every sending of email in the system
	EmailSendingCallback func(string, string, string, string, *RuntimeSys) *GFerror

	//---------------------------
	// NFT
	// get metadata on defined fetchers
	NFTgetFetchersMetaCallback func() map[string]map[string]interface{}

	// fetch NFTs for a particular owner account using a particular fetcher (with name)
	NFTfetchForOwnerAddressCallback func(string, string, *RuntimeSys) *GFerror
}

type GF_ID

type GF_ID string

func IDcreate

func IDcreate(pUniqueValsForIDlst []string,
	pUNIXtimeF float64) GF_ID

type GF_http_fetch

type GF_http_fetch = Gf_http_fetch

type GFcliCmdInfo

type GFcliCmdInfo struct {
	CmdLst         []string
	StdinDataStr   *string // data to be passed via stdin
	EnvVarsMap     map[string]string
	DirStr         string
	ViewOutputBool bool
}

type GFerror

type GFerror struct {
	Id                   bson.ObjectId          `bson:"_id,omitempty"`
	Id_str               string                 `bson:"id_str"`
	T_str                string                 `bson:"t"` // "gf_error"
	Creation_unix_time_f float64                `bson:"creation_unix_time_f"`
	Type_str             string                 `bson:"type_str"`
	User_msg_str         string                 `bson:"user_msg_str"`
	Data_map             map[string]interface{} `bson:"data_map"`
	Descr_str            string                 `bson:"descr_str"`
	Error                error                  `bson:"error"`
	ServiceNameStr       string                 `bson:"service_name_str"`
	Subsystem_name_str   string                 `bson:"subsystem_name_str"` // major portion of functionality, a particular package, or a logical group of functions
	Stack_trace_str      string                 `bson:"stack_trace_str"`
	Function_name_str    string                 `bson:"func_name_str"`
	File_str             string                 `bson:"file_str"`
	Line_num_int         int                    `bson:"line_num_int"`
}

func CLIprompt

func CLIprompt(pMsgStr string, pRuntimeSys *RuntimeSys) (bool, *GFerror)

prompt the user for a confirmation to proceed or not

func CLIpyRun

func CLIpyRun(pPyPathStr string,
	pArgsLst []string,
	pInputStdinStr *string,
	pEnvMap map[string]string,
	pStdoutPrefixStr string,
	pRuntimeSys *RuntimeSys) ([]map[string]interface{}, *GFerror)

func CLIrun

func CLIrun(pCmdInfo *GFcliCmdInfo,
	pRuntimeSys *RuntimeSys) ([]string, []string, *GFerror)

func CLIrunCore

func CLIrunCore(pCmdInfo *GFcliCmdInfo,
	pWaitForCompletionBool bool,
	pRuntimeSys *RuntimeSys) (chan string, chan string, *GFerror)

func CLIrunStandard

func CLIrunStandard(pCmdLst []string,
	pEnvVarsMap map[string]string,
	pRuntimeSys *RuntimeSys) ([]string, []string, *GFerror)

func CryptoParseKeysFromPEM

func CryptoParseKeysFromPEM(pPublicKeyPEMstr string,
	pPrivateKeyPEMstr string,
	pRuntimeSys *RuntimeSys) (*rsa.PublicKey, *rsa.PrivateKey, *GFerror)

parse a private key from a PEM string

func DBsqlConnect

func DBsqlConnect(pDBnameStr string,
	pUserNameStr string,
	pPassStr string,
	pDBhostStr string,
	pRuntimeSys *RuntimeSys) (*sql.DB, *GFerror)

func DBsqlViewTableStructure

func DBsqlViewTableStructure(pTableNameStr string,
	pRuntimeSys *RuntimeSys) *GFerror

func Elastic__get_client

func Elastic__get_client(p_es_host_str string, pRuntimeSys *RuntimeSys) (*elastic.Client, *GFerror)

func ErrorCreate

func ErrorCreate(pUserMsgStr string,
	pErrorTypeStr string,
	pErrorDataMap map[string]interface{},
	pError error,
	pSubsystemNameStr string,
	pRuntimeSys *RuntimeSys) *GFerror

func ErrorCreateWithDefs

func ErrorCreateWithDefs(pUserMsgStr string,
	pErrorTypeStr string,
	pErrorDataMap map[string]interface{},
	pError error,
	pSubsystemNameStr string,
	pErrDefsMap map[string]ErrorDef,

	pSkipStackFramesNumInt int,

	pRuntimeSys *RuntimeSys) *GFerror

func ErrorCreateWithHook

func ErrorCreateWithHook(pUserMsgStr string,
	pErrorTypeStr string,
	pErrorDataMap map[string]interface{},
	pError error,
	pSubsystemNameStr string,
	pSkipStackFramesNumInt int,
	p_hook_fun func(*GFerror) map[string]interface{},
	pRuntimeSys *RuntimeSys) *GFerror

func ErrorCreateWithStackSkip

func ErrorCreateWithStackSkip(pUserMsgStr string,
	pErrorTypeStr string,
	pErrorDataMap map[string]interface{},
	pError error,
	pSubsystemNameStr string,
	pSkipStackFramesNumInt int,
	pRuntimeSys *RuntimeSys) *GFerror

func FileCopy

func FileCopy(pSourceFileLocalPathStr string,
	pTargetFileLocalPathStr string,
	pRuntimeSys *RuntimeSys) *GFerror

func FileCreateWithContent

func FileCreateWithContent(pContentStr string,
	pFilePathStr string,
	pRuntimeSys *RuntimeSys) *GFerror

func FileRead

func FileRead(pLocalFilePathStr string,
	pRuntimeSys *RuntimeSys) (string, *GFerror)

func FileReadBytes

func FileReadBytes(pLocalFilePathStr string,
	pRuntimeSys *RuntimeSys) ([]byte, *GFerror)

func HTTPdetectMIMEtypeFromURL

func HTTPdetectMIMEtypeFromURL(pURLstr string,
	pHeadersMap map[string]string,
	pUserAgentStr string,
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) (string, *GFerror)

func HTTPgetFile

func HTTPgetFile(pTargetURLstr string,
	pFileLocalPathStr string,
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) *GFerror

func HTTPgetInput

func HTTPgetInput(pReq *http.Request,
	pRuntimeSys *RuntimeSys) (map[string]interface{}, *GFerror)

func HTTPgetStreamingResponse

func HTTPgetStreamingResponse(pURLstr string,
	pRuntimeSys *RuntimeSys) (*[]map[string]interface{}, *GFerror)

func HTTPinitSSE

func HTTPinitSSE(pResp http.ResponseWriter,
	pRuntimeSys *RuntimeSys) (http.Flusher, *GFerror)

func HTTPputFile

func HTTPputFile(pTargetURLstr string,
	pFilePathStr string,
	pHeadersMap map[string]string,
	pRuntimeSys *RuntimeSys) (*http.Response, *GFerror)

func IPFSinit

func IPFSinit(pIPFSnodeHostStr string,
	pRuntimeSys *RuntimeSys) (*ipfs.Shell, *GFerror)

func MongoCollExists

func MongoCollExists(pCollNameStr string,
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) (bool, *GFerror)

func MongoConnectNew

func MongoConnectNew(pMongoServerURLstr string,
	pDBnameStr string,
	pTLScustomConfig *tls.Config,
	pRuntimeSys *RuntimeSys) (*mongo.Database, *mongo.Client, *GFerror)

func MongoCount

func MongoCount(pQuery bson.M,
	pMetaMap map[string]interface{},
	pColl *mongo.Collection,
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) (int64, *GFerror)

func MongoDelete

func MongoDelete(pQuery bson.M,
	pCollNameStr string,
	pMetaMap map[string]interface{},
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) *GFerror

func MongoEnsureIndex

func MongoEnsureIndex(pIndexesKeysLst [][]string,
	pIndexesNamesLst []string,
	pCollNameStr string,
	pRuntimeSys *RuntimeSys) *GFerror

func MongoFind

func MongoFind(pQuery bson.M,
	pOpts *options.FindOptions,
	pMetaMap map[string]interface{},
	pColl *mongo.Collection,
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) (*mongo.Cursor, *GFerror)

func MongoFindLatest

func MongoFindLatest(pQuery bson.M,
	pTimeFieldNameStr string,
	pMetaMap map[string]interface{},
	pColl *mongo.Collection,
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) (map[string]interface{}, *GFerror)

func MongoHandleError

func MongoHandleError(p_user_msg_str string,
	p_error_type_str string,
	p_error_data_map map[string]interface{},
	p_error error,
	p_subsystem_name_str string,
	pRuntimeSys *RuntimeSys) *GFerror

func MongoInsert

func MongoInsert(p_record interface{},
	pCollNameStr string,
	pMetaMap map[string]interface{},
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) *GFerror

func MongoTXinit

func MongoTXinit(pMongoClient *mongo.Client,
	pMetaMap map[string]interface{},
	pRuntimeSys *RuntimeSys) (mongo.Session, *options.TransactionOptions, *GFerror)

func MongoTXrun

func MongoTXrun(pTXfun func() *GFerror,
	pMetaMap map[string]interface{},
	pMongoClient *mongo.Client,
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) (mongo.Session, *GFerror)

func MongoUpsert

func MongoUpsert(pQuery bson.M,
	pRecord interface{},
	pMetaMap map[string]interface{},
	pColl *mongo.Collection,
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) *GFerror

func MongoUpsertBulk

func MongoUpsertBulk(pFilterDocsByFieldsLst []map[string]string,
	pRecordsLst []interface{},
	pCollNameStr string,
	pMetaMap map[string]interface{},
	pCtx context.Context,
	pRuntimeSys *RuntimeSys) (int64, *GFerror)

func ParseJSONfromByteList

func ParseJSONfromByteList(pBytesLst []byte,
	pRuntimeSys *RuntimeSys) (map[string]interface{}, *GFerror)

func ParseJSONfromString

func ParseJSONfromString(pJSONstr string,
	pRuntimeSys *RuntimeSys) (interface{}, *GFerror)

func TemplatesLoad

func TemplatesLoad(pMainTemplateFilepathStr string,
	pRuntimeSys *RuntimeSys) (*template.Template, []string, *GFerror)

func ValidateStruct

func ValidateStruct(pTarget interface{},
	pRuntimeSys *RuntimeSys) *GFerror

type GFlogFun

type GFlogFun func(string, string, map[string]interface{})

func LogsInit

func LogsInit() (func(string, string), GFlogFun)

func LogsInitNew

func LogsInitNew(pLogrusBool bool, pLogLevelStr string) (func(string, string), GFlogFun)

pLogLevelStr - allows for explicit programmatic setting of log_level.

if this is set to "" then the ENV var is checked.
if this is also not set then the default "info" level is used.

type GFmetrics

type GFmetrics struct {

	// ERRORS_COUNTER - number of GF errors that were thrown
	ErrorsCounter prometheus.Counter
}

func MetricsInit

func MetricsInit(p_metrics_endpoint_str string,
	pPortInt int) *GFmetrics

type Gf_elasticsearch_retrier

type Gf_elasticsearch_retrier struct {
	// contains filtered or unexported fields
}

func (*Gf_elasticsearch_retrier) Retry

func (p_retrier *Gf_elasticsearch_retrier) Retry(p_ctx context.Context,
	p_retry_int int,
	p_req *http.Request,
	p_resp *http.Response,
	p_err error) (time.Duration, bool, error)

type Gf_http_fetch

type Gf_http_fetch struct {
	Url_str          string            `bson:"url_str"`
	Status_code_int  int               `bson:"status_code_int"`
	Resp_headers_map map[string]string `bson:"resp_headers_map"`
	Req_time_f       float64           `bson:"req_time_f"`
	Resp_time_f      float64           `bson:"resp_time_f"`
	Resp             *http.Response    `bson:"-"`
}

type HTTPfetch

type HTTPfetch = GF_http_fetch

---------------------------------------------------

type HTTPhandler

type HTTPhandler func(context.Context, http.ResponseWriter, *http.Request) (map[string]interface{}, *GFerror)

type HTTPhandlerInfo

type HTTPhandlerInfo struct {
	AuthBool   bool
	PathStr    string
	HandlerFun HTTPhandler
}

type RuntimeSys

type RuntimeSys struct {
	ServiceNameStr string
	EnvStr         string
	Debug_bool     bool // if debug mode is enabled (some places will print extra info in debug mode)
	LogFun         func(string, string)
	LogNewFun      GFlogFun

	// DB
	SQLdb      *sql.DB
	Mongo_db   *mongo.Database
	Mongo_coll *mongo.Collection // main mongodb collection to use when none is specified

	// ERRORS
	Errors_send_to_mongodb_bool bool // if errors should be persisted to Mongodb
	ErrorsSendToSentryBool      bool // if errors should be sent to Sentry service

	NamesPrefixStr string

	Validator *validator.Validate

	// PLUGINS
	ExternalPlugins *ExternalPlugins

	Metrics *GFmetrics

	// HTTP_PROXY
	// if a http proxy should be use this value is set
	// "http://proxy:8888"
	HTTPproxyServerURIstr string

	// SENTRY - used to pass the DNS to py sentry clients.
	SentryDSNstr string
}

type SysReleaseInfo

type SysReleaseInfo struct {
	Name_str        string
	Version_str     string
	Description_str string
	Git_commit_str  string // indicates this is usually pasted in by CI systems
}

func GetSysReleseInfo

func GetSysReleseInfo(pRuntimeSys *RuntimeSys) SysReleaseInfo

Jump to

Keyboard shortcuts

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