pkg

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 0 Imported by: 0

README

Pkg

Go Reference Go Report Card Taylor Swift Volkswagen License

pkg is a collection of Go packages that make the life of a Go developers at ZEISS easier.

Installation

go get github.com/zeiss/pkg

Go 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.

There is the typical case of pointers you need to deference. For example in the strict interfaces generated by oapi-codegen.


Somestruct {
  Field: cast.Ptr(req.Field),
}

Or the other way around, you have a pointer and you want to get the value or a default value.


SomeStruct {
  Field: cast.Value(req.Field),
}

Return a default value of a nil pointer.


func Value[T any](val *T) T {
	if val == nil {
		return Zero[T]()
	}

	return *val
}

There are also more complex tools like the Database interface which enables to easliy implement database wrappers.

// Database provides methods for transactional operations.
type Database[R, W any] interface {
	// ReadTx starts a read only transaction.
	ReadTx(context.Context, func(context.Context, R) error) error
	// ReadWriteTx starts a read write transaction.
	ReadWriteTx(context.Context, func(context.Context, W) error) error

	Migrator
	io.Closer
}

Or a simple interface to implement servers. This takes for all signal and context handling.


s, _ := server.WithContext(ctx)
s.Listen(&srv{}, true)

serverErr := &server.ServerError{}
if err := s.Wait(); errors.As(err, &serverErr) {
  log.Print(err)
	os.Exit(1)
}

License

MIT

Documentation

Overview

Package pkg provides a set of utilities for working with slices in Go.

The package gets extended over time with more utilities. Compatibility should be guaranteed within the last two minor versions.

Directories

Path Synopsis
Package async provides a simple way to run functions asynchronously.
Package async provides a simple way to run functions asynchronously.
A simple package to cast between types.
A simple package to cast between types.
A package channels is a package that contains the channels implementation of the application.
A package channels is a package that contains the channels implementation of the application.
cmd
helm/update command
Packag conv provides functions for converting between different types.
Packag conv provides functions for converting between different types.
A package to help with errors.
A package to help with errors.
examples
async command
server command
Package jsonx provides additional functionality for encoding and decoding JSON.
Package jsonx provides additional functionality for encoding and decoding JSON.
Package mapx provides a set of utilities for working with maps in Go.
Package mapx provides a set of utilities for working with maps in Go.
A package server is a package that contains the server implementation of the application.
A package server is a package that contains the server implementation of the application.
A package to operate on slices.
A package to operate on slices.
Package stringx provides string manipulation functions.
Package stringx provides string manipulation functions.
Package syncx provides some useful synchronization primitives.
Package syncx provides some useful synchronization primitives.
Package ulid provides a Universally Unique Lexicographically Sortable Identifier (ULID) implementation in Go.
Package ulid provides a Universally Unique Lexicographically Sortable Identifier (ULID) implementation in Go.
Package utilx provides additional utility functions.
Package utilx provides additional utility functions.

Jump to

Keyboard shortcuts

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