utils

package
v0.0.0-...-6c125f6 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CPU_CORES_CPUINFO_ERROR            = -2
	LAVG_TREND_CPUINFO_ERROR           = -1
	SUCCEEDED                          = 0
	LAVG_TREND_ERROR                   = 1
	LAVG_TREND_INCREASING              = 2
	LAVG_TREND_NORMAL                  = 3
	FILE_EXT_ERR                       = 4
	FILE_EXT_NOT_PROVIDED              = 5
	FILE_EXT_ASTERISK                  = 6
	FILE_PREFIX_ERR                    = 8
	FILE_PREFIX_ASTERISK               = 9
	DB_CONN_ERR                        = 10
	DB_USERNAME_NOT_PROVIDED           = 11
	DB_NAME_NOT_PROVIDED               = 12
	DB_HOSTNAME_NOT_PROVIDED           = 14
	LAVG_LOAD_LEVEL_YELLOW             = 70
	DEL_FILE_LIST_E_SLEEP              = 60
	GITHUB_WEBHOOK_SERVER_PORT_DEFAULT = 8990
)

Variables

This section is empty.

Functions

func GetFieldTagMap

func GetFieldTagMap(d interface{}, tagIdentifier string) map[string]string

func GetFieldValue

func GetFieldValue(d interface{}, field string) interface{}

func GetTagValueMap

func GetTagValueMap(d interface{}, tagIdentifier string) map[string]string

func Output

func Output(w http.ResponseWriter, jsonData []byte, httpStatus int)

Output - Function to write data to HTTP Writer stream

Types

type ApiRequest

type ApiRequest struct {
	Log                *log.Logger
	Url                string            `json:"url"`
	Data               string            `json:"data"`
	Headers            map[string]string `json:"headers"`
	Async              bool              `json:"async"`
	Timeout            int               `json:"timeout"`
	RequestMethod      string            `json:"request_method"`
	ScheduledTimeStamp int32             `json:"scheduled_time_stamp"`
	DataFormat         string            `json:"data_format"`
	ExtraInformation   string            `json:"extra_information"`
	AmazonTraceId      string            `json:"amzn_trace_id"`
}

func (*ApiRequest) AsyncSend

func (p *ApiRequest) AsyncSend() ApiResponse

func (*ApiRequest) CallApi

func (p *ApiRequest) CallApi(responseResult ApiResponse) ApiResponse

func (*ApiRequest) Send

func (p *ApiRequest) Send() ApiResponse

type ApiResponse

type ApiResponse struct {
	UUID             string     `json:"uuid"`
	TimeTaken        string     `json:"time_taken"`
	ResponseHeaders  string     `json:"response_headers"`
	Response         string     `json:"response"`
	ApiDataExtraInfo string     `json:"extra_information"`
	ApiRequestInfo   ApiRequest `json:"api_request_info"`
}

type CouchbaseConfig

type CouchbaseConfig struct {
	HostName   string // Hostname of the SQL server
	Port       int64  // Port number of the SQL server
	UserName   string // Username part of the SQL server credentials
	Password   string // Password for the a fore-defined UserName
	Bucket     string // bucket to open
	BucketPass string // bucket to open
}

func (*CouchbaseConfig) Connect

func (c *CouchbaseConfig) Connect() (*gocb.Cluster, error)

func (*CouchbaseConfig) String

func (c *CouchbaseConfig) String() string

func (*CouchbaseConfig) URL

func (c *CouchbaseConfig) URL() string

func (*CouchbaseConfig) Values

func (c *CouchbaseConfig) Values(hostName string, port int64, userName, password, bucket, bucketPass string)

type CouchbaseDB

type CouchbaseDB struct {
	Conn    *gocb.Cluster
	ConnErr error
	Conf    *CouchbaseConfig
	Log     *log.Logger
}

func (*CouchbaseDB) Connect

func (c *CouchbaseDB) Connect() error

func (*CouchbaseDB) OpenBucket

