A Variadic helper to mimic named arguments.
go get -u github.com/danielgatis/go-keyval
And then import the package in your code:
import "github.com/danielgatis/go-keyval"
An example described below is one of the use cases.
package main
import (
"fmt"
"time"
"github.com/danielgatis/go-keyval"
)
func main() {
now := time.Now().UTC()
email := "johndoe@gmail.com"
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 ...
}
Copyright (c) 2020-present Daniel Gatis
Licensed under MIT License