Go rest api files structures its ok like this?

Im using this structure for my rest api its ok like this? im using gin-gonic
OtEfM

There isn’t a rule to make a structure for rest APIs related to Go but you can use some best practices to make the endpoints eg.

Related to to files structure I use a file for every endpoint, named accordingly and prefixed with api to differentiate from regular files.

2 Likes

Thanks, but what doyu think about my structure?

Well, I don’t know nothing about your project so my opinion can be very subjective about but I can make some observations not because the things are wrong but more because from my point of view can be done better.
However, generaly speaking puting endpoints into packages can be useful if you have a semnificative number of endpoints otherwise is a little annoying in data exchange between main and package. Also I don’t know why are you using an intermediate lib folder because seems that your project isn’t a library but more some services (if I’m wrong, skip reading this paragraph :grin:).
By some conventions big letters are used for constants or some methods (see GET,PUT,etc) not packages names so I would avoid using ROUTES and I use routes.
Another point is using relative paths in package path which isn’t a good practice (are a lot of explains about this on internet). You should consider using absolute, GOPATH, vendoring or Go modules.

2 Likes

Thanks a lot for the reply all wrked perfect thanks a lot men.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.