项目作者: danielgatis

项目描述 :
A Variadic helper to mimic named arguments
高级语言: Go
项目地址: git://github.com/danielgatis/go-keyval.git
创建时间: 2020-01-06T03:02:50Z
项目社区:https://github.com/danielgatis/go-keyval

开源协议:MIT License

下载


go-keyval

Go Report Card
License MIT
Go Doc

A Variadic helper to mimic named arguments.

Install

  1. go get -u github.com/danielgatis/go-keyval

And then import the package in your code:

  1. import "github.com/danielgatis/go-keyval"

Example

An example described below is one of the use cases.

  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/danielgatis/go-keyval"
  6. )
  7. func main() {
  8. now := time.Now().UTC()
  9. email := "johndoe@gmail.com"
  10. query := "select * from users where email = :email and created_at < :created_at"
  11. execNamed(query, "email", email, "created_at", now)
  12. }
  13. func execNamed(query string, args... interface{}) {
  14. m := keyval.ToMap(args...)
  15. fmt.Printf("%s", m["email"])
  16. fmt.Printf("%s", m["created_at"])
  17. // db stuff here ...
  18. }

License

Copyright (c) 2020-present Daniel Gatis

Licensed under MIT License