Skip to content

Instantly share code, notes, and snippets.

@L04DB4L4NC3R
Created December 26, 2019 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L04DB4L4NC3R/04efd6e4659f7aab367523e52b0aa839 to your computer and use it in GitHub Desktop.
Save L04DB4L4NC3R/04efd6e4659f7aab367523e52b0aa839 to your computer and use it in GitHub Desktop.
Clean Arch
package user
import "github.com/jinzhu/gorm"
type User struct {
gorm.Model
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Password string `json:"password,omitempty"`
PhoneNumber string `json:"phone_number,omitempty"`
Email string `json:"email,omitempty"`
Address string `json:"address,omitempty"`
DisplayPic string `json:"display_pic,omitempty"`
}
@rluvaton
Copy link

Isn’t password is implementation specific?
If you wanna use Login with Google you would need to change your entity that need to be independent

Another thing is that the json path or whatever it is (I’m sorry I don’t know Go) is also implementation specific
(entity shouldn’t import libraries, if you want to change your library you would need to change your business core)

@L04DB4L4NC3R
Copy link
Author

Isn’t password is implementation specific?
If you wanna use Login with Google you would need to change your entity that need to be independent

Another thing is that the json path or whatever it is (I’m sorry I don’t know Go) is also implementation specific
(entity shouldn’t import libraries, if you want to change your library you would need to change your business core)

json tag is actually an idiomatic way to represent what the names of the fields will be when this structure is encoded into JSON. It is not a path. Your conjecture about the password field is right, I just store the OAuth access token in the password field when doing Google login, since we have to explicitly serialize them anyway. I would love to know about your approach for the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment