Skip to content

danielgatis/go-keyval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-keyval

Go Report Card License MIT Go Doc

A Variadic helper to mimic named arguments.

Install

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

And then import the package in your code:

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

Example

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

License

Copyright (c) 2020-present Daniel Gatis

Licensed under MIT License

About

A Variadic helper to mimic named arguments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages