{"id":26658100,"url":"https://github.com/skit-ai/vcore","last_synced_at":"2025-07-02T16:39:04.304Z","repository":{"id":37092247,"uuid":"202731916","full_name":"skit-ai/vcore","owner":"skit-ai","description":"Common, utility packages for Go","archived":false,"fork":false,"pushed_at":"2024-06-14T10:34:01.000Z","size":318,"stargazers_count":21,"open_issues_count":7,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-25T09:18:01.744Z","etag":null,"topics":["errors","go","golang","log","orm"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skit-ai.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-16T13:25:07.000Z","updated_at":"2024-07-05T07:04:48.000Z","dependencies_parsed_at":"2024-05-22T12:28:41.007Z","dependency_job_id":"6b13191b-c9d5-4881-9664-2341bbb131aa","html_url":"https://github.com/skit-ai/vcore","commit_stats":null,"previous_names":["vernacular-ai/vcore"],"tags_count":69,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skit-ai%2Fvcore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skit-ai%2Fvcore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skit-ai%2Fvcore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skit-ai%2Fvcore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skit-ai","download_url":"https://codeload.github.com/skit-ai/vcore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248404374,"owners_count":21097722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["errors","go","golang","log","orm"],"created_at":"2025-03-25T09:18:09.259Z","updated_at":"2025-04-11T13:07:52.450Z","avatar_url":"https://github.com/skit-ai.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vcore\n\nGolang Common utility functions\n\n## vcore/errors\n\nThe errors package is a wrapper around the brilliant [pkg/errors](https://github.com/pkg/errors) library.\nThe major difference between [pkg/errors](https://github.com/pkg/errors) and this library is support for the following:\n\n* Wrapping of an error into a custom error so as to add a stacktrace.\n* Allows creation of errors with a stack which have no cause(nil cause).\n* Every error created supports the `fatality` interface which is meant to inform us if the error is fatal or not.\n* Every error created supports the `tagged` interface which returns any tags(`map[string]string`) associated with an error.\n* The stacktrace of the error will return the stactrace starting from the deepest cause.\n\n### Basic Usage\n\n#### Create Error without cause:\n\nThis error is non-fatal. As marked by the last bool flag.\n\n```go\nerrors.NewError(\"Error without a cause\", nil, false)\n```\n\n#### Create Error with a cause:\n\n```go\ncause := errors.NewError(\"Error without a cause\", nil, false)\nerrWithCause := errors.NewError(\"Error with a cause\", cause, false)\n```\n\n#### Check if an error is fatal\n\n```go\ncause := errors.NewError(\"Error without a cause\", nil, false)\nif cause.Fatal{\n    fmt.Println(\"This error is fatal.\")\n}\n```\n\n#### Get the stacktrace of the error and print it:\n\n```go\ncause := errors.NewError(\"Error without a cause\", nil, false)\nerrWithCause := errors.NewError(\"Error with a cause\", cause, false)\nfmt.Println(errWithCause.Stacktrace())\n```\n\nAlternatively,\n\n```go\ncause := errors.NewError(\"Error without a cause\", nil, false)\nerrWithCause := errors.NewError(\"Error with a cause\", cause, false)\nerrWithCause.PrintStackTrace()\n```\n\n## vcore/crypto\n\nThe crypto module is meant to help services implement various cryptographic functions with ease.\nCurrent features include -\n\n1. Encryption of []byte and string. Supported techniques -\n    - AES-256-GCM\n2. Decryption of []byte. Supported techniques -\n    - AES-256-GCM\n\nAES-256 is PCI DSS compliant, as it is a recognised industry standard encryption.\n\nThis module exports the following functions -\n1. EncryptBytes: Encrypt a bytearray. Example usage -\n``` go\nx := []byte(\"hello world\")\nenc := EncryptBytes(x)\nfmt.Println(enc)\n```\n2. EncryptString: Encrypt a string. Example usage -\n``` go\nx := \"hello world\"\nenc := EncryptString(x)\nfmt.Println(enc)\n```\n3. DecryptBytes: Decrypt a bytearray. Example usage -\n``` go\ny := []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}\np := DecryptBytes(y)\nfmt.Println(string(p))\n```\n\n### Key management\n\nVault 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.\nVcore then calls Vault APIs to decrypt the data key and proceed with the encryption/decryption.\n\n### Environment Variables needed\n\nThe following environment variables are needed to utilize the crypto module -\n``` sh\nexport VAULT_URI=\"http://localhost:8200\"\nexport VAULT_ROLE_ID=\"****\"\nexport VAULT_SECRET_ID=\"****\"\nexport VAULT_APPROLE_MOUNTPATH=\"approle\"\nexport ENCRYPTED_DATA_KEY=\"****\"\nexport VAULT_DATA_KEY_NAME=\"datakey-name\"\n```\n\nNote: the above environment variables are just examples, set up vault and replace the actual values above.\n\n## vcore/log\n\nThe log package is a basic wrapper on the standard log package  in Go's stdlib.\nThe log package logs to STDOUT and supports log levels(`int`).\n\nThe log levels currently supported are:\n\n* 0 - ERROR\n* 1 - WARN\n* 2 - INFO\n* 3 - DEBUG\n* 4 - TRACE\n\nTo log using this package, one needs to use an instance of the `log.Logger` struct.\n\nThe `log.Logger` struct supports the following methods which can be used to log messages:\n\n* `log.Trace(args ...interface{})`\n* `log.Tracef(format string, args ...interface{})`\n* `log.Debug(args ...interface{})`\n* `log.Debugf(format string, args ...interface{})`\n* `log.Info(args ...interface{})`\n* `log.Infof(format string, args ...interface{})`\n* `log.Warn(args ...interface{})`\n* `log.Warnf(format string, args ...interface{})`\n* `log.Error(err error, args ...interface{})`\n* `log.Errorf(err error, format string, args ...interface{})`\n\nEach of these methods are wrappers that correspond to a log level. This enforces the user to take cognizance of the log \nlevel of whatever they are attempting to log.\n\nTo set the log level on a `log.Logger` struct, make use of the `log.SetLevel(level int)` function.\n\n### Default Logger\n\nTo quickly start logging messages, make use of the default logger(default level `WARN`). This can be done by simply \ncalling the functions stated above.\n\nEg. To add a trace log\n\n```go\nheaders := make(map[string]string)\nfor k := range req.Header {\n    headers[strings.ToLower(k)] = req.Header.Get(k)\n}\nlog.SetLevel(log.DEBUG)\nlog.Tracef(\"Headers: %s\", headers)\n```\n\nHere, 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.\n\n### Custom Logger\n\n```go\ncustomLogger := log.Logger{log.DEBUG}\ncustomLogger.Debug(\"This is a debug message\")\n```\n\n## vcore/events\n\n### Sending Cost Tracker Event\n\nFirst export `AWS_CREDENTIALS`\n\n```sh\nexport AWS_ACCESS_KEY_ID=AKID\nexport AWS_SECRET_ACCESS_KEY=SECRET\nexport AWS_REGION=us-east-1\n```\n\nThen use events package from the lib\n```go\nimport (\n    \"github.com/Vernacular-ai/vcore/events\"\n)\n\n// If you don't want to export AWS_CREDENTIALS or already have them under different name, call\n// `SetAWSCredentials` while initializing the module\nerr = events.SetAWSCredentials(awsAccessKey, awsSecretKey, awsRegion)\n\n// send the actual cost event\nevents.SendCostEvent(\n    events.NewCostEvent(events.ASR, events.GOOGLE, \"client-uuid\", \"flow-uuid\", \"call-uuid\", \"conv-uuid\")\n)\n\n// if you want to count a single event with multiple hits\nevents.SendCostEvent(\n    events.NewCostEventWithNumHits(events.ASR, events.GOOGLE, \"client-uuid\", \"flow-uuid\", \"call-uuid\", \"conv-uuid\", 2)\n)\n```\n\n\n## vcore/transport\n\n### vcore/transport/amqp\n### vcore/transport/redis\n\n## vcore/utils\n\nThe vcore/utils package contains basic utility functions and file utilities for downloading, reading and writing to files.\n\n## vcore/vorm","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskit-ai%2Fvcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskit-ai%2Fvcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskit-ai%2Fvcore/lists"}