5chan API — Golang, GORM, Go-fiber

This is the continuation of the 5chan project.

Creating the backend:

  • Setup project and download dependencies in one Ctrl+v-Ctrl-v :

Create a directory structure like so:

  • posts.go
  • replies.go
  • database.go
  • middleware.go
  • post.go
  • reply.go
  • routes.go
  • main.go

Da Code:

  • Creating structs

models/post.go

models/reply.go

  • Connecting the databse and creating a singleton of the instance so we can use it everywhere.
  • Creating Controllers

controllers/posts.go

controllers/replies.go

  • Setup routes:

routes/routes.go

  • A middleware to limit other methods like POST & DELETE to our Frontend. But you're using this you may change them to your liking in the .env file

middleware/middleware.go

  • And then tie everything together in the main.go file

main.go

  • And then run the project using:

After making some test requests these are the screenshots:

The source code of this project lies at:

https://github.com/100lvlmaster/5chan-go

You can find me at:
Website
https://100lvlmaster.in
Github
https://github.com/100lvlmaster

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store