All Projects → skit-ai → vcore

skit-ai / vcore

Licence: Apache-2.0 license
Common, utility packages for Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to vcore

kubelogs
Interactively dump logs from multiple Kubernetes containers.
Stars: ✭ 15 (-6.25%)
Mutual labels:  log
log-utils
Basic logging utils: colors, symbols and timestamp.
Stars: ✭ 24 (+50%)
Mutual labels:  log
aixlog
Header-only C++ logging library
Stars: ✭ 95 (+493.75%)
Mutual labels:  log
traffic analyser
Retrieve useful information from apache/nginx access logs to help troubleshoot traffic related problems
Stars: ✭ 44 (+175%)
Mutual labels:  log
guzzle-log-middleware
A Guzzle middleware to log request and responses automatically
Stars: ✭ 61 (+281.25%)
Mutual labels:  log
deeperror
Very informative, enlightening and pleasantly formatted errors for Go
Stars: ✭ 18 (+12.5%)
Mutual labels:  errors
addon-log-viewer
Log Viewer - Home Assistant Community Add-ons
Stars: ✭ 37 (+131.25%)
Mutual labels:  log
react-native-log-ios
React Native iOS standalone logger
Stars: ✭ 37 (+131.25%)
Mutual labels:  log
errorlocate
Find and replace erroneous fields in data using validation rules
Stars: ✭ 19 (+18.75%)
Mutual labels:  errors
eth-rpc-errors
Ethereum RPC Errors
Stars: ✭ 78 (+387.5%)
Mutual labels:  errors
SpringBoot-Examples
Spring boot 2.X version tutorial,Integrate various middleware to facilitate quick reference and use
Stars: ✭ 23 (+43.75%)
Mutual labels:  log
ELog
ELog----日志打印工具,带定位功能
Stars: ✭ 17 (+6.25%)
Mutual labels:  log
error-pages
🚧 Pretty server's error pages in the docker image & git repository
Stars: ✭ 296 (+1750%)
Mutual labels:  errors
easybuggy4django
EasyBuggy clone built on Django
Stars: ✭ 44 (+175%)
Mutual labels:  errors
webpack-log
A logger for the Webpack ecosystem
Stars: ✭ 18 (+12.5%)
Mutual labels:  log
GoogleCloudLogging
Swift (Darwin) library for logging application events in Google Cloud.
Stars: ✭ 24 (+50%)
Mutual labels:  log
ArgCheck.jl
Package for checking function arguments
Stars: ✭ 73 (+356.25%)
Mutual labels:  errors
Analogy.LogViewer
A customizable Log Viewer with ability to create custom providers. Can be used with C#, C++, Python, Java and others
Stars: ✭ 172 (+975%)
Mutual labels:  log
magento2-inventory-log
Magento 2 - Inventory Log by KiwiCommerce
Stars: ✭ 33 (+106.25%)
Mutual labels:  log
log
PSR-3 compatible logger
Stars: ✭ 32 (+100%)
Mutual labels:  log

vcore

Golang Common utility functions

vcore/errors

The errors package is a wrapper around the brilliant pkg/errors library. The major difference between pkg/errors and this library is support for the following:

  • Wrapping of an error into a custom error so as to add a stacktrace.
  • Allows creation of errors with a stack which have no cause(nil cause).
  • Every error created supports the fatality interface which is meant to inform us if the error is fatal or not.
  • Every error created supports the tagged interface which returns any tags(map[string]string) associated with an error.
  • The stacktrace of the error will return the stactrace starting from the deepest cause.

Basic Usage

Create Error without cause:

This error is non-fatal. As marked by the last bool flag.

errors.NewError("Error without a cause", nil, false)

Create Error with a cause:

cause := errors.NewError("Error without a cause", nil, false)
errWithCause := errors.NewError("Error with a cause", cause, false)

Check if an error is fatal

cause := errors.NewError("Error without a cause", nil, false)
if cause.Fatal{
    fmt.Println("This error is fatal.")
}

Get the stacktrace of the error and print it:

