keyval

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 1 Imported by: 1

README

go-keyval

A Variadic helper to mimic named arguments.

Go Report Card License MIT Go Doc Release

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToMap

func ToMap(keyvals ...interface{}) map[string]interface{}

ToMap returns a map by grouping arguments two by two where the first is the key and the second is the value

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL