Code Monkey home page Code Monkey logo

koddr / tutorial-go-fiber-rest-api Goto Github PK

View Code? Open in Web Editor NEW
366.0 4.0 73.0 292 KB

📖 Build a RESTful API on Go: Fiber, PostgreSQL, JWT and Swagger docs in isolated Docker containers.

Home Page: https://dev.to/koddr/build-a-restful-api-on-go-fiber-postgresql-jwt-and-swagger-docs-in-isolated-docker-containers-475j

License: MIT License

Dockerfile 2.05% Makefile 4.87% Go 93.08%
tutorial tutorials go golang api rest-api fiber fiber-framework jwt swagger

tutorial-go-fiber-rest-api's Introduction

Hello, everyone! 👋

My name is Vic Shóstak. I'm a Software Engineer with excellent UX/UI knowledge and over 13 years of practical experience.

Technical expertise

In more than 13 years of successful work in the IT industry, my technology stack has changed many times, but the technical expertise has always remained at the highest level. I think it's important, not just to write clean code and make a supported infrastructure or create a wonderful UI design, but to look for the root of the problem in the task at hand.

Currently, I'm working in the following stack:

  • Backend
    • Go, Python, Node.js/Bun (Nest.js)
    • PostgreSQL, Redis, SQLite
    • Nginx
  • Frontend
    • TypeScript
    • Angular 18+, Astro 4+, Nuxt 3+, Next.js 14+, htmx
    • Tailwind CSS, daisyUI, shadcn/ui, PrimeNG
  • Tools
    • Docker
    • GitHub Actions
    • Directus, Strapi, NocoDB, n8n, PocketBase
    • Nx, GoReleaser, Templ, Vite, esbuild

Awesome GitHub repos

My current active project is:

gowebly project

Other projects:

With my active support:

Support me

You can support me on Boosty, both on a permanent and on a one-time basis.

All proceeds from this way will go to support my OSS projects and will energize me to create new products and articles for the community.

support me on Boosty

Dev.to blog

I write useful articles on my Dev.to blog about developer tips and tricks and Open Source projects.

dev.to badges

GitHub stats


Thank you!

If you want to give :octocat: GitHub star to any of my projects, I would be very grateful! 🥰

tutorial-go-fiber-rest-api's People

Contributors

akissa avatar dependabot[bot] avatar kamran151199 avatar koddr avatar lospejos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tutorial-go-fiber-rest-api's Issues

Dockerfile: COPY go.mod go.sum ./ error

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (uname -a): Windows 10
  • Golang (go version): go1.16.7 windows/amd64

Describe the bug:
=> ERROR [builder 3/6] COPY go.mod go.sum ./ 0.0s

[builder 3/6] COPY go.mod go.sum ./:


failed to compute cache key: "/go.sum" not found: not found

Steps to reproduce the behavior:

  1. Create Dockerfile
  2. Go to docker build -t fiber .
  3. See error

Screenshots:
image

// @BasePath /api 如果放在Authorization之后,swag init 无法取到值,需要往前面放才能正确生成doc,不知道是为什么?swag v 1.8.8

// @title API
// @Version 1.0
// @basepath /api
// @description This is an auto-generated API Docs.
// @termsofservice http://swagger.io/terms/
// @contact.name API Support
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization

func main() {
....
}

make docker.run fails on github.com/swaggo/swag

This is the error that comes back, also, it doesn't matter the version whether it is your default one or 1.8.0:

=> ERROR [builder 6/6] RUN go build -ldflags="-s -w" -o apiserver .                           0.7s ------
 > [builder 6/6] RUN go build -ldflags="-s -w" -o apiserver .:
