{"id":20294466,"url":"https://github.com/katallaxie/pkg","last_synced_at":"2025-04-11T11:43:19.540Z","repository":{"id":55157922,"uuid":"520847614","full_name":"katallaxie/pkg","owner":"katallaxie","description":"🛠️ My personal collection of Go primitives","archived":false,"fork":false,"pushed_at":"2025-04-08T04:54:25.000Z","size":1596,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T05:29:53.350Z","etag":null,"topics":["go","golang","tools","toolset"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/katallaxie/pkg","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/katallaxie.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":"2022-08-03T11:10:03.000Z","updated_at":"2025-04-08T04:54:27.000Z","dependencies_parsed_at":"2024-01-05T09:30:48.545Z","dependency_job_id":"b6b74184-db64-49ba-8a08-0736c48b2744","html_url":"https://github.com/katallaxie/pkg","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katallaxie%2Fpkg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katallaxie%2Fpkg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katallaxie%2Fpkg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katallaxie%2Fpkg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/katallaxie","download_url":"https://codeload.github.com/katallaxie/pkg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248386275,"owners_count":21095043,"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":["go","golang","tools","toolset"],"created_at":"2024-11-14T15:29:19.406Z","updated_at":"2025-04-11T11:43:19.532Z","avatar_url":"https://github.com/katallaxie.png","language":"Go","readme":"# Pkg\n\n[![Test \u0026 Lint](https://github.com/katallaxie/pkg/actions/workflows/main.yml/badge.svg)](https://github.com/katallaxie/pkg/actions/workflows/main.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/katallaxie/pkg.svg)](https://pkg.go.dev/github.com/katallaxie/pkg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/katallaxie/pkg)](https://goreportcard.com/report/github.com/katallaxie/pkg)\n[![Taylor Swift](https://img.shields.io/badge/secured%20by-taylor%20swift-brightgreen.svg)](https://twitter.com/SwiftOnSecurity)\n[![Volkswagen](https://auchenberg.github.io/volkswagen/volkswargen_ci.svg?v=1)](https://github.com/auchenberg/volkswagen)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n`pkg` is a collection of Go packages that make the life of a Gopher easier.\n\n[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/katallaxie/pkg?quickstart=1)\n\n## Installation\n\n```bash\ngo get github.com/katallaxie/pkg\n```\n\nGo has a pretty good standard library, but there are some things that are missing. This collection of small packages is meant to fill those gaps.\n\n## Casting values\n\nThere is the typical case of pointers you need to deference. For example in the strict interfaces generated by [oapi-codegen](https://github.com/oapi-codegen/oapi-codegen).\n\n```go\n\nSomestruct {\n  Field: cast.Ptr(req.Field),\n}\n\n```\n\nOr the other way around, you have a pointer and you want to get the value or a default value.\n\n```go\n\nSomeStruct {\n  Field: cast.Value(req.Field),\n}\n\n```\n\nReturn a default value of a `nil` pointer.\n\n```go\ntype Foo struct {}\ncast.Zero(Foo) // \u0026Foo{}\n```\n\n## Converting values\n\nThere is also always the case to covert a value to a specific other value.\n\n```go\n// String converts a value to a string.\nb := true\ns := cast.String(b)\n\nfmt.Println(s) // \"true\"\n```\n\nThere are functions to convert `int`, `string` and `bool` values.\n\n## Operators \n\nThere is the implementation of various operators.\n\n```go\n// Is the ternary operator.\nutilx.IfElse(cond, 100, 0)\n```\n\n## Optional\n\nThere is also the `Option` type which is a wrapper around a value that can be `nil`.\n\n```go\n// Option is a wrapper around a value that can be nil.\na := optional.Some(100)\nfmt.Println(a.String()) // true\n```\n\n## Redux-inspired state management\n\nThis is a simple state management inspired by [Redux](https://redux.js.org/).\n\n```go\n// NoopState is a simple state of a store.\ntype NoopState struct {\n\tName string `json:\"name\"`\n}\n\naction := redux.NewAction(1, \"foo\")\n\nstate := NoopState{Name: \"foo\"}\nstore := redux.NewStore(State, action)\n\nstore.Dispatch(action)\nupdates := store.Subscribe()\n\n```\n\n## Databases\n\nThere are also more complex tools like the `Database` interface which enables to easliy implement database wrappers.\n\n```go\n// Database provides methods for transactional operations.\ntype Database[R, W any] interface {\n\t// ReadTx starts a read only transaction.\n\tReadTx(context.Context, func(context.Context, R) error) error\n\t// ReadWriteTx starts a read write transaction.\n\tReadWriteTx(context.Context, func(context.Context, W) error) error\n\n\tMigrator\n\tio.Closer\n}\n```\n\nOr a simple interface to implement servers. This takes for all `signal` and `context` handling.\n\n```go\n\ns, _ := server.WithContext(ctx)\ns.Listen(\u0026srv{}, true)\n\nserverErr := \u0026server.ServerError{}\nif err := s.Wait(); errors.As(err, \u0026serverErr) {\n  log.Print(err)\n\tos.Exit(1)\n}\n```\n\n## FGA with OpenFGA\n\nThere is also a package to work with the OpenFGA API.\n\n```go\n// Store is an interface that provides methods for transactional operations on the authz database.\ntype Store[Tx any] interface {\n\t// Allowed checks if the user is allowed to perform the operation on the object.\n\tAllowed(context.Context, User, Object, Relation) (bool, error)\n\t// WriteTx starts a read write transaction.\n\tWriteTx(context.Context, func(context.Context, Tx) error) error\n}\n\n// StoreTx is an interface that provides methods for transactional operations on the authz database.\ntype StoreTx interface {\n\t// WriteTuple writes a tuple to the authz database.\n\tWriteTuple(context.Context, User, Object, Relation) error\n\t// DeleteTuple deletes a tuple from the authz database.\n\tDeleteTuple(context.Context, User, Object, Relation) error\n}\n```\n\nThis can be used with the package.\n\n```go\nauthzStore, err := authx.NewStore(fgaClient, authz.NewWriteTx())\nif err != nil {\n  return err\n}\n```\n\n## License\n\n[MIT](/LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatallaxie%2Fpkg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatallaxie%2Fpkg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatallaxie%2Fpkg/lists"}