Skip to content

harukasan/bindform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

bindform

Godoc Build Status

Because bindform is aimed to only binding data, it does not cover data validations (only type checking). You should validate data after (or before) data binding.

Usage

go get -u github.com/harukasan/bindform/bindform
package main

import (
    "net/http"
    "github.com/harukasan/bindform/bindform"

type ContactForm struct {
  Name    string `form:"name"`
  Email   string `form:"email"`
  Message string `form:"message"`
}

func HandlePostContactForm(w http.ResponseWriter, r *http.Request) {
	form := &ContactForm{}

	err := bindform.BindPostForm(r, form)
	if err != nil {
		http.Error(w, "Bad Request", 400)
	}

  // Debug print
  // log.Println(form)

  // needs more validations ...
}

Supported types

  • bool
  • int
  • uint
  • float
  • string

TODO

  • Supports array type
  • Supports require tag

LICENSE

Copyright (c) 2015, MICHII Shunsuke.

See License

About

Post data binding into Go struct.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages