autobindings

command module
v0.0.0-...-9c1e54f Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2017 License: MIT Imports: 11 Imported by: 0

README

Autobindings

Autobindings is a simple extention to the amazing library Binding. So binding is a reflectionless data binding for Go's net/http. For that developer has to write a FieldMap function which is used by this library to map the incoming JSON from the request to the struct fields.

What autobinding does ?

So it automatically creates FieldMap function for your struct.

How to use ?

Just add this line to all of your files which has struct and for which you want to create a FieldMap function

//go:generate autobindings -file <file_name>

Or

From command line just run

autobindings -file <file_name>

Or

If you don't want to create the automatic files, then use -print flag to just print the function associated with your struct on the console

autobindings -file <file_name> -print

Example

$ ./generator -file testfile.go -print
package main

/*
This is an autogenerated file by autobindings
*/

import (
  "github.com/mholt/binding"
)

func (i Item) FieldMap() binding.FieldMap {
  return binding.FieldMap{
    &i.A: "A",
    &i.B: "B",
  }
}

How to install ?

go install github.com/rainingclouds/autobindings

How does it happens ?

Using the power of go generate :) It creates <struct_name>_bindings.go for every struct in the given file. This file contains FieldMap function for that struct. This function is used by Binding library to perform the mapping.

Okay so what is missing ?

  • It doesn't support Embedded fields yet.

Happy to help

akshay@rainingclouds.com @akshay_deo

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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