From 4fc95b0d691f40578766638d54409ad17f15f6d7 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 19 Jul 2017 00:52:27 +0800 Subject: [PATCH] gofmt and golint --- controller.go | 1 + grace/conn.go | 4 +-- migration/ddl.go | 1 + migration/doc.go | 71 ++++++++++++++++++---------------------- validation/util.go | 6 ++-- validation/validators.go | 12 +++---- 6 files changed, 44 insertions(+), 51 deletions(-) diff --git a/controller.go b/controller.go index da8e8504..c104eb2a 100644 --- a/controller.go +++ b/controller.go @@ -55,6 +55,7 @@ type ControllerComments struct { MethodParams []*param.MethodParam } +// ControllerCommentsSlice implements the sort interface type ControllerCommentsSlice []ControllerComments func (p ControllerCommentsSlice) Len() int { return len(p) } diff --git a/grace/conn.go b/grace/conn.go index 6f52045f..e020f850 100644 --- a/grace/conn.go +++ b/grace/conn.go @@ -9,7 +9,7 @@ import ( type graceConn struct { net.Conn server *Server - m sync.Mutex + m sync.Mutex closed bool } @@ -26,7 +26,7 @@ func (c *graceConn) Close() (err error) { } } }() - + c.m.Lock() if c.closed { c.m.Unlock() diff --git a/migration/ddl.go b/migration/ddl.go index 01cee196..cea10355 100644 --- a/migration/ddl.go +++ b/migration/ddl.go @@ -71,6 +71,7 @@ func (m *Migration) CreateTable(tablename, engine, charset string, p ...func()) m.ModifyType = "create" } +// AlterTable set the ModifyType to alter func (m *Migration) AlterTable(tablename string) { m.TableName = tablename m.ModifyType = "alter" diff --git a/migration/doc.go b/migration/doc.go index 2d6ccaf6..0c6564d4 100644 --- a/migration/doc.go +++ b/migration/doc.go @@ -1,41 +1,32 @@ -/* Package migration enables you to generate migrations back and forth. It generates both migrations. - - -//Creates a table -m.CreateTable("tablename","InnoDB","utf8"); - - - -//Alter a table -m.AlterTable("tablename") - - - -//Standard Column Methods -* SetDataType -* SetNullable -* SetDefault -* SetUnsigned (use only on integer types unless produces error) - - -//Sets a primary column, multiple calls allowed, standard column methods available -m.PriCol("id").SetAuto(true).SetNullable(false).SetDataType("INT(10)").SetUnsigned(true) - -//UniCol Can be used multiple times, allows standard Column methods. Use same "index" string to add to same index -m.UniCol("index","column") - -//Standard Column Initialisation, can call .Remove() after NewCol("") on alter to remove -m.NewCol("name").SetDataType("VARCHAR(255) COLLATE utf8_unicode_ci").SetNullable(false) -m.NewCol("value").SetDataType("DOUBLE(8,2)").SetNullable(false) - -//Rename Columns , only use with Alter table, doesn't works with Create, prefix standard column methods with "Old" to -//create a true reversible migration eg: SetOldDataType("DOUBLE(12,3)") -m.RenameColumn("from","to")... - - -//Foreign Columns, single columns are only supported, SetOnDelete & SetOnUpdate are available, call appropriately. -//Supports standard column methods, automatic reverse. -m.ForeignCol("local_col","foreign_col","foreign_table") - -*/ +// Package migration enables you to generate migrations back and forth. It generates both migrations. +// +// //Creates a table +// m.CreateTable("tablename","InnoDB","utf8"); +// +// //Alter a table +// m.AlterTable("tablename") +// +// Standard Column Methods +// * SetDataType +// * SetNullable +// * SetDefault +// * SetUnsigned (use only on integer types unless produces error) +// +// //Sets a primary column, multiple calls allowed, standard column methods available +// m.PriCol("id").SetAuto(true).SetNullable(false).SetDataType("INT(10)").SetUnsigned(true) +// +// //UniCol Can be used multiple times, allows standard Column methods. Use same "index" string to add to same index +// m.UniCol("index","column") +// +// //Standard Column Initialisation, can call .Remove() after NewCol("") on alter to remove +// m.NewCol("name").SetDataType("VARCHAR(255) COLLATE utf8_unicode_ci").SetNullable(false) +// m.NewCol("value").SetDataType("DOUBLE(8,2)").SetNullable(false) +// +// //Rename Columns , only use with Alter table, doesn't works with Create, prefix standard column methods with "Old" to +// //create a true reversible migration eg: SetOldDataType("DOUBLE(12,3)") +// m.RenameColumn("from","to")... +// +// //Foreign Columns, single columns are only supported, SetOnDelete & SetOnUpdate are available, call appropriately. +// //Supports standard column methods, automatic reverse. +// m.ForeignCol("local_col","foreign_col","foreign_table") package migration diff --git a/validation/util.go b/validation/util.go index 4695b776..66fce283 100644 --- a/validation/util.go +++ b/validation/util.go @@ -45,8 +45,8 @@ var ( "Valid": true, "NoMatch": true, } - - Int64On32Err = fmt.Errorf("not support int64 on 32-bit platform") + // ErrInt64On32 show 32 bit platform not support int64 + ErrInt64On32 = fmt.Errorf("not support int64 on 32-bit platform") ) func init() { @@ -255,7 +255,7 @@ func parseParam(t reflect.Type, s string) (i interface{}, err error) { i, err = strconv.Atoi(s) case reflect.Int64: if wordsize == 32 { - return nil, Int64On32Err + return nil, ErrInt64On32 } i, err = strconv.ParseInt(s, 10, 64) case reflect.Int32: diff --git a/validation/validators.go b/validation/validators.go index a9c3e6b8..4dff9c0b 100644 --- a/validation/validators.go +++ b/validation/validators.go @@ -25,12 +25,12 @@ import ( // CanSkipFuncs will skip valid if RequiredFirst is true and the struct field's value is empty var CanSkipFuncs = map[string]struct{}{ - "Email": struct{}{}, - "IP": struct{}{}, - "Mobile": struct{}{}, - "Tel": struct{}{}, - "Phone": struct{}{}, - "ZipCode": struct{}{}, + "Email": {}, + "IP": {}, + "Mobile": {}, + "Tel": {}, + "Phone": {}, + "ZipCode": {}, } // MessageTmpls store commond validate template