Answer the question
In order to leave comments, you need to log in
How to build application architecture?
Hello everyone
. I am periodically engaged in development, and recently I was asked to make a simple backend for a cafe service. The bottom line is that the page should display dishes with photos.
From the side of the backend, I made the functionality of adding / changing / deleting data from databases and wrote an http wrapper for this. But I don't like the current architecture, namely:
There is a food structure:
type Food struct {
Id int `validate:"required" gorm:"primary_key:true"`
Name string `validate:"required" gorm:"column:name;unique"`
....
}
type Categories struct {
Id int `gorm:"primary_key:true"`
Name string `validate:"required" gorm:"column:name;unique"`
....
}
r.Route("/food/", func (r chi.Router) {
r.Post("/add", AddFood)
r.Post("/update", UpdateFood)
r.Post("/delete", DeleteFood)
})
r.Route("/category/", func (r chi.Router) {
r.Post("/add", AddCategorie)
r.Post("/update", UpdateCategorie)
r.Post("/delete", DeleteCategorie)
})
func AddFood|AddCategorie(w http.ResponseWriter, r *http.Request) {
result := food|categorie.Validate()
food|categorie.Save()
}
func UpdateFood|UpdateCategorie(w http.ResponseWriter, r *http.Request) {
result := food|categorie.Validate()
food|categorie.Update()
}
func DeleteFood|DeleteCategorie(w http.ResponseWriter, r *http.Request) {
}
func (f Food|Categorie) Save() (result Result){
return
}
func (f Food|Categorie) Update() (result Result){
return
}
func (f Food|Categorie) Delete() (result Result){
return
}
Answer the question
In order to leave comments, you need to log in
And what for do you rest on go for this?) Based on the technical specification, even just html files will suffice. Go is for something highly loaded, and not because it is fashionable, it will work with orm in terms of speed at the level of some thread of pehepe, because for example they all do mapping, pull relations, etc. through reflexes, different crutches. Now, if you need to tear out a million records from the database and do terrible and terrible things with them, then this will be revealed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question