#10 0.672 /go/pkg/mod/github.com/swaggo/[email protected]/field_parser.go:13:2: missing go.sum entry for module providing package github.com/go-openapi/spec (imported by github.com/swaggo/swag); to add:
#10 0.672       go get github.com/swaggo/[email protected]
#10 0.672 /go/pkg/mod/github.com/swaggo/[email protected]/ab0x.go:15:2: missing go.sum entry for module providing package golang.org/x/net/webdav (imported by github.com/swaggo/files); to add:
#10 0.672       go get github.com/swaggo/[email protected]
#10 0.672 /go/pkg/mod/github.com/gofiber/fiber/[email protected]/internal/isatty/isatty_tcgets.go:6:8: missing go.sum entry for module providing package golang.org/x/sys/unix (imported by github.com/gofiber/fiber/v2/internal/isatty); to add:
#10 0.672       go get github.com/gofiber/fiber/v2/internal/[email protected]
#10 0.672 /go/pkg/mod/github.com/go-playground/validator/[email protected]/baked_in.go:21:2: missing go.sum entry for module providing package golang.org/x/text/language (imported by github.com/go-playground/validator/v10); to add:
#10 0.672       go get github.com/go-playground/validator/[email protected]
#10 0.672 /go/pkg/mod/github.com/jackc/[email protected]/auth_scram.go:27:2: missing go.sum entry for module providing package golang.org/x/text/secure/precis (imported by github.com/jackc/pgconn); to add:
#10 0.672       go get github.com/jackc/[email protected]
#10 0.672 /go/pkg/mod/github.com/swaggo/[email protected]/operation.go:18:2: missing go.sum entry for module providing package golang.org/x/tools/go/loader (imported by github.com/swaggo/swag); to add:
#10 0.672       go get github.com/swaggo/[email protected]
------
executor failed running [/bin/sh -c go build -ldflags="-s -w" -o apiserver .]: exit code: 1
make: *** [Makefile:40: docker.fiber.build] Error 1

Error response from daemon: network with name dev-network already exist

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (uname -a): Windows 10
  • Golang (go version): go1.16.7 windows/amd64

Describe the bug:
make docker.run
docker network inspect dev-network >/dev/null 2>&1 ||
docker network create -d bridge dev-network
The system cannot find the path specified.
Error response from daemon: network with name dev-network already exists
make: *** [Makefile:36: docker.network] Error 1

Steps to reproduce the behavior:

  1. Go to project
  2. make docker.run
  3. See error

Screenshots:
image

Error when creating book using swagger & curl

Required check list:

  • I'm gonna mark the checkboxes like this.
  • I didn't find in the repository's issues section similar bug.
  • I understand, this is Open Source and not-for-profit product.
  • This is not about third-party project, framework, package or technology.

My environment:

  • OS (uname -a): Linux 89327648a97a 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 Linux (inside docker)
  • Golang (go version): go version go1.18.3 linux/amd64

Describe the bug:

I followed your article & successfully run it. But when I tried to test the create book API, it fail. I tried using Swagger, it still the same. Do you have any sample JSON for create book ?

Steps to reproduce the behavior:

  1. Run the app like shown in readme & run the migration. Make sure no records in DB.
  2. Generate token & copy the token using swagger or curl -X 'GET' 'http://127.0.0.1:5000/api/v1/token/new' -H 'accept: application/json'
  3. Put the token at swagger. By click "Authorize" button on top right. Fill with Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTczMDIzNzF9.0VJubL5Z_49W2-9BHvqQaFn2pN1TxkysFIvzb5SpUow
    image
  4. Try Swagger POST /v1/book by clicking Try It Out & fill Title, Author, etc. image
  5. Click Execute
  6. See error image

I tried to change the JSON, it still error, you can try this curl

curl -X 'POST' \
  'http://127.0.0.1:5000/api/v1/book' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTcyOTc2NzN9.fCjWNsiCVoUecjY1fhKNB_zHrZWS3SQohTeese5HdqM' \
  -H 'Content-Type: application/json' \
  -d '{
  "author": "Michael Crichton",
  "book_attrs": {
    "description": "A cautionary tale about genetic engineering",
    "picture": "https://upload.wikimedia.org/wikipedia/en/3/33/Jurassicpark.jpg",
    "rating": 8
  },
  "title": "Jurassic Park"
}

And it show error
{"error":true,"msg":{"ID":"Key: 'Book.ID' Error:Field validation for 'ID' failed on the 'uuid' tag","UserID":"Key: 'Book.UserID' Error:Field validation for 'UserID' failed on the 'uuid' tag"}}

Expected behavior:

Successfully create book

Screenshots:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.