Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielgatis/go-keyval
A Variadic helper to mimic named arguments.
https://github.com/danielgatis/go-keyval
go golang named-arguments varargs variadic
Last synced: 11 days ago
JSON representation
A Variadic helper to mimic named arguments.
- Host: GitHub
- URL: https://github.com/danielgatis/go-keyval
- Owner: danielgatis
- License: mit
- Created: 2020-01-06T03:02:50.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-26T04:34:16.000Z (over 4 years ago)
- Last Synced: 2024-10-28T19:55:19.106Z (about 2 months ago)
- Topics: go, golang, named-arguments, varargs, variadic
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-keyval
[![Go Report Card](https://goreportcard.com/badge/github.com/danielgatis/go-keyval?style=flat-square)](https://goreportcard.com/report/github.com/danielgatis/go-keyval)
[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/danielgatis/go-keyval/master/LICENSE)
[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/danielgatis/go-keyval)A Variadic helper to mimic named arguments.
## Install
```bash
go get -u github.com/danielgatis/go-keyval
```And then import the package in your code:
```go
import "github.com/danielgatis/go-keyval"
```### Example
An example described below is one of the use cases.
```go
package mainimport (
"fmt"
"time""github.com/danielgatis/go-keyval"
)func main() {
now := time.Now().UTC()
email := "[email protected]"
query := "select * from users where email = :email and created_at < :created_at"execNamed(query, "email", email, "created_at", now)
}func execNamed(query string, args... interface{}) {
m := keyval.ToMap(args...)
fmt.Printf("%s", m["email"])
fmt.Printf("%s", m["created_at"])// db stuff here ...
}
```## License
Copyright (c) 2020-present [Daniel Gatis](https://github.com/danielgatis)
Licensed under [MIT License](./LICENSE)