cause := errors.NewError("Error without a cause", nil, false)
errWithCause := errors.NewError("Error with a cause", cause, false)
fmt.Println(errWithCause.Stacktrace())

Alternatively,

cause := errors.NewError("Error without a cause", nil, false)
errWithCause := errors.NewError("Error with a cause", cause, false)
errWithCause.PrintStackTrace()

vcore/crypto

The crypto module is meant to help services implement various cryptographic functions with ease. Current features include -

  1. Encryption of []byte and string. Supported techniques -
    • AES-256-GCM
  2. Decryption of []byte. Supported techniques -
    • AES-256-GCM

AES-256 is PCI DSS compliant, as it is a recognised industry standard encryption.

This module exports the following functions -

  1. EncryptBytes: Encrypt a bytearray. Example usage -
x := []byte("hello world")
enc := EncryptBytes(x)
fmt.Println(enc)
  1. EncryptString: Encrypt a string. Example usage -
x := "hello world"
enc := EncryptString(x)
fmt.Println(enc)
  1. DecryptBytes: Decrypt a bytearray. Example usage -
y := []byte{180, 27, 0, 28, 249, 65, 157, 217, 78, 134, 227, 25, 135, 180, 197, 2, 170, 235, 128, 7, 99, 202, 202, 210, 149, 75, 209, 157, 114, 129, 236, 206, 62, 132, 175, 42, 26, 224, 26}
p := DecryptBytes(y)
fmt.Println(string(p))

Key management

Vault is used to generate the encrypted data key when an environment/client is set up. The encrypted data key is passed to vcore as an environment variable. Vcore then calls Vault APIs to decrypt the data key and proceed with the encryption/decryption.

Environment Variables needed

The following environment variables are needed to utilize the crypto module -

export VAULT_URI="http://localhost:8200"
export VAULT_ROLE_ID="****"
export VAULT_SECRET_ID="****"
export VAULT_APPROLE_MOUNTPATH="approle"
export ENCRYPTED_DATA_KEY="****"
export VAULT_DATA_KEY_NAME="datakey-name"

Note: the above environment variables are just examples, set up vault and replace the actual values above.

vcore/log

The log package is a basic wrapper on the standard log package in Go's stdlib. The log package logs to STDOUT and supports log levels(int).

The log levels currently supported are:

  • 0 - ERROR
  • 1 - WARN
  • 2 - INFO
  • 3 - DEBUG
  • 4 - TRACE

To log using this package, one needs to use an instance of the log.Logger struct.

The log.Logger struct supports the following methods which can be used to log messages:

  • log.Trace(args ...interface{})
  • log.Tracef(format string, args ...interface{})
  • log.Debug(args ...interface{})
  • log.Debugf(format string, args ...interface{})
  • log.Info(args ...interface{})
  • log.Infof(format string, args ...interface{})
  • log.Warn(args ...interface{})
  • log.Warnf(format string, args ...interface{})
  • log.Error(err error, args ...interface{})
  • log.Errorf(err error, format string, args ...interface{})

Each of these methods are wrappers that correspond to a log level. This enforces the user to take cognizance of the log level of whatever they are attempting to log.

To set the log level on a log.Logger struct, make use of the log.SetLevel(level int) function.

Default Logger

To quickly start logging messages, make use of the default logger(default level WARN). This can be done by simply calling the functions stated above.

Eg. To add a trace log

headers := make(map[string]string)
for k := range req.Header {
    headers[strings.ToLower(k)] = req.Header.Get(k)
}
log.SetLevel(log.DEBUG)
log.Tracef("Headers: %s", headers)

Here, we directly make use of the default logger. Please note, since the log level is set to DEBUG here, this trace message will not be logged.

Custom Logger

customLogger := log.Logger{log.DEBUG}
customLogger.Debug("This is a debug message")

vcore/transport

vcore/transport/amqp

vcore/transport/redis

vcore/utils

The vcore/utils package contains basic utility functions and file utilies for downloading, reading and writing to files.

vcore/vorm

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].