func (c *CouchbaseDB) OpenBucket() (*gocb.Bucket, error)

func (*CouchbaseDB) Upsert

func (c *CouchbaseDB) Upsert(key string, value ApiResponse) error

type RDBMS

type RDBMS struct {
	Conn    *sql.DB
	ConnErr error
	Conf    *RDBMSConfig
}

func (*RDBMS) Close

func (d *RDBMS) Close() error

func (*RDBMS) Connect

func (d *RDBMS) Connect() error

func (*RDBMS) ConnectM2

func (d *RDBMS) ConnectM2() error

func (*RDBMS) DropTable

func (d *RDBMS) DropTable(tableName string) error

func (*RDBMS) InsertRow

func (d *RDBMS) InsertRow(table string, insertDataArray map[string]string) int

*

  • @param type string $dbObj
  • @param type string $tablename
  • @param type string insertDataArray
  • @return type int
  • @author Shweta<shweta.agarwal@healthians.com>

func (*RDBMS) SelectRows

func (d *RDBMS) SelectRows(tableName, columns, condition, limit, offset, orderBy string) *sql.Rows

*

  • @param type string $dbObj
  • @param type string $tablename
  • @param type string $columns
  • @param type string $condition
  • @param type integer $limit
  • @param type integer $offset
  • @param type string $order_by
  • @return array
  • @author Shweta <shweta.agarwal@healthians.com>

func (*RDBMS) UpdateRows

func (d *RDBMS) UpdateRows(table string, updateDataArray map[string]string, optionDataArray map[string]string) *sql.Rows

*

  • @param type string $dbObj
  • @param type string $tablename
  • @param type string updateDataArray
  • @param type string optionDataArray
  • @return type rows
  • @author Shweta<shweta.agarwal@healthians.com>

func (*RDBMS) UpdateTable

func (d *RDBMS) UpdateTable(table string, updateDataArray map[string]string, optionDataArray map[string]string) (sql.Result, error)

type RDBMSConfig

type RDBMSConfig struct {
	DriverName      string // Name of the SQL driver viz., mysql, postgres, sqlite etc
	HostName        string // Hostname of the SQL server
	Port            int64  // Port number of the SQL server
	Database        string // Name of the database to connect to on the SQL server
	UserName        string // Username part of the SQL server credentials
	Password        string // Password for the afore-defined UserName
	MaxOpenConns    int    // Maximum number of connections to be opened
	MaxIdleConns    int    // Maximum number of idle connections to be kept
	MaxLifeTimeConn int    // Maximum life of connection (in seconds)
}

func (*RDBMSConfig) Connect

func (c *RDBMSConfig) Connect() (*sql.DB, error)

func (*RDBMSConfig) DSN

func (c *RDBMSConfig) DSN() string

func (*RDBMSConfig) String

func (c *RDBMSConfig) String() string

func (*RDBMSConfig) Values

func (c *RDBMSConfig) Values(driverName, hostName string, port int64, database, restrictedUsers, userName, password string, maxOpenconns, maxIdleConns, maxLifeTimeConn int)

type Utils

type Utils struct {
	Log *log.Logger
}

func NewUtils

func NewUtils(l *log.Logger) *Utils

func (*Utils) CPUCores

func (u *Utils) CPUCores() int32

func (*Utils) CPUInfo

func (u *Utils) CPUInfo() ([]cpu.InfoStat, error)

func (*Utils) DeleteFileByAge

func (u *Utils) DeleteFileByAge(path string, minAgeForDeletion int64) (bool, error)

func (*Utils) DeleteFileList

func (u *Utils) DeleteFileList(fileExtToClean, directoryPath string) int

func (*Utils) DeleteFileListE

func (u *Utils) DeleteFileListE(prefix, fileExtToClean, directoryPath string, maxAge int64, forceNoExt bool) int

func (*Utils) DeleteMessage

func (u *Utils) DeleteMessage(qURL string, svc *sqs.SQS, receiptHandler *string) error

