Giter Site home page Giter Site logo

autobindings's Introduction

Autobindings

Join the chat at https://gitter.im/rainingclouds/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

[email protected] @akshay_deo

autobindings's People

Contributors

aniketawati avatar gitter-badger avatar tlianza avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.