Package zen is an utility-first package that provides a set of commonly used functions, helpers and extensions. Most of the functions are adapted to be used with `html/template`. We had too many cases of copy-pasting the same code between projects over and over again. So we decided to combine it all in one place. Library provides basic aggregative functions. Library provides simple arithmetic functions for sets of values: Sum, Sub, Mul, Div. Main point is to provide runtime template functions (which are missing in the built-in `html/template`). See Funcmap section for details. Library provides a way to define and run asynchronous functions. It's based on Go's standard goroutines and channels. Future object holds value channel and error. It's used as an awaitable object. As far as Go is not provides any async/await syntax, your function must to return a Future, provided by Async function. Zen provides a generic atomic wrapper, based on RWMutex. Usually, actions are performed with Get and Set methods. For complex cases (like simultaneous Get and Set), Atomic provides a Context method which allows to pass a function and lock a mutex for the duration of the function. Library provides a comfortable way to work with slices casting ([]any). Library provides a simple helper functions to handle error cases, like Must or Ignore. Library provides an utilities funcmap to be attached to template rendering. See FuncMap variable for details. Zen provides some useful non-standard string formatting functions. Logical expressions from another languages, but missing in Go. Unfortunately, it's not syntax-level feature. That's why you can't use conditional code execution here. Some generic functions for basic slice operations. Library provides a set of wrappers and builder in addition to default net/http package. RequestBuilder is a builder with an ability to chain request definition and execution. You can initialize RequestBuilder with zen.Request function. It allows to set query, headers, body, almost everything in single line of code. Supports both setting values with structs/maps and native values (like url.Values for query). As far as RequestBuilder have an option to return *ResponseWrapper, you can chain both request building and response processing into single line. ResponseWrapper is a wrapper with an ability to chain response processing. You can initialize ResponseWrapper with a zen.Response function. It allows to operate with wrapped response in a more convenient way. Check status code, dump response to stdout for debug, convert body into map or decode directly into value. Almost everything in single line of code. Library provides a number of functions that can be used to transform data into different types and forms. Most of these functions are working with base data types.
go get git.sr.ht/~kyoto-framework/zen