DeleteMessage - Delete a message from queue

func (*Utils) EnqueueSQS

func (u *Utils) EnqueueSQS(arrayDataJSON string, qURL string, dbM2 *RDBMS, dbM2Err error) (int, int)

EnqueueSQS - Add data to queue

func (*Utils) EnqueueSQSBatch

func (u *Utils) EnqueueSQSBatch(arrayDataJSON string, qURL string, dbM2 *RDBMS, dbM2Err error) (int, int)

EnqueueSQSBatch - Add data to queue in batches of 10 messages

func (*Utils) EnqueueSQSImport

func (u *Utils) EnqueueSQSImport(qMsgs []schemas.QueueMessageDatum, qURL string, dbProd *sql.DB, dbM2 *RDBMS, dbM2Err error)

EnqueueSQSImport - Add Slice data to queue

func (*Utils) ExitErrorf

func (u *Utils) ExitErrorf(msg string, args ...interface{})

ExitErrorf - A function to output error and kill the current process returning the control back to the OS.

func (*Utils) FileExists

func (u *Utils) FileExists(path string) bool

func (*Utils) GetAWSSession

func (u *Utils) GetAWSSession() (*session.Session, error)

GetAWSSession - returns an active AWS session for further use with the components of the AWS SDK

and error in case it is not able to create one.

func (*Utils) GetFileList

func (u *Utils) GetFileList(directoryPath string) map[int]string

func (*Utils) GetFileListGlob

func (u *Utils) GetFileListGlob(pattern string) map[int]string

func (*Utils) ImplodeMapIntString

func (u *Utils) ImplodeMapIntString(glue string, pieces map[int]string) string

func (*Utils) ImplodeStringArr

func (u *Utils) ImplodeStringArr(glue string, pieces []string) string

func (*Utils) InsertEmailPool

func (u *Utils) InsertEmailPool(email, subject, content string, dbProd *RDBMS)

InsertEmailPool - insert a row into email_pool

func (*Utils) InsertEnqueueRetry

func (u *Utils) InsertEnqueueRetry(query string, qURL string, dbProd *RDBMS)

InsertEnqueueRetry - A function to insert data into the redrive queue

func (*Utils) LoadAvg

func (u *Utils) LoadAvg() (*load.AvgStat, error)

func (*Utils) LoadAvgCheck

func (u *Utils) LoadAvgCheck() int

func (*Utils) LoadAvgCheckCPUCores

func (u *Utils) LoadAvgCheckCPUCores(cpuCores int32) int

func (*Utils) MicroTime

func (u *Utils) MicroTime() float64

func (*Utils) NewUUID

func (u *Utils) NewUUID() string

func (*Utils) ReceiveMessageSQS

func (u *Utils) ReceiveMessageSQS(sess *session.Session, maxMsgs, qURL string) (*sqs.SQS, *sqs.ReceiveMessageOutput, error)

func (*Utils) RenderTemplate

func (u *Utils) RenderTemplate(res http.ResponseWriter, templateType string, templateName string, data interface{})

RenderTemplate serves HTML template

func (*Utils) SendCurl

func (u *Utils) SendCurl(query string, url string) (result *http.Response)

SendCurl - A function to send a HTTP POST request via golang

func (*Utils) SendEmailAlert

func (u *Utils) SendEmailAlert(emails []string, subject, emailContent string)

func (*Utils) SendRequest

func (u *Utils) SendRequest(p *ApiRequest, myChan chan ApiResponse, result ApiResponse)

func (*Utils) UploadToS3

func (u *Utils) UploadToS3(bucket string, key string, source string) (*s3manager.UploadOutput, error)

UploadToS3 - Function to upload a file to AWS' Simple Storage Service (S3) bucket - string containing the bucket name key - string containing the key under which the data is to be stored source - string containing the path of local file that is to be uploaded Cf. https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/s3-example-basic-bucket-operations.html

Jump to

Keyboard shortcuts

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