From 1a99c7bd1ee78b0576fc0bd022dcbd34051422e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Poreda?= Date: Thu, 14 Mar 2019 09:32:29 +0100 Subject: [PATCH] Create model_snake.go It would be nice to be able force all models to use snake case on son response. In my projects all api endpoints returns always snake case. Gorm models are the only that are "hard" to do so. --- model_snake.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 model_snake.go diff --git a/model_snake.go b/model_snake.go new file mode 100644 index 00000000..b7822146 --- /dev/null +++ b/model_snake.go @@ -0,0 +1,15 @@ +package gorm + +import "time" + +// Model base model definition, including fields `ID`, `CreatedAt`, `UpdatedAt`, `DeletedAt`, which could be embedded in your models +// type User struct { +// gorm.ModelSC +// } + +type ModelSC struct { + ID uint `gorm:"primary_key" json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt *time.Time `sql:"index" json:"deleted_at"` +}